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
9 changes: 4 additions & 5 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ def callback
auth = omniauth_params
course_booking_uri = course_redirect_params

Sentry.configure_scope do |scope|
scope.set_context("oauth_custom_claim", auth.info)
end

user_exists = User.exists?(stem_user_id: auth.info.stem_user_id)
user = User.from_auth(auth.uid, auth.credentials, auth.info)

Expand All @@ -22,7 +18,10 @@ def callback

Achiever::FetchUsersCompletedCoursesFromAchieverJob.perform_later(user)
rescue => e
Sentry.capture_exception(e)
Sentry.with_scope do |scope|
scope.set_context("oauth_custom_claim", auth&.info)
Sentry.capture_exception(e)
end

raise e
end
Expand Down
72 changes: 52 additions & 20 deletions spec/requests/auth/callback_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
require "rails_helper"

RSpec.describe AuthController do
describe "#callback" do
let(:integration_key) { "13251241" }
let(:user) { create(:user, stem_user_id: integration_key) }
let(:auth0_hash) {
OmniAuth::AuthHash.new(
provider: "stem",
uid: "auth0|user@example.com",
credentials: {
expires_at: 1_546_601_180,
token: "14849048797785647933"
},
info: {
achiever_contact_no: "b44cb53f-c690-4535-bd79-89e893337ec6",
first_name: "Jane",
last_name: "Doe",
email: "user@example.com",
stem_user_id: integration_key
let(:integration_key) { "13251241" }
let(:user) { create(:user, stem_user_id: integration_key) }
let(:auth0_hash) {
OmniAuth::AuthHash.new(
provider: "stem",
uid: "auth0|user@example.com",
credentials: {
expires_at: 1_546_601_180,
token: "14849048797785647933"
},
info: {
achiever_contact_no: "b44cb53f-c690-4535-bd79-89e893337ec6",
first_name: "Jane",
last_name: "Doe",
email: "user@example.com",
stem_user_id: integration_key

}
)
}

let(:auth0_invalid_hash) {
OmniAuth::AuthHash.new(
provider: "stem",
uid: "auth0|user@example.com",
credentials: {
expires_at: 1_546_601_180,
token: "14849048797785647933"
},
info: {
achiever_contact_no: nil,
first_name: "Jane",
last_name: "Doe",
email: "user@example.com",
stem_user_id: nil

}
)
}
}
)
}

describe "#callback" do
before do
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:stem] = auth0_hash
Expand Down Expand Up @@ -53,6 +72,19 @@
end
end

context "invalid info" do
before do
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:stem] = auth0_invalid_hash
end

it "raises exception when data missing" do
expect {
get callback_path
}.to raise_error(StandardError)
end
end

context "when source_uri is not present" do
before do
OmniAuth.config.test_mode = true
Expand Down