Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(RoleSelection) Now returns the role if list contains a single entry #49

Merged
merged 1 commit into from
Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/saml2aws/commands/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func Login(loginFlags *LoginFlags) error {
return errors.Wrap(err, "Failed to assume role, please check you are permitted to assume the given role for the AWS service")
}

// fmt.Println("Selected role:", role.RoleARN)
fmt.Println("Selected role:", role.RoleARN)

sess, err := session.NewSession()
if err != nil {
Expand Down Expand Up @@ -200,7 +200,7 @@ func resolveRole(awsRoles []*saml2aws.AWSRole, samlAssertion string, loginFlags
if loginFlags.RoleSupplied() {
return saml2aws.LocateRole(awsRoles, loginFlags.RoleArn)
}
role = awsRoles[0]
return awsRoles[0], nil
} else if len(awsRoles) == 0 {
return nil, errors.New("no roles available")
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/saml2aws/commands/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,20 @@ func TestResolveLoginDetails(t *testing.T) {
assert.Empty(t, err)
assert.Equal(t, loginDetails, &saml2aws.LoginDetails{Username: "wolfeidau", Password: "testtestlol", Hostname: "id.example.com"})
}

func TestResolveRoleSingleEntry(t *testing.T) {

adminRole := &saml2aws.AWSRole{
Name: "admin",
RoleARN: "arn:aws:iam::456456456456:saml-provider/example-idp,arn:aws:iam::456456456456:role/admin",
PrincipalARN: "arn:aws:iam::456456456456:role/admin,arn:aws:iam::456456456456:saml-provider/example-idp",
}

awsRoles := []*saml2aws.AWSRole{
adminRole,
}

got, err := resolveRole(awsRoles, "", &LoginFlags{})
assert.Empty(t, err)
assert.Equal(t, got, adminRole)
}