File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,10 @@ type userTraits struct {
62
62
AWSRoleARNs []string `json:"awsRoleArns,omitempty"`
63
63
}
64
64
65
+ // unknownSSOAUthType is used when we know the user is from SSO, but we don't
66
+ // know the SSO connector name or type.
67
+ const unknownSSOAuthType = "unknown SSO"
68
+
65
69
// User contains data needed by the web UI to display locally saved users.
66
70
type User struct {
67
71
UserListEntry
@@ -76,7 +80,11 @@ func NewUserListEntry(teleUser types.User) (*UserListEntry, error) {
76
80
77
81
authType := "local"
78
82
if teleUser .GetUserType () == types .UserTypeSSO {
79
- authType = teleUser .GetCreatedBy ().Connector .Type
83
+ // Gracefully handle a malformed SSO user that doesn't have a "CreatedBy"
84
+ authType = unknownSSOAuthType
85
+ if connector := teleUser .GetCreatedBy ().Connector ; connector != nil {
86
+ authType = connector .Type
87
+ }
80
88
}
81
89
82
90
return & UserListEntry {
Original file line number Diff line number Diff line change @@ -59,6 +59,31 @@ func TestNewUserListEntry(t *testing.T) {
59
59
},
60
60
},
61
61
},
62
+ {
63
+ name : "malformed sso" ,
64
+ user : & types.UserV2 {
65
+ Metadata : types.Metadata {
66
+ Name : "malformed-sso" ,
67
+ },
68
+ Spec : types.UserSpecV2 {
69
+ Roles : []string {"behavioral-analyst" },
70
+ // CreatedBy is not set BUT there's a GitHub identity, so the user's type will be SSO
71
+ GithubIdentities : []types.ExternalIdentity {
72
+ {
73
+ ConnectorID : "github" ,
74
+ Username : "malformed-sso" ,
75
+ UserID : "malformed-sso" ,
76
+ },
77
+ },
78
+ },
79
+ },
80
+ want : & UserListEntry {
81
+ Name : "malformed-sso" ,
82
+ Roles : []string {"behavioral-analyst" },
83
+ // We should not panic and display that we don't know who created the user
84
+ AuthType : unknownSSOAuthType ,
85
+ },
86
+ },
62
87
}
63
88
64
89
for _ , tt := range tests {
You can’t perform that action at this time.
0 commit comments