diff --git a/Makefile b/Makefile index 108568f..1920d84 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,8 @@ LDFLAGS := -ldflags="-s -w -X \"github.com/$(OWNER)/$(NAME)/cmd.Version=$(VERSIO .PHONY: test test_ci tidy install buildprep build buildmac buildwin test: test_prereq - go test ./... -v -mod=readonly -coverprofile=.coverage/out | go-junit-report > .coverage/report-junit.xml && \ + go test ./... -v -mod=readonly -coverprofile=.coverage/out && \ + cat .coverage/out | go-junit-report > .coverage/report-junit.xml && \ gocov convert .coverage/out | gocov-xml > .coverage/report-cobertura.xml test_ci: diff --git a/cmd/saml.go b/cmd/saml.go index e3b5d5a..84885c0 100755 --- a/cmd/saml.go +++ b/cmd/saml.go @@ -89,7 +89,7 @@ func getSaml(cmd *cobra.Command, args []string) error { }, } - saveRole := "" + saveRole := role if isSso { sr := strings.Split(ssoRole, ":") if len(sr) != 2 { diff --git a/internal/credentialexchange/helper.go b/internal/credentialexchange/helper.go index e46ae24..542adf0 100644 --- a/internal/credentialexchange/helper.go +++ b/internal/credentialexchange/helper.go @@ -43,12 +43,14 @@ func SessionName(username, selfName string) string { func InsertRoleIntoChain(role string, roleChain []string) []string { // IF role is provided it can be assumed from the WEB_ID credentials // this is to maintain the old implementation - if role != "" { - // could use this experimental slice Insert - // https://pkg.go.dev/golang.org/x/exp/slices#Insert - roleChain = append(roleChain[:0], append([]string{role}, roleChain[0:]...)...) + rc := []string{} + for _, r := range roleChain { + if r != role { + rc = append(rc, r) + } } - return roleChain + + return rc } func SetCredentials(creds *AWSCredentials, config CredentialConfig) error { diff --git a/internal/credentialexchange/helper_test.go b/internal/credentialexchange/helper_test.go index c1967b8..0e3c055 100644 --- a/internal/credentialexchange/helper_test.go +++ b/internal/credentialexchange/helper_test.go @@ -109,13 +109,13 @@ func Test_InsertIntoRoleSlice_with(t *testing.T) { expect []string }{ "chain empty and role specified": { - "role", []string{}, []string{"role"}, + "role", []string{}, []string{}, }, "chain set and role empty": { "", []string{"rolec1"}, []string{"rolec1"}, }, "both set and role is always first in list": { - "role", []string{"rolec1"}, []string{"role", "rolec1"}, + "role", []string{"rolec1"}, []string{"rolec1"}, }, } for name, tt := range ttests {