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

Some API definition routes are not parsed correctly #8

Open
255kb opened this issue May 3, 2023 · 2 comments
Open

Some API definition routes are not parsed correctly #8

255kb opened this issue May 3, 2023 · 2 comments
Labels
blocked Issue blocked by another one bug Something isn't working

Comments

@255kb
Copy link
Member

255kb commented May 3, 2023

Describe the bug
Discussed in mockoon/mockoon#1028
Some API definition (AWS cognito) are not parsed correctly and show a header in the endpoint. It's also prefixed with a # which makes calling the endpoint impossible

To Reproduce
Import the definition and try to call the endpoint.

Expected behavior
Endpoint should be ListUserPools instead of #X-Amz-Target=AWSCognitoIdentityProviderService.ListUserPools.

@255kb 255kb self-assigned this May 3, 2023
@255kb 255kb added the bug Something isn't working label May 3, 2023
@Havrin
Copy link

Havrin commented May 9, 2023

Unfortunately, I don't think this can work. At least for the AWS PHP SDK, the Clients, for example the CognitoIdentityProviderClient that would call the example above with ListUserPools, is always using / as route. The client distinguishes the different methods by header, not by route.
Example output from mockoon logging of a ListUserPools call with CognitoIdentityProviderClient in a PHP application:

{
  "level": "info",
  "message": "POST / | 200",
  "mockName": "mockoon-amazon-cognito-identity-provider",
  "timestamp": "2023-05-09T11:49:51.180Z",
  "transaction": {
    "proxied": false,
    "request": {
      "body": "{\"MaxResults\":30}",
      "headers": [
        {
          "key": "authorization",
          "value": "AWS4-HMAC-SHA256 Credential=XXX/20230509/eu-central-1/cognito-idp/aws4_request, SignedHeaders=host;x-amz-date;x-amz-target;x-amz-user-agent, Signature=XXX"
        },
        {
          "key": "aws-sdk-invocation-id",
          "value": "XXX"
        },
        {
          "key": "aws-sdk-retry",
          "value": "0/0"
        },
        {
          "key": "content-length",
          "value": "17"
        },
        {
          "key": "content-type",
          "value": "application/x-amz-json-1.1"
        },
        {
          "key": "host",
          "value": "mockoon:3000"
        },
        {
          "key": "user-agent",
          "value": "aws-sdk-php/3.268.16 OS/Linux/5.15.90.1-microsoft-standard-WSL2 lang/php/8.2.4 GuzzleHttp/7"
        },
        {
          "key": "x-amz-date",
          "value": "20230509T114951Z"
        },
        {
          "key": "x-amz-target",
          "value": "AWSCognitoIdentityProviderService.ListUserPools"
        },
        {
          "key": "x-amz-user-agent",
          "value": "aws-sdk-php/3.268.16 OS/Linux/5.15.90.1-microsoft-standard-WSL2 lang/php/8.2.4"
        }
      ],
      "method": "POST",
      "params": [],
      "query": "",
      "queryParams": {},
      "route": "/",
      "urlPath": "/"
    },
    "response": {
      "body": "{}",
      "headers": [
        {
          "key": "content-length",
          "value": "2"
        },
        {
          "key": "content-type",
          "value": "application/json; charset=utf-8"
        }
      ],
      "statusCode": 200,
      "statusMessage": "OK"
    },
    "routeResponseUUID": "e162096b-18ba-40b8-99d2-f8f1dc42fc9b",
    "routeUUID": "5114dd4f-7643-4acd-b736-303163bc1bd9"
  }
}

I changed the Cognito json provided by mockoon to not have #X-Amz-Target=XXX in it's route which results in 101 Routes for / and I will always receive the result for the first / route 🥲
There is no way to add rules to route matching, right? Duplicate routes by path but Route A is called when Header A is sent and Route B matches if Header B is sent.

Edit: temporary solution at least for my case: use one route with many responses + rules.

@255kb
Copy link
Member Author

255kb commented Jul 4, 2023

Sorry, your message slipped my mind for a long time!
There is no rules system at the environment level (there is an opened issue though), only at the route level.
I guess it would be possible to automatically create a route with multiple header rules. But I guess it would become hard to manage at one point.
I think this improvement should be done after a global rules system has been added.

@255kb 255kb added the blocked Issue blocked by another one label Jul 4, 2023
@255kb 255kb removed their assignment Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Issue blocked by another one bug Something isn't working
Projects
Status: Backlog (long term planning)
Development

No branches or pull requests

2 participants