From ad91842d062e993647b5750aa90c509f562ee442 Mon Sep 17 00:00:00 2001 From: Mariano Cano Date: Tue, 30 Jul 2019 15:28:04 -0700 Subject: [PATCH] Add test for SanitizeSSHUserPrincipal --- authority/provisioner/provisioner_test.go | 30 ++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/authority/provisioner/provisioner_test.go b/authority/provisioner/provisioner_test.go index 11615e1a..d79c2b69 100644 --- a/authority/provisioner/provisioner_test.go +++ b/authority/provisioner/provisioner_test.go @@ -1,6 +1,8 @@ package provisioner -import "testing" +import ( + "testing" +) func TestType_String(t *testing.T) { tests := []struct { @@ -24,3 +26,29 @@ func TestType_String(t *testing.T) { }) } } + +func TestSanitizeSSHUserPrincipal(t *testing.T) { + type args struct { + email string + } + tests := []struct { + name string + args args + want string + }{ + {"simple", args{"foobar"}, "foobar"}, + {"camelcase", args{"FooBar"}, "foobar"}, + {"email", args{"foo@example.com"}, "foo"}, + {"email with dots", args{"foo.bar.zar@example.com"}, "foobarzar"}, + {"email with dashes", args{"foo-bar-zar@example.com"}, "foo-bar-zar"}, + {"email with underscores", args{"foo_bar_zar@example.com"}, "foo_bar_zar"}, + {"email with symbols", args{"Foo.Bar0123456789!#$%&'*+-/=?^_`{|}~;@example.com"}, "foobar0123456789________-___________"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := SanitizeSSHUserPrincipal(tt.args.email); got != tt.want { + t.Errorf("SanitizeSSHUserPrincipal() = %v, want %v", got, tt.want) + } + }) + } +}