Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Every other response fails - Endpoint examples matching order flip flops each run. #155

Open
bwinterling opened this issue Feb 13, 2017 · 1 comment

Comments

@bwinterling
Copy link

bwinterling commented Feb 13, 2017

First of all. I want to thank you for all the hard work that has been put into this tool. We're excited to use it and it has sped up our development.

Last week, something changed. When sending the same exact request, every other response is matched incorrectly. Here are some details to help with debugging:

Here's the dockerfile used with Drakov:

FROM node:boron
RUN npm install -g drakov
EXPOSE 80
WORKDIR /app
COPY . .
CMD ["drakov", "--config", "config.js"]

Here's the config.js

module.exports = {
    sourceFiles: "/app/identity.apib",
    serverPort: 80,
    public: true,
    autoOptions: true,
    header: "Authorization",
    method: "GET, POST",
    discover: true
};

The request is a simple get request to an endpoint with an Authorization header.

Here are the logs. The only difference I can see in the logs is the order in which the MATCHING occurs and the final DRAKOV response. Again, the request is identical.

Failing response or incorrect matching:

mock_identity_1  | [LOG] GET /identity/sessions
mock_identity_1  | [MATCHING] by url pattern: /identity/sessions/refresh NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/users/:id NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/user_groups/:id NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/sessions MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request header authorization = Bearer invalid.bearer.token NOT_MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request header authorization = Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxWU01aW1hRWFuNTlHVmJJQzZ0QnE2IiwianRpIjoic29tZV9qdGkifQ._WwA_3cesbxS2IpXGWe81UzJymUZfPupSErjSEAEVik MATCHED
mock_identity_1  | [MATCHING] by request content type:  actual:  MATCHED
mock_identity_1  | [MATCHING] by request content type:  actual:  MATCHED
mock_identity_1  | [MATCHING] by request body content MATCHED
mock_identity_1  | [MATCHING] by request body content MATCHED
mock_identity_1  | [DRAKOV] GET /identity/sessions Request with missing token

Correct response and matching:

mock_identity_1  | [LOG] GET /identity/sessions
mock_identity_1  | [MATCHING] by url pattern: /identity/sessions/refresh NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/users/:id NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/user_groups/:id NOT_MATCHED
mock_identity_1  | [MATCHING] by url pattern: /identity/sessions MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request header authorization = Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxWU01aW1hRWFuNTlHVmJJQzZ0QnE2IiwianRpIjoic29tZV9qdGkifQ._WwA_3cesbxS2IpXGWe81UzJymUZfPupSErjSEAEVik MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request header authorization = Bearer invalid.bearer.token NOT_MATCHED
mock_identity_1  | [MATCHING] by request header accept-version = v1 MATCHED
mock_identity_1  | [MATCHING] by request content type:  actual:  MATCHED
mock_identity_1  | [MATCHING] by request content type:  actual:  MATCHED
mock_identity_1  | [MATCHING] by request body content MATCHED
mock_identity_1  | [MATCHING] by request body content MATCHED
mock_identity_1  | [DRAKOV] GET /identity/sessions Get Session

Every time I make this identical request, it toggles back and forth between the two responses.

In my .apib file, the first two examples have an 'Authorization' header, the third does not. My guess is that every other request, this third example is matched, even though the header is present in the request, and should have matched the first example which has the same header.

First example in .apib:

+ Request

    + Headers

            Accept-Version: v1
            Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxWU01aW1hRWFuNTlHVmJJQzZ0QnE2IiwianRpIjoic29tZV9qdGkifQ._WwA_3cesbxS2IpXGWe81UzJymUZfPupSErjSEAEVik

+ Response 200 (application/json)

Third example in .apib:

+ Request

    Request with missing token

    + Headers

            Accept-Version: v1

+ Response 401 (application/json)

If I remove the third example, the problem goes away. Thing is, I need that example for Dredd contract testing. Any help in resolving this would be greatly appreciated.

@bwinterling
Copy link
Author

On closer look (thanks for the better log messages!), the endpoint in question has three examples. Looks like each time, the order they are processed flips. (1,2,3) on the first run. (3,2,1) on the second run. It would be nice if the behavior was always (1,2,3) so that you can put more explicit endpoint first, and more generic (catch all) endpoints later, with predictable results.

This becomes more important when using Dredd for contract testing, wanting to cover more request / response scenarios.

@bwinterling bwinterling changed the title Every other response fails. Every other response fails - Endpoint examples matching order flip flops each run. Feb 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant