Skip to content

Commit 5c8df8e

Browse files
author
Chris Gilmer
committed
Validate the output of the config file after it is created
1 parent 470b1c9 commit 5c8df8e

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

cmd/add_profile_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ output=json
3636
config, err := vault.LoadConfig(f)
3737
assert.NoError(t, err)
3838

39+
mfaSerial := "arn:aws:iam::111111111111:mfa/test-user"
3940
addProfileConfig := AddProfileConfig{
4041
// Config
4142
Logger: logger,
@@ -48,11 +49,21 @@ output=json
4849
Output: "json",
4950

5051
// Profiles
51-
AWSProfileAccounts: []string{"test-id:123456789012"},
52+
AWSProfileAccounts: []string{"test-id-new:123456789012"},
5253
AWSProfileName: "test-id",
5354
}
5455
err = addProfileConfig.AddProfile()
5556
assert.NoError(t, err)
5657

57-
// TODO: Check contents of file
58+
// re-load the config file
59+
config, err = vault.LoadConfig(f)
60+
assert.NoError(t, err)
61+
62+
testSection, ok := config.ProfileSection("test-id-new")
63+
assert.True(t, ok)
64+
assert.Equal(t, testSection.SourceProfile, "test-id-base")
65+
assert.Equal(t, testSection.MfaSerial, mfaSerial)
66+
assert.Equal(t, testSection.RoleARN, "arn:aws:iam::123456789012:role/test-role")
67+
assert.Equal(t, testSection.Region, "us-west-2")
68+
// assert.Equal(t, testBaseSection.Output, "json")
5869
}

cmd/setup_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ output=json
4444
keyring, err := getKeyring("test")
4545
assert.NoError(t, err)
4646

47+
mfaSerial := "arn:aws:iam::111111111111:mfa/test-user"
4748
setupConfig := SetupConfig{
4849
// Config
4950
Logger: logger,
@@ -61,11 +62,28 @@ output=json
6162
// Profiles
6263
BaseProfileName: "test-id-base",
6364
AWSProfileAccounts: []string{"test-id:123456789012"},
65+
MFASerial: mfaSerial,
6466
}
6567
err = setupConfig.UpdateAWSConfigFile()
6668
assert.NoError(t, err)
6769

68-
// TODO: Check contents of file
70+
// re-load the config file
71+
config, err = vault.LoadConfig(f)
72+
assert.NoError(t, err)
73+
74+
testBaseSection, ok := config.ProfileSection("test-id-base")
75+
assert.True(t, ok)
76+
assert.Equal(t, len(testBaseSection.MfaSerial), 0)
77+
assert.Equal(t, testBaseSection.Region, "us-west-2")
78+
// assert.Equal(t, testBaseSection.Output, "json")
79+
80+
testSection, ok := config.ProfileSection("test-id")
81+
assert.True(t, ok)
82+
assert.Equal(t, testSection.SourceProfile, "test-id-base")
83+
assert.Equal(t, testSection.MfaSerial, mfaSerial)
84+
assert.Equal(t, testSection.RoleARN, "arn:aws:iam::123456789012:role/test-role")
85+
assert.Equal(t, testSection.Region, "us-west-2")
86+
// assert.Equal(t, testBaseSection.Output, "json")
6987
}
7088

7189
func TestGenerateQrCode(t *testing.T) {

0 commit comments

Comments
 (0)