Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/web/ui/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ type userTraits struct {
AWSRoleARNs []string `json:"awsRoleArns,omitempty"`
}

// unknownSSOAUthType is used when we know the user is from SSO, but we don't
// know the SSO connector name or type.
const unknownSSOAuthType = "unknown SSO"

// User contains data needed by the web UI to display locally saved users.
type User struct {
UserListEntry
Expand All @@ -76,7 +80,11 @@ func NewUserListEntry(teleUser types.User) (*UserListEntry, error) {

authType := "local"
if teleUser.GetUserType() == types.UserTypeSSO {
authType = teleUser.GetCreatedBy().Connector.Type
// Gracefully handle a malformed SSO user that doesn't have a "CreatedBy"
authType = unknownSSOAuthType
if connector := teleUser.GetCreatedBy().Connector; connector != nil {
authType = connector.Type
}
}

return &UserListEntry{
Expand Down
24 changes: 24 additions & 0 deletions lib/web/ui/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,30 @@ func TestNewUserListEntry(t *testing.T) {
},
},
},
{
name: "malformed sso",
user: &types.UserV2{
Metadata: types.Metadata{
Name: "malformed-sso",
},
Spec: types.UserSpecV2{
Roles: []string{"behavioral-analyst"},
// CreatedBy is not set BUT there's a GitHub identity, so the user's type will be SSO
GithubIdentities: []types.ExternalIdentity{
{
ConnectorID: "github",
Username: "malformed-sso",
},
},
},
},
want: &UserListEntry{
Name: "malformed-sso",
Roles: []string{"behavioral-analyst"},
// We should not panic and display that we don't know who created the user
AuthType: unknownSSOAuthType,
},
},
}

for _, tt := range tests {
Expand Down
Loading