| Total Complexity | 79 |
| Total Lines | 447 |
| 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 | $retval = []; |
||
| 119 | if ($jsonResult === FALSE) { // monitoring API didn't respond at all! |
||
| 120 | $retval["STATUS"] = AbstractTest::STATUS_MONITORINGFAIL; |
||
| 121 | return $retval; |
||
| 122 | } |
||
| 123 | $decoded = json_decode($jsonResult, TRUE); |
||
| 124 | $retval["RAW"] = $decoded; |
||
| 125 | $atLeastOneFunctional = FALSE; |
||
| 126 | $allFunctional = TRUE; |
||
| 127 | if (!isset($decoded[$type]) || isset($decoded['ERROR'])) { |
||
| 128 | $retval["STATUS"] = AbstractTest::STATUS_MONITORINGFAIL; |
||
| 129 | return $retval; |
||
| 130 | } |
||
| 131 | foreach ($decoded[$type] as $instance => $resultset) { |
||
| 132 | if ($instance == $ignore[$type]) { |
||
| 133 | // don't care |
||
| 134 | continue; |
||
| 135 | } |
||
| 136 | // TLR test has statuscode on this level, otherwise need to recurse |
||
| 137 | // one more level |
||
| 138 | switch ($type) { |
||
| 139 | case "tlr_test": |
||
| 140 | switch ($resultset['status_code']) { |
||
| 141 | case 0: |
||
| 142 | $atLeastOneFunctional = TRUE; |
||
| 143 | break; |
||
| 144 | case 9: // monitoring itself has an error, no effect on our verdict |
||
| 145 | case -1: // Reject test fails, but we diagnose supposed-working connection, so no effect on our verdict |
||
| 146 | case -10: // same as previous |
||
| 147 | case -11: // same as previous |
||
| 148 | break; |
||
| 149 | default: |
||
| 150 | $allFunctional = FALSE; |
||
| 151 | } |
||
| 152 | break; |
||
| 153 | default: |
||
| 154 | foreach ($resultset as $particularInstance => $particularResultset) { |
||
| 155 | switch ($particularResultset['status_code']) { |
||
| 156 | case 0: |
||
| 157 | $atLeastOneFunctional = TRUE; |
||
| 158 | break; |
||
| 159 | case 9: // monitoring itself has an error, no effect on our verdict |
||
| 160 | case -1: // Reject test fails, but we diagnose supposed-working connection, so no effect on our verdict |
||
| 161 | case -10: // same as previous |
||
| 162 | case -11: // same as previous |
||
| 163 | break; |
||
| 164 | default: |
||
| 165 | $allFunctional = FALSE; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($allFunctional) { |
||
| 172 | $retval["STATUS"] = AbstractTest::STATUS_GOOD; |
||
| 173 | return $retval; |
||
| 174 | } |
||
| 175 | if ($atLeastOneFunctional) { |
||
| 176 | $retval["STATUS"] = AbstractTest::STATUS_PARTIAL; |
||
| 177 | return $retval; |
||
| 178 | } |
||
| 179 | $retval["STATUS"] = AbstractTest::STATUS_DOWN; |
||
| 180 | return $retval; |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Are the ETLR servers in order? |
||
| 185 | * @return array |
||
| 186 | */ |
||
| 187 | private function checkEtlrStatus() { |
||
| 188 | // TODO: we always check the European TLRs even though the connection in question might go via others and/or this one |
||
| 189 | // needs a table to determine what goes where :-( |
||
| 190 | $ret = $this->genericAPIStatus("tlr_test", "TLR_EU"); |
||
| 191 | $this->additionalFindings[AbstractTest::INFRA_ETLR][] = $ret; |
||
| 192 | switch ($ret["STATUS"]) { |
||
| 193 | case AbstractTest::STATUS_GOOD: |
||
| 194 | unset($this->possibleFailureReasons[AbstractTest::INFRA_ETLR]); |
||
| 195 | break; |
||
| 196 | case AbstractTest::STATUS_PARTIAL: |
||
| 197 | case AbstractTest::STATUS_MONITORINGFAIL: |
||
| 198 | // one of the ETLRs is down, or there is a failure in the monitoring system? |
||
| 199 | // This probably doesn't impact the user unless he's unlucky and has his session fall into failover. |
||
| 200 | // keep ETLR as a possible problem with original probability |
||
| 201 | break; |
||
| 202 | case AbstractTest::STATUS_DOWN: |
||
| 203 | // Oh! Well if it is not international roaming, that still doesn't have an effect /in this case/. |
||
| 204 | if ($this->idPFederation == $this->visitedFlr) { |
||
| 205 | unset($this->possibleFailureReasons[AbstractTest::INFRA_ETLR]); |
||
| 206 | break; |
||
| 207 | } |
||
| 208 | // But it is about int'l roaming, and we are spot on here. |
||
| 209 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 210 | $this->possibleFailureReasons[AbstractTest::INFRA_ETLR] = 0.95; |
||
| 211 | } |
||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Is the uplink between an NRO server and the ETLRs in order? |
||
| 216 | * @param string $whichSide |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | private function checkFedEtlrUplink($whichSide) { |
||
| 220 | // TODO: we always check the European TLRs even though the connection in question might go via others and/or this one |
||
| 221 | // needs a table to determine what goes where :-( |
||
| 222 | switch ($whichSide) { |
||
| 223 | case AbstractTest::INFRA_NRO_IDP: |
||
| 224 | $fed = $this->idPFederation; |
||
| 225 | $linkVariant = AbstractTest::INFRA_LINK_ETLR_NRO_IDP; |
||
| 226 | break; |
||
| 227 | case AbstractTest::INFRA_NRO_SP: |
||
| 228 | $fed = $this->visitedFlr; |
||
| 229 | $linkVariant = AbstractTest::INFRA_LINK_ETLR_NRO_SP; |
||
| 230 | break; |
||
| 231 | default: |
||
| 232 | throw new Exception("This function operates on the IdP- or SP-side FLR, nothing else!"); |
||
| 233 | } |
||
| 234 | |||
| 235 | $ret = $this->genericAPIStatus("federation_via_tlr", $fed); |
||
| 236 | $this->additionalFindings[AbstractTest::INFRA_NRO_IDP][] = $ret; |
||
| 237 | switch ($ret["STATUS"]) { |
||
| 238 | case AbstractTest::STATUS_GOOD: |
||
| 239 | unset($this->possibleFailureReasons[$whichSide]); |
||
| 240 | unset($this->possibleFailureReasons[$linkVariant]); |
||
| 241 | break; |
||
| 242 | case AbstractTest::STATUS_PARTIAL: |
||
| 243 | // 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. |
||
| 244 | // keep FLR as a possible problem with original probability |
||
| 245 | break; |
||
| 246 | case AbstractTest::STATUS_DOWN: |
||
| 247 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 248 | // if earlier test found the server itself to be the problem, keep it, otherwise put the blame on the link |
||
| 249 | if ($this->possibleFailureReasons[$whichSide] != 0.95) { |
||
| 250 | $this->possibleFailureReasons[$linkVariant] = 0.95; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | } |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Is the NRO server itself in order? |
||
| 257 | * @param string $whichSide |
||
| 258 | * @return array |
||
| 259 | */ |
||
| 260 | private function checkFlrServerStatus($whichSide) { |
||
| 261 | switch ($whichSide) { |
||
| 262 | case AbstractTest::INFRA_NRO_IDP: |
||
| 263 | $fed = $this->idPFederation; |
||
| 264 | break; |
||
| 265 | case AbstractTest::INFRA_NRO_SP: |
||
| 266 | $fed = $this->visitedFlr; |
||
| 267 | break; |
||
| 268 | default: |
||
| 269 | throw new Exception("This function operates on the IdP- or SP-side FLR, nothing else!"); |
||
| 270 | } |
||
| 271 | |||
| 272 | $ret = $this->genericAPIStatus("flrs_test", $fed); |
||
| 273 | $this->additionalFindings[$whichSide][] = $ret; |
||
| 274 | switch ($ret["STATUS"]) { |
||
| 275 | case AbstractTest::STATUS_GOOD: |
||
| 276 | unset($this->possibleFailureReasons[$whichSide]); |
||
| 277 | break; |
||
| 278 | case AbstractTest::STATUS_PARTIAL: |
||
| 279 | // 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. |
||
| 280 | // keep FLR as a possible problem with original probability |
||
| 281 | break; |
||
| 282 | case AbstractTest::STATUS_DOWN: |
||
| 283 | // Raise probability by much (even monitoring is sometimes wrong, or a few minutes behind reality) |
||
| 284 | $this->possibleFailureReasons[$whichSide] = 0.95; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Does authentication traffic flow between a given source and destination NRO? |
||
| 290 | * @return array |
||
| 291 | */ |
||
| 292 | private function checkNROFlow() { |
||
| 293 | return $this->genericAPIStatus("flr_by_federation", $this->idPFederation, $this->visitedFlr); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Runs the CAT-internal diagnostics tests. Determines the state of the |
||
| 298 | * realm (and indirectly that of the links and statuses of involved proxies |
||
| 299 | * and returns a judgment whether external Monitoring API tests are warranted |
||
| 300 | * or not |
||
| 301 | * @return boolean TRUE if external tests have to be run |
||
| 302 | */ |
||
| 303 | private function CATInternalTests() { |
||
| 304 | // we are expecting to get a REJECT from all runs, because that means the packet got through to the IdP. |
||
| 305 | // (the ETLR sometimes does a "Reject instead of Ignore" but that is filtered out and changed into a timeout |
||
| 306 | // by the test suite automatically, so it does not disturb the measurement) |
||
| 307 | // If that's true, we can exclude two sources of problems (both proxy levels). Hooray! |
||
| 308 | $allAreConversationReject = TRUE; |
||
| 309 | $atLeastOneConversationReject = FALSE; |
||
| 310 | |||
| 311 | foreach (CONFIG_DIAGNOSTICS['RADIUSTESTS']['UDP-hosts'] as $probeindex => $probe) { |
||
| 312 | $reachCheck = $this->testsuite->udpReachability($probeindex); |
||
| 313 | if ($reachCheck != RADIUSTests::RETVAL_CONVERSATION_REJECT) { |
||
| 314 | $allAreConversationReject = FALSE; |
||
| 315 | } else { |
||
| 316 | $atLeastOneConversationReject = TRUE; |
||
| 317 | } |
||
| 318 | |||
| 319 | $this->additionalFindings[AbstractTest::INFRA_ETLR][] = ["DETAIL" => $this->testsuite->consolidateUdpResult($probeindex)]; |
||
| 320 | $this->additionalFindings[AbstractTest::INFRA_NRO_IDP][] = ["DETAIL" => $this->testsuite->consolidateUdpResult($probeindex)]; |
||
| 321 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["DETAIL" => $this->testsuite->consolidateUdpResult($probeindex)]; |
||
| 322 | } |
||
| 323 | |||
| 324 | if ($allAreConversationReject) { |
||
| 325 | $this->additionalFindings[AbstractTest::INFRA_ETLR][] = ["CONNCHECK" => RADIUSTests::RETVAL_CONVERSATION_REJECT]; |
||
| 326 | $this->additionalFindings[AbstractTest::INFRA_NRO_IDP][] = ["CONNCHECK" => RADIUSTests::RETVAL_CONVERSATION_REJECT]; |
||
| 327 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["CONNCHECK" => RADIUSTests::RETVAL_CONVERSATION_REJECT]; |
||
| 328 | $this->additionalFindings[AbstractTest::INFRA_LINK_ETLR_NRO_IDP][] = ["LINKCHECK" => RADIUSTests::L_OK]; |
||
| 329 | // we have actually reached an IdP, so all links are good, and the |
||
| 330 | // realm is routable in eduroam. So even if it exists in neither DB |
||
| 331 | // we can exclude the NONEXISTENTREALM case |
||
| 332 | unset($this->possibleFailureReasons[AbstractTest::INFRA_ETLR]); |
||
| 333 | unset($this->possibleFailureReasons[AbstractTest::INFRA_NRO_IDP]); |
||
| 334 | unset($this->possibleFailureReasons[AbstractTest::INFRA_LINK_ETLR_NRO_IDP]); |
||
| 335 | unset($this->possibleFailureReasons[AbstractTest::INFRA_NONEXISTENTREALM]); |
||
| 336 | } |
||
| 337 | |||
| 338 | if ($atLeastOneConversationReject) { |
||
| 339 | // at least we can be sure it exists |
||
| 340 | unset($this->possibleFailureReasons[AbstractTest::INFRA_NONEXISTENTREALM]); |
||
| 341 | // It could still be an IdP RADIUS problem in that some cert oddities |
||
| 342 | // in combination with the device lead to a broken auth |
||
| 343 | // if there is nothing beyond the "REMARK" level, then it's not an IdP problem |
||
| 344 | // otherwise, add the corresponding warnings and errors to $additionalFindings |
||
| 345 | switch ($this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][0]['DETAIL']['level']) { |
||
| 346 | case RADIUSTests::L_OK: |
||
| 347 | case RADIUSTests::L_REMARK: |
||
| 348 | // both are fine - the IdP is working and the user problem |
||
| 349 | // is not on the IdP RADIUS level |
||
| 350 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["ODDITYLEVEL" => $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][0]['DETAIL']['level']]; |
||
| 351 | unset($this->possibleFailureReasons[AbstractTest::INFRA_IDP_RADIUS]); |
||
| 352 | break; |
||
| 353 | case RADIUSTests::L_WARN: |
||
| 354 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["ODDITYLEVEL" => RADIUSTests::L_WARN]; |
||
| 355 | $this->possibleFailureReasons[AbstractTest::INFRA_IDP_RADIUS] = 0.3; // possibly we found the culprit - if RADIUS server is misconfigured AND user is on a device which reacts picky about exactly this oddity. |
||
| 356 | break; |
||
| 357 | case RADIUSTests::L_ERROR: |
||
| 358 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["ODDITYLEVEL" => RADIUSTests::L_ERROR]; |
||
| 359 | $this->possibleFailureReasons[AbstractTest::INFRA_IDP_RADIUS] = 0.8; // errors are never good, so we can be reasonably sure we've hit the spot! |
||
| 360 | } |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | private function determineTestsuiteParameters() { |
||
| 365 | if ($this->catProfile > 0) { |
||
| 366 | $profileObject = \core\ProfileFactory::instantiate($this->catProfile); |
||
| 367 | $readinessLevel = $profileObject->readinessLevel(); |
||
| 368 | |||
| 369 | switch ($readinessLevel) { |
||
| 370 | case \core\AbstractProfile::READINESS_LEVEL_SHOWTIME: |
||
| 371 | // fall-througuh intended: use the data even if non-public but complete |
||
| 372 | case \core\AbstractProfile::READINESS_LEVEL_SUFFICIENTCONFIG: |
||
| 373 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["Profile" => $profileObject->identifier]; |
||
| 374 | $this->testsuite = new RADIUSTests($this->realm, $profileObject->getRealmCheckOuterUsername(), $profileObject->getEapMethodsinOrderOfPreference(1), $profileObject->getCollapsedAttributes()['eap:server_name'], $profileObject->getCollapsedAttributes()["eap:ca_file"]); |
||
| 375 | break; |
||
| 376 | case \core\AbstractProfile::READINESS_LEVEL_NOTREADY: |
||
| 377 | $this->additionalFindings[AbstractTest::INFRA_IDP_RADIUS][] = ["Profile" => "UNCONCLUSIVE"]; |
||
| 378 | $this->testsuite = new RADIUSTests($this->realm, "anonymous@" . $this->realm); |
||
| 379 | break; |
||
| 380 | default: |
||
| 381 | } |
||
| 382 | } else { |
||
| 383 | $this->testsuite = new RADIUSTests($this->realm, "anonymous@" . $this->realm); |
||
| 384 | } |
||
| 385 | } |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Does the main meditation job |
||
| 389 | * @return array the findings |
||
| 390 | */ |
||
| 391 | public function magic() { |
||
| 471 | } |
||
| 472 | |||
| 473 | } |
||
| 474 |