-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(terraform): Add hyphen and non-ASCII support for domain names in…
… credential extraction (#6108) Co-authored-by: simar7 <[email protected]>
- Loading branch information
1 parent
9c5e5a0
commit 4a9ac6d
Showing
3 changed files
with
102 additions
and
4 deletions.
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
56 changes: 56 additions & 0 deletions
56
pkg/iac/scanners/terraform/parser/resolvers/registry_test.go
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package resolvers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_getPrivateRegistryTokenFromEnvVars_ErrorsWithNoEnvVarSet(t *testing.T) { | ||
token, err := getPrivateRegistryTokenFromEnvVars("registry.example.com") | ||
assert.Equal(t, "", token) | ||
assert.Equal(t, "no token was found for the registry at registry.example.com", err.Error()) | ||
} | ||
|
||
func Test_getPrivateRegistryTokenFromEnvVars_ConvertsSiteNameToEnvVar(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
siteName string | ||
tokenName string | ||
}{ | ||
{ | ||
name: "returns string when simple env var set", | ||
siteName: "registry.example.com", | ||
tokenName: "TF_TOKEN_registry_example_com", | ||
}, | ||
{ | ||
name: "allows dashes in hostname to be dashes", | ||
siteName: "my-registry.example.com", | ||
tokenName: "TF_TOKEN_my-registry_example_com", | ||
}, | ||
{ | ||
name: "allows dashes in hostname to be double underscores", | ||
siteName: "my-registry.example.com", | ||
tokenName: "TF_TOKEN_my__registry_example_com", | ||
}, | ||
{ | ||
name: "handles utf8 to punycode correctly", | ||
siteName: "例えば.com", | ||
tokenName: "TF_TOKEN_xn--r8j3dr99h_com", | ||
}, | ||
{ | ||
name: "handles punycode with dash to underscore conversion", | ||
siteName: "café.fr", | ||
tokenName: "TF_TOKEN_xn____caf__dma_fr", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Setenv(tt.tokenName, "abcd") | ||
token, err := getPrivateRegistryTokenFromEnvVars(tt.siteName) | ||
assert.Equal(t, "abcd", token) | ||
assert.Equal(t, nil, err) | ||
}) | ||
} | ||
} |