Skip to content

Commit

Permalink
Catch OIDC error
Browse files Browse the repository at this point in the history
I'm not sure if this can be tested easily, or needs to be.
  • Loading branch information
dacook committed Jan 21, 2025
1 parent a1df61c commit 4ce2730
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/controllers/admin/dfc_product_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def index
@count = imported.compact.count
rescue Faraday::Error,
Addressable::URI::InvalidURIError,
ActionController::ParameterMissing => e
ActionController::ParameterMissing,
Rack::OAuth2::Client::Error => e
flash[:error] = e.message
redirect_to admin_product_import_path
end
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions spec/system/admin/dfc_product_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@
expect(product.image).to be_present
end

it "shows oauth error message", vcr: true do
allow_any_instance_of(DfcRequest).to receive(:refresh_access_token!).and_raise(
Rack::OAuth2::Client::Error.new(
1, { error: "invalid_grant", error_description: "session not active" }
)
)

user.update!(oidc_account: build(:testdfc_account))

visit admin_product_import_path

select enterprise.name, from: "Enterprise"
url = "https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts"
fill_in "catalog_url", with: url

click_button "Import"

expect(page).to have_content "invalid_grant"
expect(page).to have_content "session not active"
end

it "fails gracefully" do
user.oidc_account.update!(
uid: "anonymous@example.net",
Expand Down

0 comments on commit 4ce2730

Please sign in to comment.