Verifying SHA-256 of a file #3933
-
|
I'm trying to write my first Hurl (version 5.0.1) script to validate a proxy for a MaxMind API proxy.
What I want do to is retrieve the SHA256 file, saved the SHA and then request the actual file and compare checksums. This fails as follows: Basically I can't work out how to resolve this issue to convert the bytes into a string or vice-versa. Thank you in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
|
Hi @mdodds-cns Unfortunately I don't think we have implemented what you need! We have a decode filter that convert bytes to string given an encoding. But that's not exactly what you want, you want a filter that convert hexadecimal representation string to bytes. What we could do either:
expected_sha256: body regex "([a-f0-9]{64})\\s+[^\\s]+" fromHex
...
sha256 == {{expected_sha256}}
expected_sha256: body regex "([a-f0-9]{64})\\s+[^\\s]+"
...
sha256 toString == {{expected_sha256}}
expected_sha256: body regex "([a-f0-9]{64})\\s+[^\\s]+"
...
sha256 decode "hex" == {{expected_sha256}}I quite like the third solution, as it fits into the As your use case is a rather common use case, I think we're going to address it soon. @fabricereix @lepapareil any preferences? In the meantime, you can still hardcode the GET https://example.org/data.tar.gz
HTTP 200
[Asserts]
sha256 == hex,039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81; |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for investigating this! It does feel like this would be a useful enhancement for Hurl as this is a common pattern when downloading files. |
Beta Was this translation helpful? Give feedback.
-
|
Ho @mdodds-cns The filter GET https://{{DOMAIN}}/geoip/databases/GeoLite2-Country-CSV/download?suffix=zip
HTTP 200
[Asserts]
sha256 toHex == {{expected_sha256}}
sha256 toHex == "039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81" |
Beta Was this translation helpful? Give feedback.
Hi @mdodds-cns
Unfortunately I don't think we have implemented what you need!
We have a decode filter that convert bytes to string given an encoding. But that's not exactly what you want, you want a filter that convert hexadecimal representation string to bytes.
What we could do either:
fromHexorfromHexString: this way you could do:expected_sha256: body regex "([a-f0-9]{64})\\s+[^\\s]+" fromHex ... sha256 == {{expected_sha256}}toStringfilter on bytes to convert back to an hexadecimal string representationexpected_sha256: body regex "([a-f0-9]{64})\\s+[^\\s]+" ... sha256 toString == {{expected_sha256}}decodecould accept the encodinghexso thatβ¦