|
14 | 14 | package regcreds
|
15 | 15 |
|
16 | 16 | import (
|
| 17 | + "encoding/json" |
| 18 | + "fmt" |
17 | 19 | "testing"
|
18 | 20 |
|
19 | 21 | "github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/secretsmanager/mock"
|
@@ -245,6 +247,36 @@ func TestValidateCredsInput_ErrorOnDuplicateContainers(t *testing.T) {
|
245 | 247 | assert.Error(t, err, "Expected creds with duplicate containers to return error")
|
246 | 248 | }
|
247 | 249 |
|
| 250 | +func TestGenerateSecretString(t *testing.T) { |
| 251 | + type ECSRegistrySecret struct { |
| 252 | + Username string `json:"username"` |
| 253 | + Password string `json:"password"` |
| 254 | + } |
| 255 | + |
| 256 | + testCases := []struct { |
| 257 | + inputUsername string |
| 258 | + inputPassword string |
| 259 | + expectedSecret ECSRegistrySecret |
| 260 | + }{ |
| 261 | + {"user1", "l33tp4$$w0rd", ECSRegistrySecret{"user1", "l33tp4$$w0rd"}}, |
| 262 | + {"someUserNameThatIsVeryLong0987654321", "*3G7nMl6W*Pi#*erjm", ECSRegistrySecret{"someUserNameThatIsVeryLong0987654321", "*3G7nMl6W*Pi#*erjm"}}, |
| 263 | + { "[email protected]", "some-dashed-psswrd-64", ECSRegistrySecret{ "[email protected]", "some-dashed-psswrd-64"}}, |
| 264 | + } |
| 265 | + for _, test := range testCases { |
| 266 | + t.Run(fmt.Sprintf("Parse registry secret %s", test.inputUsername), func(t *testing.T) { |
| 267 | + |
| 268 | + actualSecretString := generateSecretString(test.inputUsername, test.inputPassword) |
| 269 | + assert.NotEmpty(t, *actualSecretString) |
| 270 | + |
| 271 | + regSecret := &ECSRegistrySecret{} |
| 272 | + err := json.Unmarshal([]byte(*actualSecretString), regSecret) |
| 273 | + assert.NoError(t, err, "Unexpected error when unmarshalling registry secret") |
| 274 | + assert.Equal(t, test.expectedSecret.Username, regSecret.Username, "Expected username to match") |
| 275 | + assert.Equal(t, test.expectedSecret.Password, regSecret.Password, "Expected password to match") |
| 276 | + }) |
| 277 | + } |
| 278 | +} |
| 279 | + |
248 | 280 | func getTestCredsEntry(secretARN, username, password, kmsKey string, containers []string) readers.RegistryCredEntry {
|
249 | 281 | return readers.RegistryCredEntry{
|
250 | 282 | SecretManagerARN: secretARN,
|
|
0 commit comments