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

Redacts secrets from JSON report #3630

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions integration/hurl/tests_failed/assert_secret.err

This file was deleted.

19 changes: 19 additions & 0 deletions integration/hurl/tests_failed/assert_secret.err.pattern
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
HTTP/1.1 200
Server: Werkzeug/<<<.*?>>> Python/<<<.*?>>>
Date: <<<.*?>>>
Content-Type: text/html; charset=utf-8
Content-Length: 9
Server: Flask Server
Connection: close

Hello ***

error: Assert body value
--> tests_failed/assert_secret.hurl:3:1
|
| GET http://localhost:8000/secret-failed
| ...
3 | "Hello ***"
| ^ actual value is <Hello ***>
|

33 changes: 32 additions & 1 deletion integration/hurl/tests_failed/assert_secret.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,35 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'

hurl --secret name=Alice tests_failed/assert_secret.hurl
if (Test-Path -Path build/assert_secret) {
Remove-Item -Recurse build/assert_secret
}

# We want to check leaks and do not stop at the first error
$ErrorActionPreference = 'Continue'

hurl --secret name1=Alice `
--secret name2=Bob `
--error-format long `
--report-html build/assert_secret/report-html `
--report-json build/assert_secret/report-json `
tests_failed/assert_secret.hurl

$secrets = @("Alice", "Bob")

$files = @(Get-ChildItem -Filter *.html -Recurse build/assert_secret/report-html)
$files += @(Get-ChildItem -Filter *.json build/assert_secret/)
$files += @(Get-ChildItem tests_failed/assert_secret.err.pattern)

foreach ($secret in $secrets) {
foreach ($file in $files) {
# Don't search leaks in sources
if ($file.name.EndsWith("source.html")) {
continue
}
if (Get-Content $file | Select-String -CaseSensitive $secret) {
echo "Secret <$secret> have leaked in $file"
exit 1
}
}
}
37 changes: 36 additions & 1 deletion integration/hurl/tests_failed/assert_secret.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
#!/bin/bash
set -Eeuo pipefail

hurl --secret name=Alice tests_failed/assert_secret.hurl
rm -rf build/assert_secret

# We want to check leaks and do not stop at the first error
set +euo pipefail

hurl --secret name1=Alice \
--secret name2=Bob \
--error-format long \
--report-html build/assert_secret/report-html \
--report-json build/assert_secret/report-json \
tests_failed/assert_secret.hurl

ret=$?

secrets=("Alice" "Bob")

files=$(find build/assert_secret/report-html/*.html \
build/assert_secret/report-html/**/*.html \
build/assert_secret/report-json/*.json \
tests_failed/assert_secret.err.pattern)

for secret in "${secrets[@]}"; do
for file in $files; do
# Don't search leaks in sources
if [[ "$file" == *source.html ]]; then
continue
fi
if grep -q "$secret" "$file"; then
echo "Secret <$secret> have leaked in $file"
exit 1
fi
done
done

# We use the exit code of the Hurl command
exit $ret
3 changes: 2 additions & 1 deletion integration/hurl/tests_ok/secret.err.pattern
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@
* start_transfer: <<<\d+>>> µs
* total: <<<\d+>>> µs
*
* Writing HTML report to build/secret
* Writing HTML report to build/secret/report-html
* Writing JSON report to build/secret/report-json
9 changes: 6 additions & 3 deletions integration/hurl/tests_ok/secret.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ hurl --very-verbose `
--secret a=secret1 `
--secret b=secret2 `
--secret c=12345678 `
--report-html build/secret `
--report-html build/secret/report-html `
--report-json build/secret/report-json `
tests_ok/secret.hurl

$secrets = @("secret1", "secret2", "secret3", 12345678)
$secrets = @("secret1", "secret2", "secret3", "12345678")

$files = Get-ChildItem -Filter *.html -Recurse build/secret
$files = @(Get-ChildItem -Filter *.html -Recurse build/secret/report-html)
$files += @(Get-ChildItem -Filter *.json build/secret/report-json)
$files += @(Get-ChildItem tests_ok/secret.err.pattern)

foreach ($secret in $secrets) {
foreach ($file in $files) {
Expand Down
8 changes: 6 additions & 2 deletions integration/hurl/tests_ok/secret.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ hurl --very-verbose \
--secret a=secret1 \
--secret b=secret2 \
--secret c=12345678 \
--report-html build/secret \
--report-html build/secret/report-html \
--report-json build/secret/report-json \
tests_ok/secret.hurl

secrets=("secret1" "secret2" "secret3" "12345678")

files=$(find build/secret/*.html build/secret/**/*.html tests_ok/secret.err.pattern)
files=$(find build/secret/report-html/*.html \
build/secret/report-html/**/*.html \
build/secret/report-json/*.json \
tests_ok/secret.err.pattern)

for secret in "${secrets[@]}"; do
for file in $files; do
Expand Down
Loading
Loading