davide.cucurnia@vola.it
2024-02-07 bdead46014e9854ef4fa2adba5ad0cd29737937a
nomi variabili
2 files modified
58 ■■■■■ changed files
app/Http/Controllers/FakeResponder/FakeResponder.php 2 ●●●●● patch | view | raw | blame | history
app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php 56 ●●●●● patch | view | raw | blame | history
app/Http/Controllers/FakeResponder/FakeResponder.php
@@ -11,8 +11,6 @@
class FakeResponder extends Controller
{
    public string $cookieFakeSSOName = "CAuthCookie";
    public string $cookieFakePicassoName = "SSOSESSIONID";
    public array $headers;
    public VolaFakeHTTPResponder $VolaFakeSSO;
app/Vola/Services/VolaFakeHTTPResponder/VolaFakeHTTPResponder.php
@@ -14,49 +14,49 @@
{
    public array $data;
    public array $headers;
    private array $sso_XML;
    private array $xmlResponses;
    public function __construct()
    {
        $this->sso_XML = config('devtools.fake_sso_profiles');
        $this->xmlResponses = config('devtools.fake_sso_profiles');
    }
    public function getModelBasedResponses($request, $testUser, $picasso = false): string|array
    public function getModelBasedResponses($request, $selectedUser, $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
    public function getResponses(Request $request, $selectedUser, $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);
                $loginResponse = ($picasso) ? $this->getLoggedPicasso($selectedUser) : $this->getLoggedLegacy($selectedUser);
                return $loginResponse;
            } else if ($methodUri != "") {
                // controllo metodo e parametri e conseguente risposta
                $userResponses = $this->getUserResponseSet($testUser, $picasso);
                $userResponses = $this->getUserResponseGroup($selectedUser, $picasso);
                if (isset($userResponses[$methodUri])) {
                    $responseContent = $this->getResponseArgumentsBased($userResponses, $methodUri, $reqParams);
                    return $responseContent;
                } else {
                    return 'user is not set for this method';
                    return $this->getErrorMessage('no-method-on-user');
                }
            } else {
                return 'wrong-request-no-such-method';
                return $this->getErrorMessage('no-method');
            }
    }
    public function getLoggedPicasso($testUser): string|array
    public function getLoggedPicasso($selectedUser): string|array
    {
        if (isset($_COOKIE["SSOSESSIONID"])) {
            if (!isset($this->sso_XML[$testUser]["picasso"])) {
                return 'this picasso user doesnt exist. check your SSOSESSIONID value';
            if (!isset($this->xmlResponses[$selectedUser]["picasso"])) {
                return $this->getErrorMessage('no-picasso-user');
            }
            $sampleResponseString = Arr::first($this->sso_XML[$testUser]["picasso"]["getWebcustomerInformation"]["parametri"]["k"] );
            $sampleResponseString = Arr::first($this->xmlResponses[$selectedUser]["picasso"]["getWebcustomerInformation"]["parametri"]["k"] );
            $sampleResponseObject = Utils::convertXMLStrToArray($sampleResponseString);
            $resp = [
                'logged' => (string) 1,
@@ -75,13 +75,13 @@
        return $xml;
    }
    public function getLoggedLegacy($testUser): string|array
    public function getLoggedLegacy($selectedUser): string|array
    {
        if (isset($_COOKIE["CAuthCookie"])) {
            if (!isset($this->sso_XML[$testUser]["sso"])) {
                return 'this user doesnt exist. check your CAuthCookie value';
            if (!isset($this->xmlResponses[$selectedUser]["sso"])) {
                return $this->getErrorMessage('no-sso-user');
            }
            $sampleResponseString = Arr::first($this->sso_XML[$testUser]["sso"]["getWebcustomerInformation"]["parametri"]["k"] );
            $sampleResponseString = Arr::first($this->xmlResponses[$selectedUser]["sso"]["getWebcustomerInformation"]["parametri"]["k"] );
            $sampleResponseObject = Utils::convertXMLStrToArray($sampleResponseString);
            $resp = [
                'logged' => (string) 1,
@@ -123,18 +123,34 @@
    /**
     * @param Request $request
     * @param mixed $testUser
     * @param mixed $selectedUser
     * @param bool $picasso
     * @return array|mixed
     */
    private function getUserResponseSet(mixed $testUser, bool $picasso): array
    private function getUserResponseGroup(mixed $selectedUser, bool $picasso): array
    {
        if ($picasso) {
            $userMethods = $this->sso_XML[$testUser]["picasso"] ?? [];
            $userMethods = $this->xmlResponses[$selectedUser]["picasso"] ?? [];
        } else {
            $userMethods = $this->sso_XML[$testUser]["sso"] ?? [];
            $userMethods = $this->xmlResponses[$selectedUser]["sso"] ?? [];
        }
        return $userMethods;
    }
    private function getErrorMessage(string $code): string
    {
        switch ($code) {
            case 'no-sso-user':
                return 'this sso user doesnt exist. check your CAuthCookie value';
            case 'no-picasso-user':
                return 'this picasso user doesnt exist. check your SSOSESSIONID value';
            case 'no-method-on-user':
                return 'this method response is not set for this user';
            case 'no-method':
                return 'couldnt detect requested method';
            default:
                return 'couldnt detect proper response. check your syntax';
        }
    }
}