davide.cucurnia@vola.it
2024-02-07 59b0688842f1808c1a51f277d8605b3ec4a710de
app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
@@ -21,7 +21,12 @@
        $this->sso_XML = config('devtools.fake_sso_profiles');
    }
    public function getResponses(Request $request, $testUser, $picasso = false)
    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], "/");
@@ -33,20 +38,25 @@
            } else if ($methodUri != "") {
                // controllo metodo e parametri e conseguente risposta
                $userResponses = $this->getUserResponseSet($request, $testUser);
                $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 'wront-request-no-such-method';
                return 'wrong-request-no-such-method';
            }
    }
    public function getLoggedPicasso($testUser)
    public function getLoggedPicasso($testUser): string|array
    {
        if (isset($_COOKIE["SSOSESSIONID"])) {
            $sampleResponseString = Arr::first($this->sso_XML[$testUser]["picasso"]["getWebcustomerInformation"]["parametri"]["t"] );
            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,
@@ -65,10 +75,13 @@
        return $xml;
    }
    public function getLoggedLegacy($testUser)
    public function getLoggedLegacy($testUser): string|array
    {
        if (isset($_COOKIE["CAuthCookie"])) {
            $sampleResponseString = Arr::first($this->sso_XML[$testUser]["picasso"]["getWebcustomerInformation"]["parametri"]["t"] );
            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,
@@ -87,7 +100,7 @@
        return $xml;
    }
    public function getResponseArgumentsBased($userMethods, $methodUri, $reqParams = [])
    public function getResponseArgumentsBased($userMethods, $methodUri, $reqParams = []): string
    {
        $method = $userMethods[$methodUri];
        $params = $method["parametri"];
@@ -95,29 +108,28 @@
        //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 != "t" && isset($params[$key])) {
            if ($key != "k" && isset($params[$key])) {
                if (array_key_exists($value, $params[$key])) {
                    \Log::channel('general')->debug("[VolaFakeHTTPResponder] Inserisco xml specifico per key:$key ,params: " . print_r($params, 1) . " key: $key, value: $value, xml: " . print_r($params[$key][$value], 1));
                    \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["t"]);
        \Log::channel('general')->debug("[VolaFakeHTTPResponder] Inserisco xml di default $defaultResponse per method: $methodUri");
        $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(Request $request, mixed $testUser)
    private function getUserResponseSet(mixed $testUser, bool $picasso): array
    {
        $url = $request->url();
        $isPicasso = Str::contains($url, "picasso");
        if ($isPicasso) {
        if ($picasso) {
            $userMethods = $this->sso_XML[$testUser]["picasso"] ?? [];
        } else {
            $userMethods = $this->sso_XML[$testUser]["sso"] ?? [];