-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: generate role session name should only contain valid chars
- Loading branch information
1 parent
65b003e
commit 4caa1ae
Showing
2 changed files
with
40 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,30 @@ func TestSetDefaultsInvalidDuration(t *testing.T) { | |
t.Errorf("expected the default of 3600 as duration seconds") | ||
} | ||
} | ||
|
||
func TestGenerateRoleSessionName(t *testing.T) { | ||
type args struct { | ||
roleName string | ||
pipelineId string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{"no pipeline", args{"role", ""}, "role"}, | ||
{"role and pipeline", args{"role", "1234"}, "role-1234"}, | ||
{"no leading or trailing dash", args{"-role-", ""}, "role"}, | ||
{"invalid chars", args{"/gitlab/role", "1234"}, "gitlab-role-1234"}, | ||
{"multiple invalid chars", args{"/gitlab/role-%^$abc", "1234"}, "gitlab-role-abc-1234"}, | ||
{"all valid special chars", args{"[email protected]_", "1234"}, "[email protected]_-1234"}, | ||
{"keep dashes", args{"gitlab-role--nice", ""}, "gitlab-role-nice"}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := GenerateRoleSessionName(tt.args.roleName, tt.args.pipelineId); got != tt.want { | ||
t.Errorf("GenerateRoleSessionName() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |