provisioner_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package provisioner
  2. import (
  3. "testing"
  4. )
  5. func TestType_String(t *testing.T) {
  6. tests := []struct {
  7. name string
  8. t Type
  9. want string
  10. }{
  11. {"JWK", TypeJWK, "JWK"},
  12. {"OIDC", TypeOIDC, "OIDC"},
  13. {"AWS", TypeAWS, "AWS"},
  14. {"Azure", TypeAzure, "Azure"},
  15. {"GCP", TypeGCP, "GCP"},
  16. {"noop", noopType, ""},
  17. {"notFound", 1000, ""},
  18. }
  19. for _, tt := range tests {
  20. t.Run(tt.name, func(t *testing.T) {
  21. if got := tt.t.String(); got != tt.want {
  22. t.Errorf("Type.String() = %v, want %v", got, tt.want)
  23. }
  24. })
  25. }
  26. }
  27. func TestSanitizeSSHUserPrincipal(t *testing.T) {
  28. type args struct {
  29. email string
  30. }
  31. tests := []struct {
  32. name string
  33. args args
  34. want string
  35. }{
  36. {"simple", args{"foobar"}, "foobar"},
  37. {"camelcase", args{"FooBar"}, "foobar"},
  38. {"email", args{"foo@example.com"}, "foo"},
  39. {"email with dots", args{"foo.bar.zar@example.com"}, "foobarzar"},
  40. {"email with dashes", args{"foo-bar-zar@example.com"}, "foo-bar-zar"},
  41. {"email with underscores", args{"foo_bar_zar@example.com"}, "foo_bar_zar"},
  42. {"email with symbols", args{"Foo.Bar0123456789!#$%&'*+-/=?^_`{|}~;@example.com"}, "foobar0123456789________-___________"},
  43. }
  44. for _, tt := range tests {
  45. t.Run(tt.name, func(t *testing.T) {
  46. if got := SanitizeSSHUserPrincipal(tt.args.email); got != tt.want {
  47. t.Errorf("SanitizeSSHUserPrincipal() = %v, want %v", got, tt.want)
  48. }
  49. })
  50. }
  51. }