-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
encoding.b64decode/encode fails on binary data #1798
Comments
Hi @rtolar, Unfortunately, this hasn't been worked on specifically as there hasn't been time and it will be a breaking change, so we will prefer if we either find a way for it to not be breaking or get it right the second time, so there isn't a third ;). I have done some experimenting, but am hitting a strange problem where instead of Also heavily related to #1020 |
I have found the issue (:facepalm:) in my code and it is now working as expected |
I even managed to get it working directly with ArrayBuffers. This though is even more ... patched together from other sources [1][2] so it likely has more corner cases, although it also has promise so 🤷♂️ maybe it will be useful to someone. We would probably need to have those fixed in k6 as that will also probably be a lot faster, but in the meantime, there is at least a way, that will also work without xk6, and so in cloud or for users who can't or don't want to use xk6. |
Thanks for looking at this! It looks like the ArrayBuffer approach would also require changes to the signing functions to accept ArrayBuffers instead of uint8[]? I tried a quick test using the Base64Binary.decodeArrayBuffer() method you provided, and it generates an error trying to pass the decoded result into a signing function.
So far, my workaround is to directly download and use the CryptoJS libraries. Then, use the CryptoJS methods directly:
This seems to work, and I'm getting the correct signatures I need.
|
I missed that part - yeah this won't work with the ArrayBuffer approach. This will need changes to the crypto library or one more I take it you didn't want to use the xk6 extension for some reason? |
I'm not opposed to using extensions, I'm just not familiar with xk6. I got it to work building the xk6 version, but the go tests themselves fail. Is that expected? Detailed steps:
$ which go gvm gos (installed) => go1.15
Here's the local k6 build:
|
Hi @rtolar , yes you are correct in what xk6 does. And unfortunately, I did not have time to try and make the test work for xk6-encoding, as that is just a PoC ;). The tests are just a copy of the same tests that are in the k6 codebase currently. So yes ... it is expected for the tests to fail, although not desirable :). I am taking PRs though ;) |
Any update on when this might be fixed? |
@juwatanabe this has been fixed, by #1800 and #1841 it was just not closed :( |
The base64encode and decode functions do not correctly handle binary input.
I have a base64-encoded string that was generated elsewhere.
When I use encoding.b64decode(), and feed that into a crypto.hmac() call, I get an incorrect value.
I believe the problem to be the encoding.b64decode/encode functions.
See below for a test case that illustrates the decoding issue.
Environment
k6 version:
$ k6 version
k6 v0.29.0 ((devel), go1.15.4, darwin/amd64)
OS and version:
MacOS Catalina 10.15.7
Docker version and image, if applicable:
n/a
Expected Behavior
Given a base64-encoded string, use the decode function to get the original data, and then encode() it again.
The end result should be the original string.
Actual Behavior
Round-trip encoding fails.
Steps to Reproduce the Problem
Possibly related to: #1770 ?
I created a github project that recreates this issue.
See github project : https://github.com/rtolar/2021-01-13-k6-bug-b64decode
The k6 script shows the roundtrip encoding/decode failure, and a node.js script which does the same thing using the crypto-js library.
Here's a copy of the k6 code.
The text was updated successfully, but these errors were encountered: