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

Add base64Encode/base64Decode filter #2145

Open
jcamiel opened this issue Nov 10, 2023 Discussed in #1921 · 4 comments
Open

Add base64Encode/base64Decode filter #2145

jcamiel opened this issue Nov 10, 2023 Discussed in #1921 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers topic: filters

Comments

@jcamiel
Copy link
Collaborator

jcamiel commented Nov 10, 2023

Discussed in #1921

Originally posted by eydun September 12, 2023
My login-request returns a token, which I am able to capture with jsonpath.

But before I can use this token for authorization in the second request, I need to base64 encode it. Is that possible?

Add base64Encode/base64Decode filter.

  • base64Encode: input is in bytes, output is a string
  • base64Decode: input is a string, output is bytes
GET https://foo.com/data.bin
HTTP 200
[Asserts]
bytes base64Encode == "SGVsbG8="
body == "Hello"

Note: to be more useful, we need to have also a filter going from bytes to string for instance utf8Encode/utf8Decode:

  • utf8Encode: input is a string, output is in bytes
  • utf8Decode: input is in bytes, output is a string
GET https://api.foo.com
HTTP 200
[Asserts]
jsonpath "$.data" base64Decode == hex,534756736247383d;
jsonpath "$.data" base64Decode utf8Decode == "Hello"
jsonpath "$.data" utf8Encode base64Encode == "SGVsbG8="

? Do we need a strEncode "encoding"/strDecode "encoding" filter with arbitrary encoding ? Like strEncode "gb-2317"

@ashishajr
Copy link
Contributor

Hey @jcamiel, I'd love to work on this, could I take this up?

@jcamiel
Copy link
Collaborator Author

jcamiel commented Jan 21, 2025

Yes @ashishajr of course.

This could be maybe too big for only one commit / one PR.

What I propose you is to split in multiple PRs or in one PR with multiple commits so it will be easier to review (multiple PRs is preferred as we can commit to master as soon as the PRs are validated):

  1. Update grammar hurl.grammar => see docs/spec/grammar/REAME.md
  2. Implement filter base64Decode base64Encode parsing
  3. Implement filter base64Decode runtime evaluation + unit tests
  4. Implement filter base64Encode runtime evaluation + unit tests
  5. Add integration tests for base64Decode => see integration/README.md
  6. Add integration tests for base64Encode => see integration/README.md

@ashishajr
Copy link
Contributor

ashishajr commented Jan 22, 2025

Thanks @jcamiel, I'll start working on these.

Could you please tell me where I'd have to implement the parsing for the new filters, I couldn't quite find that part in code.

TODO List for myself, I'll keep coming back and updating it

@jcamiel
Copy link
Collaborator Author

jcamiel commented Jan 22, 2025

Hi @ashishajr you can look at a similar filter htmlEscape, parsing is done in hurl_core/src/parser/filter.rs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers topic: filters
Projects
None yet
Development

No branches or pull requests

2 participants