Skip to content

[BUG] ApiFunctional TestFramework GraphQL Client Parses Headers Improperly #26425

Closed
@damienwebdev

Description

@damienwebdev

Preconditions (*)

Magento v2.3.3

Steps to reproduce (*)

  1. Make a call with the GraphQlAbstract::graphQlQueryWithResponseHeaders
  2. Have a header in the response like: Access-Control-Allow-Origin: https://www.example.com
  3. See that the header does NOT show up in the headers array

Expected result (*)

  1. Have a header in the headers array like: ['Access-Control-Allow-Origin'] => 'https://www.example.com'

Actual result (*)

See above.

This is due to a failed preg_split logic in:

https://github.com/magento/magento2/blame/6b4a82b8554917ba78f7bc84ada8ea05a85aca92/dev/tests/api-functional/framework/Magento/TestFramework/TestCase/GraphQl/Client.php#L210

/**
     * Parse response headers into associative array
     *
     * @param string $headers
     * @return array
     */
    private function processResponseHeaders(string $headers): array
    {
        $headersArray = [];

        $headerLines = preg_split('/((\r?\n)|(\r\n?))/', $headers);
        foreach ($headerLines as $headerLine) {
            $headerParts = preg_split('/: /', $headerLine);
            if (count($headerParts) == 2) {
                $headersArray[trim($headerParts[0])] = trim($headerParts[1]);
            } elseif (preg_match('/HTTP\/[\.0-9]+/', $headerLine)) {
                $headersArray[trim('Status-Line')] = trim($headerLine);
            }
        }

        return $headersArray;
    }

It should preg_split with a limit of 2:

$headerParts = preg_split('/: /', $headerLine, 2);

cc: @danielrenaud @danmooney2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: TestFrameworkIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPAPPartners acceleration programProject: GraphQLReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions