Skip to content

Commit 1fb9b76

Browse files
Merge pull request #2341 from NCCE/3008-auth-custom-claim-capture-fix
Modifying the custom claim capture
2 parents 4a8c818 + 668c094 commit 1fb9b76

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

app/controllers/auth_controller.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ def callback
33
auth = omniauth_params
44
course_booking_uri = course_redirect_params
55

6-
Sentry.configure_scope do |scope|
7-
scope.set_context("oauth_custom_claim", auth.info)
8-
end
9-
106
user_exists = User.exists?(stem_user_id: auth.info.stem_user_id)
117
user = User.from_auth(auth.uid, auth.credentials, auth.info)
128

@@ -22,7 +18,10 @@ def callback
2218

2319
Achiever::FetchUsersCompletedCoursesFromAchieverJob.perform_later(user)
2420
rescue => e
25-
Sentry.capture_exception(e)
21+
Sentry.with_scope do |scope|
22+
scope.set_context("oauth_custom_claim", auth&.info)
23+
Sentry.capture_exception(e)
24+
end
2625

2726
raise e
2827
end

spec/requests/auth/callback_spec.rb

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,47 @@
11
require "rails_helper"
22

33
RSpec.describe AuthController do
4-
describe "#callback" do
5-
let(:integration_key) { "13251241" }
6-
let(:user) { create(:user, stem_user_id: integration_key) }
7-
let(:auth0_hash) {
8-
OmniAuth::AuthHash.new(
9-
provider: "stem",
10-
uid: "auth0|user@example.com",
11-
credentials: {
12-
expires_at: 1_546_601_180,
13-
token: "14849048797785647933"
14-
},
15-
info: {
16-
achiever_contact_no: "b44cb53f-c690-4535-bd79-89e893337ec6",
17-
first_name: "Jane",
18-
last_name: "Doe",
19-
email: "user@example.com",
20-
stem_user_id: integration_key
4+
let(:integration_key) { "13251241" }
5+
let(:user) { create(:user, stem_user_id: integration_key) }
6+
let(:auth0_hash) {
7+
OmniAuth::AuthHash.new(
8+
provider: "stem",
9+
uid: "auth0|user@example.com",
10+
credentials: {
11+
expires_at: 1_546_601_180,
12+
token: "14849048797785647933"
13+
},
14+
info: {
15+
achiever_contact_no: "b44cb53f-c690-4535-bd79-89e893337ec6",
16+
first_name: "Jane",
17+
last_name: "Doe",
18+
email: "user@example.com",
19+
stem_user_id: integration_key
20+
21+
}
22+
)
23+
}
24+
25+
let(:auth0_invalid_hash) {
26+
OmniAuth::AuthHash.new(
27+
provider: "stem",
28+
uid: "auth0|user@example.com",
29+
credentials: {
30+
expires_at: 1_546_601_180,
31+
token: "14849048797785647933"
32+
},
33+
info: {
34+
achiever_contact_no: nil,
35+
first_name: "Jane",
36+
last_name: "Doe",
37+
email: "user@example.com",
38+
stem_user_id: nil
2139

22-
}
23-
)
24-
}
40+
}
41+
)
42+
}
2543

44+
describe "#callback" do
2645
before do
2746
OmniAuth.config.test_mode = true
2847
OmniAuth.config.mock_auth[:stem] = auth0_hash
@@ -53,6 +72,19 @@
5372
end
5473
end
5574

75+
context "invalid info" do
76+
before do
77+
OmniAuth.config.test_mode = true
78+
OmniAuth.config.mock_auth[:stem] = auth0_invalid_hash
79+
end
80+
81+
it "raises exception when data missing" do
82+
expect {
83+
get callback_path
84+
}.to raise_error(StandardError)
85+
end
86+
end
87+
5688
context "when source_uri is not present" do
5789
before do
5890
OmniAuth.config.test_mode = true

0 commit comments

Comments
 (0)