Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.

Commit

Permalink
return empty string if resolver passed empty role (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph-Irving authored Aug 16, 2019
1 parent e98ada5 commit 23626e5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/aws/sts/arn_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func DefaultResolver(prefix string) *Resolver {

// Resolve converts from a role string into the absolute role arn.
func (r *Resolver) Resolve(role string) string {
if role == "" {
return ""
}

if strings.HasPrefix(role, "/") {
role = strings.TrimPrefix(role, "/")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/aws/sts/arn_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ func TestAddsPrefix(t *testing.T) {
}
}

func TestReturnsEmpty(t *testing.T) {
resolver := DefaultResolver("arn:aws:iam::account-id:role/")
role := resolver.Resolve("")

if role != "" {
t.Error("unexpected role, was:", role)
}
}

func TestAddsPrefixWithRoleBeginningWithSlash(t *testing.T) {
resolver := DefaultResolver("arn:aws:iam::account-id:role/")
role := resolver.Resolve("/myrole")
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
pb "github.com/uswitch/kiam/proto"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"k8s.io/api/core/v1"
"k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
Expand Down

0 comments on commit 23626e5

Please sign in to comment.