Filippo Bertilotti
2024-07-22 0991a9fb42afabd45d2b7504b84d6484b241c35d
app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
@@ -13,7 +13,6 @@
class VolaFakeHTTPResponder
{
    public array $data;
    public array $headers;
    private array $xmlResponses;
    public function __construct()
@@ -21,9 +20,26 @@
        $this->xmlResponses = config('devtools.fake_sso_profiles');
    }
    public function getModelBasedResponses($request, $selectedUser, $picasso = false): string|array
    public function getModelBasedResponses(Request $request): array
    {
        return 'test. funziono ma le logiche non sono state ancora implementate';
        $picassoRequest = (str_starts_with($request->getRequestUri(), '/picasso/',));
        $profile = Utils::getRequestedUser($request);
        if (isset($profile)) {
            $responseContent["data"] = 'test. funziono ma le logiche non sono state ancora implementate';
            $responseContent["status"] = 200;
            \RequestLogger::logProcessedRequest($request, $responseContent, (($picassoRequest) ? 'Picasso' : 'SSO Legacy') );
            return $responseContent;
        } else {
            \RequestLogger::logRejectedRequest($request, $request->cookies);
            return [
                "status" => 400,
                "data" => $this->getErrorMessage('no-cookie')
            ];
        }
    }
    public function getResponses(Request $request, $selectedUser, $picasso = false): string|array
@@ -43,7 +59,7 @@
                    $responseContent = $this->getResponseArgumentsBased($userResponses, $methodUri, $reqParams);
                    return $responseContent;
                } else {
                    return $this->getErrorMessage('no-method-on-user');
                    return $methodUri . " " . $selectedUser . " " . $this->getErrorMessage('no-method-on-user');
                }
            } else {
                return $this->getErrorMessage('no-method');
@@ -63,7 +79,7 @@
                'errorCode' => (string) 0,
                'username' => (string) $sampleResponseObject["Username"],
                'next_user' => (string) 'N',
                //'token' => '415F2B31F1C15FA45C9A6E1CBEB0ADF3'
                'token' => (string) 'xno:' . $selectedUser,
            ];
        } else {
            $resp = [
@@ -87,7 +103,7 @@
                'logged' => (string) 1,
                'errorCode' => (string) 0,
                'username' => (string) $sampleResponseObject["Username"],
                'token' => (string) '415F2B31F1C15FA45C9A6E1CBEB0ADF3',
                'token' => (string) 'xno:' . $selectedUser,
                'next_user' => (string) 'N',
            ];
        } else {
@@ -140,16 +156,18 @@
    private function getErrorMessage(string $code): string
    {
        switch ($code) {
            case 'no-cookie':
                return 'No cookie No Party. Send your CAuthCookie or SESSIONID cookie';
            case 'no-sso-user':
                return 'this sso user doesnt exist. check your CAuthCookie value';
                return 'This sso user doesnt exist. Check your CAuthCookie cookie value';
            case 'no-picasso-user':
                return 'this picasso user doesnt exist. check your SSOSESSIONID value';
                return 'This picasso user doesnt exist. Check your SSOSESSIONID coookie value';
            case 'no-method-on-user':
                return 'this method response is not set for this user';
                return 'This method response is not set for this user. Check this server database.';
            case 'no-method':
                return 'couldnt detect requested method';
                return 'Couldnt detect requested method. Check your request url.';
            default:
                return 'couldnt detect proper response. check your syntax';
                return 'Couldnt detect proper response.';
        }
    }