Skip to content

Commit

Permalink
Add user name to UserInfoResponse header (flyteorg#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrogan authored Jan 10, 2023
1 parent cb1224b commit d6bc85d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions auth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ func GetUserInfoForwardResponseHandler() UserInfoForwardResponseHandler {
info, ok := m.(*service.UserInfoResponse)
if ok {
w.Header().Set("X-User-Subject", info.Subject)
w.Header().Set("X-User-Name", info.Name)
}
return nil
}
Expand Down
5 changes: 5 additions & 0 deletions auth/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,18 @@ func TestUserInfoForwardResponseHander(t *testing.T) {
w := httptest.NewRecorder()
resp := service.UserInfoResponse{
Subject: "user-id",
Name: "User Name",
}
assert.NoError(t, handler(ctx, w, &resp))
assert.Contains(t, w.Result().Header, "X-User-Subject")
assert.Equal(t, w.Result().Header["X-User-Subject"], []string{"user-id"})

assert.Contains(t, w.Result().Header, "X-User-Name")
assert.Equal(t, w.Result().Header["X-User-Name"], []string{"User Name"})

w = httptest.NewRecorder()
unrelatedResp := service.OAuth2MetadataResponse{}
assert.NoError(t, handler(ctx, w, &unrelatedResp))
assert.NotContains(t, w.Result().Header, "X-User-Subject")
assert.NotContains(t, w.Result().Header, "X-User-Name")
}

0 comments on commit d6bc85d

Please sign in to comment.