Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sourishkrout committed Mar 15, 2024
1 parent ee5094d commit c84e805
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions internal/owl/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,54 @@ func Test_Store_SensitiveKeys(t *testing.T) {
require.NoError(t, err)
require.EqualValues(t, keys, []string{"INSTRUMENTATION_KEY", "PGPASS"})
}

func Test_Store_SecretMasking(t *testing.T) {
t.Parallel()

t.Run("Short secret is masked as empty", func(t *testing.T) {
fake := []byte("SHORT_SECRET=extra-short # Secret!\n")

store, err := NewStore(withSpecsFile(".env.example", fake, true), WithEnvFile(".env", fake))
require.NoError(t, err)
require.NotNil(t, store)

snapshot, err := store.snapshot(false)
require.NoError(t, err)
require.NotNil(t, snapshot)

snapshot.sortbyKey()

snapshot0 := snapshot[0]
require.EqualValues(t, "SHORT_SECRET", snapshot0.Var.Key)
require.EqualValues(t, "Secret", snapshot0.Spec.Name)
require.EqualValues(t, true, snapshot0.Spec.Required)
require.EqualValues(t, "", snapshot0.Value.Resolved)
require.EqualValues(t, "", snapshot0.Value.Original)
require.EqualValues(t, "MASKED", snapshot0.Value.Status)
require.LessOrEqual(t, len(snapshot0.Errors), 0)
})

t.Run("Long secret greater than 24 chars shows glimpse", func(t *testing.T) {
fake := []byte("LONG_SECRET=this-is-a-extra-long-secret-which-is-much-better-practice # Secret!\n")

store, err := NewStore(withSpecsFile(".env.example", fake, true), WithEnvFile(".env", fake))
require.NoError(t, err)
require.NotNil(t, store)

snapshot, err := store.snapshot(false)
require.NoError(t, err)
require.NotNil(t, snapshot)

snapshot.sortbyKey()

snapshot0 := snapshot[0]
require.EqualValues(t, "LONG_SECRET", snapshot0.Var.Key)
require.EqualValues(t, "Secret", snapshot0.Spec.Name)
require.EqualValues(t, true, snapshot0.Spec.Required)
// codespell-ignore-next
require.EqualValues(t, "thi...ice", snapshot0.Value.Resolved)
require.EqualValues(t, "", snapshot0.Value.Original)
require.EqualValues(t, "MASKED", snapshot0.Value.Status)
require.LessOrEqual(t, len(snapshot0.Errors), 0)
})
}

0 comments on commit c84e805

Please sign in to comment.