-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow requesting a join token with IAM method from the web api (#11339)
Co-authored-by: Jim Bishopp <[email protected]> Co-authored-by: Nic Klaassen <[email protected]>
- Loading branch information
1 parent
2eca7c7
commit 57cc2ed
Showing
6 changed files
with
510 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2008,9 +2008,11 @@ func (s *WebSuite) TestGetClusterDetails(c *C) { | |
|
||
func TestTokenGeneration(t *testing.T) { | ||
tt := []struct { | ||
name string | ||
roles types.SystemRoles | ||
shouldErr bool | ||
name string | ||
roles types.SystemRoles | ||
shouldErr bool | ||
joinMethod types.JoinMethod | ||
allow []*types.TokenRule | ||
}{ | ||
{ | ||
name: "single node role", | ||
|
@@ -2037,6 +2039,19 @@ func TestTokenGeneration(t *testing.T) { | |
roles: types.SystemRoles{}, | ||
shouldErr: true, | ||
}, | ||
{ | ||
name: "cannot request token with IAM join method without allow field", | ||
roles: types.SystemRoles{types.RoleNode}, | ||
joinMethod: types.JoinMethodIAM, | ||
shouldErr: true, | ||
}, | ||
{ | ||
name: "can request token with IAM join method", | ||
roles: types.SystemRoles{types.RoleNode}, | ||
joinMethod: types.JoinMethodIAM, | ||
allow: []*types.TokenRule{{AWSAccount: "1234"}}, | ||
shouldErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
|
@@ -2047,8 +2062,10 @@ func TestTokenGeneration(t *testing.T) { | |
pack := proxy.authPack(t, "[email protected]") | ||
|
||
endpoint := pack.clt.Endpoint("webapi", "token") | ||
re, err := pack.clt.PostJSON(context.Background(), endpoint, createTokenRequest{ | ||
Roles: tc.roles, | ||
re, err := pack.clt.PostJSON(context.Background(), endpoint, types.ProvisionTokenSpecV2{ | ||
Roles: tc.roles, | ||
JoinMethod: tc.joinMethod, | ||
Allow: tc.allow, | ||
}) | ||
|
||
if tc.shouldErr { | ||
|
@@ -2066,6 +2083,13 @@ func TestTokenGeneration(t *testing.T) { | |
generatedToken, err := proxy.auth.Auth().GetToken(context.Background(), responseToken.ID) | ||
require.NoError(t, err) | ||
require.Equal(t, tc.roles, generatedToken.GetRoles()) | ||
|
||
expectedJoinMethod := tc.joinMethod | ||
if tc.joinMethod == "" { | ||
expectedJoinMethod = types.JoinMethodToken | ||
} | ||
// if no joinMethod is provided, expect token method | ||
require.Equal(t, expectedJoinMethod, generatedToken.GetJoinMethod()) | ||
}) | ||
} | ||
} | ||
|
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
Oops, something went wrong.