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

queryParams No Longer Working #619

Closed
daniel-klingensmith-jamf opened this issue Aug 30, 2024 · 5 comments
Closed

queryParams No Longer Working #619

daniel-klingensmith-jamf opened this issue Aug 30, 2024 · 5 comments
Assignees
Labels

Comments

@daniel-klingensmith-jamf
Copy link

daniel-klingensmith-jamf commented Aug 30, 2024

I'm unable to get queryParams to work since the change to how they are processed. Neither of the following syntaxes seems to work.

  - method: GET
    path: "/v1/assets-and-licenses"
    queryParams:
      accountId: 1001
    response:
      file: account-1001.json

or

  - method: GET
    path: "/v1/assets-and-licenses"
    queryParams:
        accountId:
            operator: EqualTo
            value: 1001
    response:
      file: account-1001.json

Request:
https://<lambda>.lambda-url.us-east-1.on.aws/v1/assets-and-licenses?accountId=1001

Imposter Logs:

i.g.i.c.S3FileDownloader - File read [675 bytes] from S3: s3://imposter-bucket/ABC-123/account-1001.json
i.g.i.c.S3FileDownloader - Downloaded file: s3://imposter-bucket/ABC-123/account-1001.json [19578 bytes] to: /tmp/s3-imposter-bucket3810744698872442139/account-1001.json
…
i.g.i.p.r.RestPluginImpl - Adding handler: GET -> /v1/assets-and-licenses
…
i.g.i.a.AbstractHandler - Received request: GET /v1/assets-and-licenses
i.g.i.p.r.RestPluginImpl - Handling object request for: GET http://<lambda>.lambda.lambda-url.us-east-1.on.aws/v1/assets-and-licenses
i.g.i.s.ResponseServiceImpl - Response file and data are blank for [84c11c84-dbf0-445d-b46e-976b0cd36aa0] GET http://<lambda>.lambda.lambda-url.us-east-1.on.aws/v1/assets-and-licenses
i.g.i.s.ResponseServiceImpl - Returning empty response for [84c11c84-dbf0-445d-b46e-976b0cd36aa0] GET http://<lambda>.lambda.lambda-url.us-east-1.on.aws/v1/assets-and-licenses

Running Imposter 4.0.3 by zip file in S3

@outofcoffee outofcoffee self-assigned this Sep 6, 2024
@outofcoffee
Copy link
Owner

Hi @daniel-klingensmith-jamf, I'm not able to reproduce this locally:

mock-config.yaml

plugin: rest

resources:
  - method: GET
    path: "/v1/assets-and-licenses"
    queryParams:
      accountId: 1001
    response:
      file: account-1001.json

account-1001.json

{
    "accountId": 1001
}

Command

$ curl "http://localhost:8080/v1/assets-and-licenses?accountId=1001"
{
    "accountId": 1001
}

Logs

09:54:45 DEBUG i.g.i.c.u.ConfigUtil - Loading configuration file: /Users/me/projects/imposter/issues/issue619/mock-config.yaml
09:54:47 DEBUG i.g.i.p.PluginManager - Loaded 7 plugin(s): [js-detector, store-detector, meta-detector, js-graal, store-inmem, config-detector, rest]
09:54:48 DEBUG i.g.i.p.r.RestPluginImpl - Adding handler: GET -> /v1/assets-and-licenses
09:54:48 INFO  i.g.i.Imposter - Mock engine up and running on http://localhost:8080
09:55:04 DEBUG i.g.i.h.AbstractResourceMatcher - Matched resource config for GET http://localhost:8080/v1/assets-and-licenses?accountId=1001
09:55:04 INFO  i.g.i.p.r.RestPluginImpl - Handling object request for: GET http://localhost:8080/v1/assets-and-licenses?accountId=1001
09:55:04 INFO  i.g.i.s.ResponseFileServiceImpl - Serving response file account-1001.json for GET http://localhost:8080/v1/assets-and-licenses?accountId=1001 with status code 200
09:55:04 DEBUG i.g.i.s.ResponseServiceImpl - Inferred application/json content type

Perhaps there's other configuration conflicting with this resource?

Also, does this happen locally for you or just in Lambda?

@outofcoffee
Copy link
Owner

outofcoffee commented Sep 6, 2024

Also seems to work when deployed to Lambda:

$ imposter remote deploy
INFO[0000] deploying workspace 'test' to awslambda remote
DEBU[0000] using role: arn:aws:iam::000000000000:role/ImposterLambdaExecutionRole
DEBU[0000] lambda binary '4.0.3' already present
INFO[0000] bundling 3 files from workspace
DEBU[0000] created deployment package
DEBU[0001] bucket imposter-mock-b2b2083400684064b285b44be25b6814 exists
DEBU[0005] uploaded file /var/folders/vx/zcg6m13956bblwgn6yb4hgsc0000gn/T/imposter-bundle-3861492318.zip to bucket imposter-mock-b2b2083400684064b285b44be25b6814
DEBU[0005] updating function code for: arn:aws:lambda:eu-west-2:000000000000:function:imposter-issue619
INFO[0008] updated function code for: arn:aws:lambda:eu-west-2:000000000000:function:imposter-issue619
DEBU[0008] configuring URL for function: arn:aws:lambda:eu-west-2:000000000000:function:imposter-issue619
DEBU[0008] function URL already configured: https://redacted.lambda-url.eu-west-2.on.aws/
DEBU[0008] anonymous URL access permission already exists
INFO[0008] deployed workspace 'test'
Base URL: https://redacted.lambda-url.eu-west-2.on.aws/
Spec:
Status: https://redacted.lambda-url.eu-west-2.on.aws/system/status

$ curl "https://redacted.lambda-url.eu-west-2.on.aws/v1/assets-and-licenses?accountId=1001"
{
    "accountId": 1001
}

@daniel-klingensmith-jamf
Copy link
Author

daniel-klingensmith-jamf commented Sep 6, 2024

I tried a few permutations and found that the issue happens when the Query Parameter starts with a '0'. I did some cleanup of the scenario before opening the ticket so hadn't run exactly what I had used in the original comment.

resources:
  - method: GET
    path: "/v1/assets-and-licenses"
    queryParams:
      accountId: 001
    response:
      file: 1001.json

curl localhost:8080/v1/assets-and-licenses\?accountId=001

@outofcoffee
Copy link
Owner

Ah, OK. In YAML 1.1, a value starting with a zero is interpreted as octal. So 001 is interpreted as octal 1, not a string "001".

Side note
This behaviour changed in YAML 1.2, which required octal numbers to start with 0o.

Sadly Jackson, which is used for YAML parsing in this project, makes use of a version of snakeyaml that supports YAML 1.1, not 1.2.

For your use-case, you can quote the value in the config file as "001" and it should be treated by the YAML parser as a string rather than an octal value.

Hope this helps!

@daniel-klingensmith-jamf
Copy link
Author

Query Parameters on 4.0.3 are working for me now after quoting, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants