sso_XML = config('devtools.fake_sso_profiles'); } public function getModelBasedResponses($request, $testUser, $picasso = false): string|array { return 'test. funziono ma le logiche non sono state ancora implementate'; } public function getResponses(Request $request, $testUser, $picasso = false): string|array { $uriParts = explode("?", $request->url()); $methodUri = Str::afterLast($uriParts[0], "/"); $reqParams = !empty($request->query()) ? $request->query() : []; if (($methodUri == 'isLogged') || ($methodUri == 'islogged')) { // controllo cookie e conseguente risposta isLogged $loginResponse = ($picasso) ? $this->getLoggedPicasso($testUser) : $this->getLoggedLegacy($testUser); return $loginResponse; } else if ($methodUri != "") { // controllo metodo e parametri e conseguente risposta $userResponses = $this->getUserResponseSet($testUser, $picasso); if (isset($userResponses[$methodUri])) { $responseContent = $this->getResponseArgumentsBased($userResponses, $methodUri, $reqParams); return $responseContent; } else { return 'user is not set for this method'; } } else { return 'wrong-request-no-such-method'; } } public function getLoggedPicasso($testUser): string|array { if (isset($_COOKIE["SSOSESSIONID"])) { if (!isset($this->sso_XML[$testUser]["picasso"])) { return 'this picasso user doesnt exist. check your SSOSESSIONID value'; } $sampleResponseString = Arr::first($this->sso_XML[$testUser]["picasso"]["getWebcustomerInformation"]["parametri"]["k"] ); $sampleResponseObject = Utils::convertXMLStrToArray($sampleResponseString); $resp = [ 'logged' => (string) 1, 'errorCode' => (string) 0, 'username' => (string) $sampleResponseObject["Username"], 'next_user' => (string) 'N', //'token' => '415F2B31F1C15FA45C9A6E1CBEB0ADF3' ]; } else { $resp = [ 'logged' => (string) 0, 'errorCode' => (string) 0, ]; } $xml = Utils::convertToXML($resp, $root = ''); return $xml; } public function getLoggedLegacy($testUser): string|array { if (isset($_COOKIE["CAuthCookie"])) { if (!isset($this->sso_XML[$testUser]["sso"])) { return 'this user doesnt exist. check your CAuthCookie value'; } $sampleResponseString = Arr::first($this->sso_XML[$testUser]["sso"]["getWebcustomerInformation"]["parametri"]["k"] ); $sampleResponseObject = Utils::convertXMLStrToArray($sampleResponseString); $resp = [ 'logged' => (string) 1, 'errorCode' => (string) 0, 'username' => (string) $sampleResponseObject["Username"], 'token' => (string) '415F2B31F1C15FA45C9A6E1CBEB0ADF3', 'next_user' => (string) 'N', ]; } else { $resp = [ 'logged' => (string) 0, 'errorCode' => (string) 0, ]; } $xml = Utils::convertToXML($resp, $root = ''); return $xml; } public function getResponseArgumentsBased($userMethods, $methodUri, $reqParams = []): string { $method = $userMethods[$methodUri]; $params = $method["parametri"]; //assumo che se la richiesta sia arrivata fin qui abbia tutti i mandatory nel url foreach ($reqParams as $key => $value) { //verifico se il metodo dell' utente ha la chiave che sto cercando if ($key != "k" && isset($params[$key])) { if (array_key_exists($value, $params[$key])) { \Log::channel('requests')->debug("[VolaFakeHTTPResponder] Inserisco xml specifico per key:$key ,params: " . print_r($params, 1) . " key: $key, value: $value, xml: " . print_r($params[$key][$value], 1)); return $params[$key][$value]; } } } //xml di default (se richiede parametri di default conterrĂ  errori) $defaultResponse = Arr::first($params["k"]); \Log::channel('requests')->debug("[VolaFakeHTTPResponder] Inserisco xml di default $defaultResponse per method: $methodUri"); return $defaultResponse; } /** * @param Request $request * @param mixed $testUser * @param bool $picasso * @return array|mixed */ private function getUserResponseSet(mixed $testUser, bool $picasso): array { if ($picasso) { $userMethods = $this->sso_XML[$testUser]["picasso"] ?? []; } else { $userMethods = $this->sso_XML[$testUser]["sso"] ?? []; } return $userMethods; } }