-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: still uncomment some not ported negative assertions
- Loading branch information
Showing
6 changed files
with
188 additions
and
17 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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package store_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dnitsch/configmanager/internal/store" | ||
) | ||
|
||
func Test_StoreDefault(t *testing.T) { | ||
|
||
t.Run("Default Shoudl not errror", func(t *testing.T) { | ||
rs := store.NewDefatultStrategy() | ||
if rs == nil { | ||
t.Fatal("unable to init default strategy") | ||
} | ||
}) | ||
t.Run("Token method should error", func(t *testing.T) { | ||
rs := store.NewDefatultStrategy() | ||
if _, err := rs.Token(); err == nil { | ||
t.Fatal("Token should return not implemented error") | ||
} | ||
}) | ||
|
||
} |
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 |
---|---|---|
|
@@ -25,6 +25,19 @@ func (m mockGenerate) Token() (s string, e error) { | |
return m.value, m.err | ||
} | ||
|
||
var TEST_GCP_CREDS = []byte(`{ | ||
"type": "service_account", | ||
"project_id": "xxxxx", | ||
"private_key_id": "yyyyyyyyyyyy", | ||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDf842hcn5Nvp6e\n7yKARaCVIDfLXpKDhRwUOvHMzJ1ioRgQo/kbv1n4yHGCSUFyY6hKGj0HBjaGj5kE\n79H/6Y3dJNGhnsMnxBhHdo+3FI8QF0CHZh460NMZSAJ41UMQSBGssGVsNfyUzXGH\nLc45sIx/Twx3yr1k2GD3E8FlDcKlZqa3xGHf+aipg2X3NxbYi+Sz7Yed+SOMhNHl\ncX6E/TqG9n1aTyIwjMIHscCYarJqURkJxr24ukDroCeMxAfxYTdMvRU2e8pFEdoY\nrgUC88fYfaVI5txJ6j/ZKauKQX9Pa8tSyXJeGva3JYp4VC7V4IyoVviCUgEGWZDN\n6/i3zoF/AgMBAAECggEAcVBCcVYFIkE48SH+Svjv74SFtpj7eSB4vKO2hPFjEOyB\nyKmu+aMwWvjQtiNqwf46wIPWLR+vpxYxTpYpo1sBNMvUZfp2tEA8KKyMuw3j9ThO\npjO9R/UxWrFcztbZP/u3NbFrH/2Q95mbv9IlbnsuG5xbqqEig0wYg+uzBvaXbig3\n/Jr0vLT2BkRCBKQkYGjVZcHlHVLoF7/J8cghFgkV1PGvknOv6/q7qzn9L4TjQIet\nfhrhN8Z1vgFiSYtpjP6YQEUEPSHmCQeD3WzJcnASPpU2uCUwd/z65ltKPnn+rqMt\n6jt9R1S1Ju2ZSjv+kR5fIXzihdOzncyzDDm33c/QwQKBgQD2QDZuzLjTxnhsfGii\nKJDAts+Jqfs/6SeEJcJKtEngj4m7rgzyEjbKVp8qtRHIzglKRWAe62/qzzy2BkKi\nvAd4+ZzmG2SkgypGsKVfjGXVFixz2gtUdmBOmK/TnYsxNT9yTt+rX9IGqKK60q73\nOWl8VsliLIsfvSH7+bqi7sRcXQKBgQDo0VUebyQHoTAXPdzGy2ysrVPDiHcldH0Y\n/hvhQTZwxYaJr3HpOCGol2Xl6zyawuudEQsoQwJ3Li6yeb0YMGiWX77/t+qX3pSn\nkGuoftGaNDV7sLn9UV2y+InF8EL1CasrhG1k5RIuxyfV0w+QUo+E7LpVR5XkbJqT\n9QNKnDQXiwKBgQDvvEYCCqbp7e/xVhEbxbhfFdro4Cat6tRAz+3egrTlvXhO0jzi\nMp9Kz5f3oP5ma0gaGX5hu75icE1fvKqE+d+ghAqe7w5FJzkyRulJI0tEb2jphN7A\n5NoPypBqyZboWjmhlG4mzouPVf/POCuEnk028truDAWJ6by7Lj3oP+HFNQKBgQCc\n5BQ8QiFBkvnZb7LLtGIzq0n7RockEnAK25LmJRAOxs13E2fsBguIlR3x5qgckqY8\nXjPqmd2bet+1HhyzpEuWqkcIBGRum2wJz2T9UxjklbJE/D8Z2i8OYDZX0SUOA8n5\ntXASwduS8lqB2Y1vcHOO3AhlV6xHFnjEpCPnr4PbKQKBgAhQ9D9MPeuz+5yw3yHg\nkvULZRtud+uuaKrOayprN25RTxr9c0erxqnvM7KHeo6/urOXeEa7x2n21kAT0Nch\nkF2RtWBLZKXGZEVBtw1Fw0UKNh4IDgM26dwlzRfTVHCiw6M6dCiTNk9KkP2vlkim\n3QFDSSUp+eBTXA17WkDAQf7w\n-----END PRIVATE KEY-----\n", | ||
Check failure Code scanning / SonarCloud Google Cloud service accounts keys should not be disclosed High
Make sure this service account key gets revoked, changed, and removed from the code. See more on SonarCloud
|
||
"client_email": "foo@project.iam.gserviceaccount.com", | ||
"client_id": "99999911111111", | ||
"auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
"token_uri": "https://oauth2.googleapis.com/token", | ||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/bla" | ||
}`) | ||
|
||
func Test_Strategy_Retrieve_succeeds(t *testing.T) { | ||
|
||
ttests := map[string]struct { | ||
|
@@ -70,7 +83,6 @@ func Test_Strategy_Retrieve_succeeds(t *testing.T) { | |
} | ||
|
||
func Test_CustomStrategyFuncMap_add_own(t *testing.T) { | ||
// t.Skip() | ||
ttests := map[string]struct { | ||
}{ | ||
"default": {}, | ||
|
@@ -129,13 +141,110 @@ func Test_SelectImpl_With(t *testing.T) { | |
"AZTABLESTORE#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
conf, _ := config.NewParsedTokenConfig("AZTABLESTORE#foo/bar1", *config.NewConfig().WithTokenSeparator("#")) | ||
s, _ := store.NewAzTableStore(context.TODO(), conf) | ||
token, _ := config.NewParsedTokenConfig("AZTABLESTORE#foo/bar1", *config.NewConfig().WithTokenSeparator("#")) | ||
s, _ := store.NewAzTableStore(context.TODO(), token) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success AWSPARAMSTR": { | ||
func() func() { | ||
os.Setenv("AWS_ACCESS_KEY", "AAAAAAAAAAAAAAA") | ||
os.Setenv("AWS_SECRET_ACCESS_KEY", "00000000000000000000111111111") | ||
return func() { | ||
os.Clearenv() | ||
} | ||
}, | ||
"AWSPARAMSTR#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
s, _ := store.NewParamStore(context.TODO()) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success AWSSECRETS": { | ||
func() func() { | ||
os.Setenv("AWS_ACCESS_KEY", "AAAAAAAAAAAAAAA") | ||
os.Setenv("AWS_SECRET_ACCESS_KEY", "00000000000000000000111111111") | ||
return func() { | ||
os.Clearenv() | ||
} | ||
}, | ||
"AWSSECRETS#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
s, _ := store.NewSecretsMgr(context.TODO()) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success AZKVSECRET": { | ||
func() func() { | ||
os.Setenv("AWS_ACCESS_KEY", "AAAAAAAAAAAAAAA") | ||
os.Setenv("AWS_SECRET_ACCESS_KEY", "00000000000000000000111111111") | ||
return func() { | ||
os.Clearenv() | ||
} | ||
}, | ||
"AZKVSECRET#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
token, _ := config.NewParsedTokenConfig("AZKVSECRET#foo/bar1", *config.NewConfig().WithTokenSeparator("#")) | ||
s, _ := store.NewKvScrtStore(context.TODO(), token) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success AZAPPCONF": { | ||
func() func() { | ||
return func() { | ||
os.Clearenv() | ||
} | ||
}, | ||
"AZAPPCONF#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
token, _ := config.NewParsedTokenConfig("AZAPPCONF#foo/bar1", *config.NewConfig().WithTokenSeparator("#")) | ||
s, _ := store.NewAzAppConf(context.TODO(), token) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success VAULT": { | ||
func() func() { | ||
os.Setenv("VAULT_", "AAAAAAAAAAAAAAA") | ||
return func() { | ||
os.Clearenv() | ||
} | ||
}, | ||
"VAULT#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
token, _ := config.NewParsedTokenConfig("VAULT#foo/bar1", *config.NewConfig().WithTokenSeparator("#")) | ||
s, _ := store.NewVaultStore(context.TODO(), token) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
"success GCPSECRETS": { | ||
func() func() { | ||
cf, _ := os.CreateTemp(".", "*") | ||
cf.Write(TEST_GCP_CREDS) | ||
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", cf.Name()) | ||
return func() { | ||
os.Remove(cf.Name()) | ||
os.Clearenv() | ||
} | ||
}, | ||
"GCPSECRETS#foo/bar1", | ||
config.NewConfig().WithTokenSeparator("#"), | ||
func() store.Strategy { | ||
s, _ := store.NewGcpSecrets(context.TODO()) | ||
return s | ||
}, | ||
nil, | ||
}, | ||
|
||
// "default Error": { | ||
// func() func() { | ||
// os.Setenv("AWS_ACCESS_KEY", "AAAAAAAAAAAAAAA") | ||
|