| Total Complexity | 78 |
| Total Lines | 443 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Telepath often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Telepath, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class Telepath extends AbstractTest { |
||
| 25 | |||
| 26 | private $realm; |
||
| 27 | private $visitedFlr; |
||
| 28 | private $visitedHotspot; |
||
| 29 | private $catProfile; |
||
| 30 | private $dbIdP; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * |
||
| 34 | * @var string|null |
||
| 35 | */ |
||
| 36 | private $idPFederation; |
||
| 37 | private $testsuite; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * prime the Telepath with info it needs to know to successfully meditate over the problem |
||
| 41 | * @param string $realm the realm of the user |
||
| 42 | * @param string|null $visitedFlr which NRO is the user visiting |
||
| 43 | * @param string|null $visitedHotspot external DB ID of the hotspot he visited |
||
| 44 | */ |
||
| 45 | public function __construct(string $realm, $visitedFlr = NULL, $visitedHotspot = NULL) { |
||
| 69 | } |
||
| 70 | |||
| 71 | /* The eduroam OT monitoring has the following return codes: |
||
| 72 | * |
||
| 73 | |||
| 74 | Status codes |
||
| 75 | |||
| 76 | 0 - O.K. |
||
| 77 | -1 - Accept O.K. Reject No |
||
| 78 | -2 - Reject O.K. Accept No |
||
| 79 | -3 - Accept No Reject No |
||
| 80 | -9 - system error |
||
| 81 | -10 - Accept O.K. Reject timeou |
||
| 82 | -11 - Accept O.K. Reject no EAP |
||
| 83 | -20 - Reject O.K. Accept timeou |
||
| 84 | -21 - Reject O.K. Accept no EAP |
||
| 85 | -31 - Accept No Reject timeou |
||
| 86 | -32 - Accept Timeout Reject no |
||
| 87 | -33 - Accept Timeout Reject timeou |
||
| 88 | -35 - Accept No Reject no EAP |
||
| 89 | -36 - Reject No Accept no EAP |
||
| 90 | -37 - Reject No EAP Accept no EAP |
||
| 91 | -40 - UDP test error |
||
| 92 | |||
| 93 | */ |
||
| 94 | |||
| 95 | /** |
||
| 96 | * ask the monitoring API about the things it knows |
||
| 97 | * @param string $type which type of test to execute |
||
| 98 | * @param string $param1 test-specific parameter number 1, if any |
||
| 99 | * @param string $param2 test-specific parameter number 2, if any |
||
| 100 | * @return array |
||
| 101 | */ |
||
| 102 | private function genericAPIStatus($type, $param1 = NULL, $param2 = NULL) { |
||
| 103 | $endpoints = [ |
||
| 104 | 'tlr_test' => "https://monitor.eduroam.org/mapi/index.php?type=tlr_test&tlr=$param1", |
||
| 105 | 'federation_via_tlr' => "https://monitor.eduroam.org/mapi/index.php?type=federation_via_tlr&federation=$param1", |
||
| 106 | 'flrs_test' => "https://monitor.eduroam.org/mapi/index.php?type=flrs_test&federation=$param1", |
||
| 107 | 'flr_by_federation' => "https://monitor.eduroam.org/mapi/index.php?type=flr_by_federation&federation=$param2&with=$param1", |
||
| 108 | ]; |
||
| 109 | $ignore = [ |
||
| 110 | 'tlr_test' => 'tlr', |
||
| 111 | 'federation_via_tlr' => 'fed', |
||
| 112 | 'flrs_test' => 'fed', |
||
| 113 | 'flr_by_federation' => 'fed', |
||
| 114 | ]; |
||
| 115 | $this->loggerInstance->debug(4, "Doing Monitoring API check with $endpoints[$type]\n"); |
||
| 116 | $jsonResult = \core\common\OutsideComm::downloadFile($endpoints[$type]); |
||
| 117 | $this->loggerInstance->debug(4, "Monitoring API Result: $jsonResult\n"); |
||
| 118 | $decoded = json_decode($jsonResult, TRUE); |
||
| 119 | $retval = []; |
||
| 120 | $retval["RAW"] = $decoded; |
||
| 121 | $atLeastOneFunctional = FALSE; |
||
| 122 | $allFunctional = TRUE; |
||
| 123 | if (!isset($decoded[$type]) || isset($decoded['ERROR'])) { |
||
| 124 | $retval["STATUS"] = AbstractTest::STATUS_MONITORINGFAIL; |
||
| 125 | return $retval; |
||
| 126 | } |
||
| 127 | foreach ($decoded[$type] as $instance => $resultset) { |
||
| 128 | if ($instance == $ignore[$type]) { |
||
| 129 | // don't care |
||
| 130 | continue; |
||
| 131 | } |
||
| 132 | // TLR test has statuscode on this level, otherwise need to recurse |
||
| 133 | // one more level |
||
| 134 | switch ($type) { |
||
| 135 | case "tlr_test": |
||
| 136 | switch ($resultset['status_code']) { |
||
| 137 | case 0: |
||
| 138 | $atLeastOneFunctional = TRUE; |
||
| 139 | break; |
||
| 140 | case 9: // monitoring itself has an error, no effect on our verdict |
||
| 141 | case -1: // Reject test fails, but we diagnose supposed-working connection, so no effect on our verdict |
||
| 142 | case -10: // same as previous |
||
| 143 | case -11: // same as previous |
||
| 144 | break; |
||
| 145 | default: |
||
| 146 | $allFunctional = FALSE; |
||
| 147 | } |
||
| 148 | break; |
||
| 149 | default: |
||
| 150 | foreach ($resultset as $particularInstance => $particularResultset) { |
||
| 151 | switch ($particularResultset['status_code']) { |
||
| 152 | case 0: |
||
| 153 | $atLeastOneFunctional = TRUE; |
||
| 154 | break; |
||
| 155 | case 9: // monitoring itself has an error, no effect on our verdict |
||
| 156 | case -1: // Reject test fails, but we diagnose supposed-working connection, so no effect on our verdict |
||
| 157 | case -10: // same as previous |
||
| 158 | case -11: // same as previous |
||
| 159 | break; |
||
| 160 | default: |
||
| 161 | $allFunctional = FALSE; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | if ($allFunctional) { |
||
| 168 | $retval["STATUS"] = AbstractTest::STATUS_GOOD; |
||
| 169 | return $retval; |
||
| 170 | } |
||
| 171 | if ($atLeastOneFunctional) { |
||
| 172 | $retval["STATUS"] = AbstractTest::STATUS_PARTIAL; |
||
| 173 | return $retval; |
||
| 174 | } |
||
| 175 | $retval["STATUS"] = AbstractTest::STATUS_DOWN; |
||
| 176 | return $retval; |
||
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Are the ETLR servers in order? |
||
| 181 | * @return array |
||
| 182 | */ |
||
| 183 | private function checkEtlrStatus() { |
||
| 184 | // TODO: we always check the European TLRs even though the connection in question might go via others and/or this one |
||
| 185 | // needs a table to determine what goes where :-( |
||
| 186 | $ret = $this->genericAPIStatus("tlr_test", "TLR_EU"); |
||
| 187 | $this->additionalFindings[AbstractTest::INFRA_ETLR][] = $ret; |
||
| 188 | switch ($ret["STATUS"]) { |
||
| 189 | case AbstractTest::STATUS_GOOD: |
||
| 190 | unset($this->possibleFailureReasons[AbstractTest::INFRA_ETLR]); |
||
| 191 | break; |
||
| 192 | case AbstractTest::STATUS_PARTIAL: |
||
| 193 | case AbstractTest::STATUS_MONITORINGFAIL: |
||
| 194 | // one of the ETLRs is down, or there is a failure in the monitoring system? |
||
| 195 | // This probably doesn't impact the user unless he's unlucky and has his session fall into failover. |
||
| 196 | // keep ETLR as a possible problem with original probability |
||
| 197 | break; |
||
| 198 | case AbstractTest::STATUS_DOWN: |
||
| 199 | // Oh! Well if it is not international roaming, that still doesn't have an effect /in this case/. |
||
| 200 | if ($this->idPFederation == $this->visitedFlr) { |
||
| 201 | unset($this->possibleFailureReasons[AbstractTest::INFRA_ETLR]); |
||
| 202 | break; |
||
| 203 | } |
||
| 204 | // But it is about int'l roaming, and we are spot on here. |
||
| 205 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 206 | $this->possibleFailureReasons[AbstractTest::INFRA_ETLR] = 0.95; |
||
| 207 | } |
||
| 208 | } |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Is the uplink between an NRO server and the ETLRs in order? |
||
| 212 | * @param string $whichSide |
||
| 213 | * @return array |
||
| 214 | */ |
||
| 215 | private function checkFedEtlrUplink($whichSide) { |
||
| 216 | // TODO: we always check the European TLRs even though the connection in question might go via others and/or this one |
||
| 217 | // needs a table to determine what goes where :-( |
||
| 218 | switch ($whichSide) { |
||
| 219 | case AbstractTest::INFRA_NRO_IDP: |
||
| 220 | $fed = $this->idPFederation; |
||
| 221 | $linkVariant = AbstractTest::INFRA_LINK_ETLR_NRO_IDP; |
||
| 222 | break; |
||
| 223 | case AbstractTest::INFRA_NRO_SP: |
||
| 224 | $fed = $this->visitedFlr; |
||
| 225 | $linkVariant = AbstractTest::INFRA_LINK_ETLR_NRO_SP; |
||
| 226 | break; |
||
| 227 | default: |
||
| 228 | throw new Exception("This function operates on the IdP- or SP-side FLR, nothing else!"); |
||
| 229 | } |
||
| 230 | |||
| 231 | $ret = $this->genericAPIStatus("federation_via_tlr", $fed); |
||
| 232 | $this->additionalFindings[AbstractTest::INFRA_NRO_IDP][] = $ret; |
||
| 233 | switch ($ret["STATUS"]) { |
||
| 234 | case AbstractTest::STATUS_GOOD: |
||
| 235 | unset($this->possibleFailureReasons[$whichSide]); |
||
| 236 | unset($this->possibleFailureReasons[$linkVariant]); |
||
| 237 | break; |
||
| 238 | case AbstractTest::STATUS_PARTIAL: |
||
| 239 | // a subset of the FLRs is down? This probably doesn't impact the user unless he's unlucky and has his session fall into failover. |
||
| 240 | // keep FLR as a possible problem with original probability |
||
| 241 | break; |
||
| 242 | case AbstractTest::STATUS_DOWN: |
||
| 243 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 244 | // if earlier test found the server itself to be the problem, keep it, otherwise put the blame on the link |
||
| 245 | if ($this->possibleFailureReasons[$whichSide] != 0.95) { |
||
| 246 | $this->possibleFailureReasons[$linkVariant] = 0.95; |
||
| 247 | } |
||
| 248 | } |
||
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Is the NRO server itself in order? |
||
| 253 | * @param string $whichSide |
||
| 254 | * @return array |
||
| 255 | */ |
||
| 256 | private function checkFlrServerStatus($whichSide) { |
||
| 257 | switch ($whichSide) { |
||
| 258 | case AbstractTest::INFRA_NRO_IDP: |
||
| 259 | $fed = $this->idPFederation; |
||
| 260 | break; |
||
| 261 | case AbstractTest::INFRA_NRO_SP: |
||
| 262 | $fed = $this->visitedFlr; |
||
| 263 | break; |
||
| 264 | default: |
||
| 265 | throw new Exception("This function operates on the IdP- or SP-side FLR, nothing else!"); |
||
| 266 | } |
||
| 267 | |||
| 268 | $ret = $this->genericAPIStatus("flrs_test", $fed); |
||
| 269 | $this->additionalFindings[$whichSide][] = $ret; |
||
| 270 | switch ($ret["STATUS"]) { |
||
| 271 | case AbstractTest::STATUS_GOOD: |
||
| 272 | unset($this->possibleFailureReasons[$whichSide]); |
||
| 273 | break; |
||
| 274 | case AbstractTest::STATUS_PARTIAL: |
||
| 275 | // a subset of the FLRs is down? This probably doesn't impact the user unless he's unlucky and has his session fall into failover. |
||
| 276 | // keep FLR as a possible problem with original probability |
||
| 277 | break; |
||
| 278 | case AbstractTest::STATUS_DOWN: |
||
| 279 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 280 | $this->possibleFailureReasons[$whichSide] = 0.95; |
||
| 281 | } |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Does authentication traffic flow between a given source and destination NRO? |
||
| 286 | * @return array |
||
| 287 | */ |
||
| 288 | private function checkNROFlow() { |
||
| 289 | return $this->genericAPIStatus("flr_by_federation", $this->idPFederation, $this->visitedFlr); |
||
| 290 | } |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Runs the CAT-internal diagnostics tests. Determines the state of the |
||
| 294 | * realm (and indirectly that of the links and statuses of involved proxies |
||
| 295 | * and returns a judgment whether external Monitoring API tests are warranted |
||
| 296 | * or not |
||
| 297 | * @return boolean TRUE if external tests have to be run |
||
| 298 | */ |
||
| 299 | private function CATInternalTests() { |
||
| 356 | } |
||
| 357 | } |
||
| 358 | } |
||
| 359 | |||
| 360 | private function determineTestsuiteParameters() { |
||
| 361 | if ($this->catProfile > 0) { |
||
| 362 | $profileObject = \core\ProfileFactory::instantiate($this->catProfile); |
||
| 363 | $readinessLevel = $profileObject->readinessLevel(); |
||
| 364 | |||
| 365 | switch ($readinessLevel) { |
||
| 366 | case \core\AbstractProfile::READINESS_LEVEL_SHOWTIME: |
||
| 367 | // fall-througuh intended: use the data even if non-public but complete |
||
| 368 | case \core\AbstractProfile::READINESS_LEVEL_SUFFICIENTCONFIG: |
||
| 369 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["Profile" => $profileObject->identifier]; |
||
| 370 | $this->testsuite = new RADIUSTests($this->realm, $profileObject->getRealmCheckOuterUsername(), $profileObject->getEapMethodsinOrderOfPreference(1), $profileObject->getCollapsedAttributes()['eap:server_name'], $profileObject->getCollapsedAttributes()["eap:ca_file"]); |
||
| 371 | break; |
||
| 372 | case \core\AbstractProfile::READINESS_LEVEL_NOTREADY: |
||
| 373 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["Profile" => "UNCONCLUSIVE"]; |
||
| 374 | $this->testsuite = new RADIUSTests($this->realm, "anonymous@" . $this->realm); |
||
| 375 | break; |
||
| 376 | default: |
||
| 377 | } |
||
| 378 | } else { |
||
| 379 | $this->testsuite = new RADIUSTests($this->realm, "anonymous@" . $this->realm); |
||
| 380 | } |
||
| 381 | } |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Does the main meditation job |
||
| 385 | * @return array the findings |
||
| 386 | */ |
||
| 387 | public function magic() { |
||
| 467 | } |
||
| 468 | |||
| 470 |