Skip to content

Commit

Permalink
Add multi line env check
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-asawicki committed Nov 27, 2024
1 parent 94faebf commit eb167d2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
36 changes: 28 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,40 @@ jobs:
- name: GH Actions env
run: echo "$GITHUB_ACTIONS"

- name: Experiment
- name: Experiment single line env
run: echo "::add-mask::$TEST_SF_TF_ONE_LINER"
env:
TEST_SF_TF_ONE_LINER: ${{ secrets.TEST_SF_TF_ONE_LINER }}

- name: Experiment multiple
- name: Experiment multiple lines env
run: echo "::add-mask::$TEST_SF_TF_MULTI_LINER"
env:
TEST_SF_TF_MULTI_LINER: ${{ secrets.TEST_SF_TF_MULTI_LINER }}

- name: Experiment all lines from env
run: |
while IFS= read -r line || [[ -n $line ]]; do
echo "masking $line"
echo "::add-mask::$line"
done < <(printf '%s' "$TEST_SF_TF_MULTI_LINE")
done < <(printf '%s' "$TEST_SF_TF_ALL_LINES")
env:
TEST_SF_TF_MULTI_LINE: ${{ secrets.TEST_SF_TF_MULTI_LINE }}
TEST_SF_TF_ALL_LINES: ${{ secrets.TEST_SF_TF_ALL_LINES }}

- name: Echo
run: echo "very secret info"
- name: Echo single line env content
run: |
echo "very secret info"
echo "$TEST_SF_TF_ONE_LINER"
env:
TEST_SF_TF_ONE_LINER: ${{ secrets.TEST_SF_TF_ONE_LINER }}

- name: Echo multiple
- name: Echo multiple lines env content
run: |
echo "it\nworks\nthis way\n.\n!@#$%^&*()_+=-1234567890"
echo "$TEST_SF_TF_MULTI_LINER"
env:
TEST_SF_TF_MULTI_LINER: ${{ secrets.TEST_SF_TF_MULTI_LINER }}

- name: Echo different lines from all lines env
run: |
echo "different space-separated"
echo "really, really,"
Expand All @@ -66,14 +82,18 @@ jobs:
echo "different space-separated really, really, really secret infos"
echo "different"
echo "infos"
echo "$TEST_SF_TF_ALL_LINES"
env:
TEST_SF_TF_ALL_LINES: ${{ secrets.TEST_SF_TF_ALL_LINES }}

- name: Install dependencies
run: make dev-setup

- run: make test-experiment
env:
TEST_SF_TF_ONE_LINER: ${{ secrets.TEST_SF_TF_ONE_LINER }}
TEST_SF_TF_MULTI_LINE: ${{ secrets.TEST_SF_TF_MULTI_LINE }}
TEST_SF_TF_MULTI_LINER: ${{ secrets.TEST_SF_TF_MULTI_LINER }}
TEST_SF_TF_ALL_LINES: ${{ secrets.TEST_SF_TF_ALL_LINES }}

- name: find comment
if: ${{ always() }}
Expand Down
27 changes: 22 additions & 5 deletions pkg/experiments/experiment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_experiments(t *testing.T) {
})

// This test assumes that TEST_SF_TF_ONE_LINER is set to `very secret info`
t.Run("masking from env", func(t *testing.T) {
t.Run("masking from single line env", func(t *testing.T) {
testenvs.AssertEnvSet(t, "TEST_SF_TF_ONE_LINER")

value := os.Getenv("TEST_SF_TF_ONE_LINER")
Expand All @@ -78,15 +78,32 @@ func Test_experiments(t *testing.T) {
assert.Equal(t, "secret info", output)
})

// This test assumes that TEST_SF_TF_MULTI_LINE is set to:
// This test assumes that TEST_SF_TF_MULTI_LINER is set to:
// it
// works
// this way
// .
// !@#$%^&*()_+=-1234567890
t.Run("masking from multi line env", func(t *testing.T) {
testenvs.AssertEnvSet(t, "TEST_SF_TF_MULTI_LINER")

value := os.Getenv("TEST_SF_TF_MULTI_LINER")

t.Log(value)
t.Log("it\nworks\nthis way\n.\n!@#$%^&*()_+=-1234567890")
t.Log("it works this way . !@#$%^&*()_+=-1234567890")
t.Log("it works")
})

// This test assumes that TEST_SF_TF_ALL_LINES is set to:
// different space-separated
// really, really,
// really
// secret infos
t.Run("masking from multiple env", func(t *testing.T) {
testenvs.AssertEnvSet(t, "TEST_SF_TF_MULTI_LINE")
t.Run("masking all lines from env", func(t *testing.T) {
testenvs.AssertEnvSet(t, "TEST_SF_TF_ALL_LINES")

value := os.Getenv("TEST_SF_TF_MULTI_LINE")
value := os.Getenv("TEST_SF_TF_ALL_LINES")

t.Log(value)
t.Log("different space-separated really, really, really secret infos")
Expand Down

0 comments on commit eb167d2

Please sign in to comment.