-
Notifications
You must be signed in to change notification settings - Fork 45
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
Fix the fact that some GCP env vars are immune to WithDisallowEnvVars #250
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ const ( | |
// TestGcpKeyIdAfterConfig will test the result of calling the wrapper's KeyId() | ||
// after it's configured with various options | ||
func TestGcpKeyIdAfterConfig(t *testing.T) { | ||
t.Parallel() | ||
// Now test for cases where CKMS values are provided | ||
checkAndSetEnvVars(t) | ||
ctx := context.Background() | ||
|
@@ -91,10 +90,55 @@ func TestGcpKeyIdAfterConfig(t *testing.T) { | |
} | ||
}) | ||
} | ||
} | ||
|
||
// TestDisableEnv makes sure that we properly get all our settings from a configuration | ||
// map instead of the environment variables | ||
func TestDisableEnv(t *testing.T) { | ||
// Now test for cases where CKMS values are provided | ||
checkAndSetEnvVars(t) | ||
|
||
configMap := map[string]string{ | ||
"project": os.Getenv(EnvGcpCkmsWrapperProject), | ||
"region": os.Getenv(EnvGcpCkmsWrapperLocation), | ||
"key_ring": os.Getenv(EnvGcpCkmsWrapperKeyRing), | ||
"crypto_key": os.Getenv(EnvGcpCkmsWrapperCryptoKey), | ||
} | ||
|
||
// Reset the env values to validate we are using the config map ones | ||
t.Setenv(EnvGcpCkmsWrapperProject, "bad_project") | ||
t.Setenv(EnvGcpCkmsWrapperLocation, "bad_location") | ||
t.Setenv(EnvGcpCkmsWrapperKeyRing, "bad_key_ring") | ||
t.Setenv(EnvGcpCkmsWrapperCryptoKey, "bad_crypto_key") | ||
t.Setenv(EnvVaultGcpCkmsSealKeyRing, "bad_vault_key_ring") | ||
t.Setenv(EnvVaultGcpCkmsSealCryptoKey, "bad_vault_crypto_key") | ||
|
||
s := NewWrapper() | ||
_, err := s.SetConfig(context.Background(), wrapping.WithConfigMap(configMap), wrapping.WithDisallowEnvVars(true)) | ||
if err != nil { | ||
t.Fatalf("got error from SetConfig %v", err) | ||
} | ||
|
||
// Make sure we can use the key properly. | ||
input := []byte("foo") | ||
swi, err := s.Encrypt(context.Background(), input) | ||
if err != nil { | ||
t.Fatalf("err: %s", err.Error()) | ||
} | ||
|
||
pt, err := s.Decrypt(context.Background(), swi) | ||
if err != nil { | ||
t.Fatalf("err: %s", err.Error()) | ||
} | ||
|
||
if !reflect.DeepEqual(input, pt) { | ||
t.Fatalf("expected %s, got %s", input, pt) | ||
} | ||
} | ||
|
||
func TestGcpCkmsSeal(t *testing.T) { | ||
t.Setenv(EnvGcpCkmsWrapperProject, "") // Make sure at least one required value is not set. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test worked correctly if it ran by itself but running them all together, if another test ran first and set the appropriate vars would fail as we wouldn't get the failure we expected. |
||
|
||
// Do an error check before env vars are set | ||
s := NewWrapper() | ||
_, err := s.SetConfig(context.Background()) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed as it didn't play nice with the new test case disabling env-vars