Extract email for active directory users that don't have access to exchange (#3053)

This commit is contained in:
JBodkin-Amphora 2022-03-04 18:18:39 +00:00 committed by GitHub
parent bec4a29f19
commit 8567b56b8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View file

@ -31,15 +31,17 @@ func (obj apiUser) getEmail() string {
// AD often doesn't have the email address returned, but we can parse it from the UPN // AD often doesn't have the email address returned, but we can parse it from the UPN
// UPN looks like: // UPN looks like either:
// cdoxsey_pomerium.com#EXT#@cdoxseypomerium.onmicrosoft.com // cdoxsey_pomerium.com#EXT#@cdoxseypomerium.onmicrosoft.com
// cdoxsey@pomerium.com
email := obj.UserPrincipalName email := obj.UserPrincipalName
if idx := strings.Index(email, "#EXT"); idx > 0 { if idx := strings.Index(email, "#EXT"); idx > 0 {
email = email[:idx] email = email[:idx]
}
// find the last _ and replace it with @ // find the last _ and replace it with @
if idx := strings.LastIndex(email, "_"); idx > 0 { if idx := strings.LastIndex(email, "_"); idx > 0 {
email = email[:idx] + "@" + email[idx+1:] email = email[:idx] + "@" + email[idx+1:]
}
} }
return email return email
} }

View file

@ -62,6 +62,7 @@ func newMockAPI(t *testing.T, srv *httptest.Server) http.Handler {
"members@delta": []M{ "members@delta": []M{
{"@odata.type": "#microsoft.graph.user", "id": "user-2"}, {"@odata.type": "#microsoft.graph.user", "id": "user-2"},
{"@odata.type": "#microsoft.graph.user", "id": "user-3"}, {"@odata.type": "#microsoft.graph.user", "id": "user-3"},
{"@odata.type": "#microsoft.graph.user", "id": "user-4"},
}, },
}, },
}, },
@ -73,6 +74,7 @@ func newMockAPI(t *testing.T, srv *httptest.Server) http.Handler {
{"id": "user-1", "displayName": "User 1", "mail": "user1@example.com"}, {"id": "user-1", "displayName": "User 1", "mail": "user1@example.com"},
{"id": "user-2", "displayName": "User 2", "mail": "user2@example.com"}, {"id": "user-2", "displayName": "User 2", "mail": "user2@example.com"},
{"id": "user-3", "displayName": "User 3", "userPrincipalName": "user3_example.com#EXT#@user3example.onmicrosoft.com"}, {"id": "user-3", "displayName": "User 3", "userPrincipalName": "user3_example.com#EXT#@user3example.onmicrosoft.com"},
{"id": "user-4", "displayName": "User 4", "userPrincipalName": "user4@example.com"},
}, },
}) })
}) })
@ -186,6 +188,12 @@ func TestProvider_UserGroups(t *testing.T) {
DisplayName: "User 3", DisplayName: "User 3",
Email: "user3@example.com", Email: "user3@example.com",
}, },
{
Id: "user-4",
GroupIds: []string{"test"},
DisplayName: "User 4",
Email: "user4@example.com",
},
}, users) }, users)
testutil.AssertProtoJSONEqual(t, `[ testutil.AssertProtoJSONEqual(t, `[
{ "id": "admin", "name": "Admin Group" }, { "id": "admin", "name": "Admin Group" },