Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch OIDC error #13078

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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: 9 additions & 0 deletions app/controllers/admin/dfc_product_imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
self.class
end

def index

Check warning on line 13 in app/controllers/admin/dfc_product_imports_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Assignment Branch Condition size for index is too high. [<11, 40, 4> 41.68/30] Raw Output: app/controllers/admin/dfc_product_imports_controller.rb:13:5: C: Metrics/AbcSize: Assignment Branch Condition size for index is too high. [<11, 40, 4> 41.68/30]

Check warning on line 13 in app/controllers/admin/dfc_product_imports_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Method has too many lines. [29/25] Raw Output: app/controllers/admin/dfc_product_imports_controller.rb:13:5: C: Metrics/MethodLength: Method has too many lines. [29/25]
# The plan:
#
# * Fetch DFC catalog as JSON from URL.
Expand All @@ -35,6 +35,15 @@
end

@count = imported.compact.count
rescue Rack::OAuth2::Client::Error => e
flash[:error] = I18n.t(
'admin.dfc_product_imports.index.oauth_error_html',
message: e.message,
oidc_settings_link: ActionController::Base.helpers.link_to(
I18n.t('spree.admin.tab.oidc_settings'), Rails.application.routes.url_helpers.admin_oidc_settings_path

Check warning on line 43 in app/controllers/admin/dfc_product_imports_controller.rb

View workflow job for this annotation

GitHub Actions / runner / rubocop

[rubocop] reported by reviewdog 🐶 Line is too long. [112/100] Raw Output: app/controllers/admin/dfc_product_imports_controller.rb:43:101: C: Layout/LineLength: Line is too long. [112/100]
)
).html_safe
dacook marked this conversation as resolved.
Show resolved Hide resolved
redirect_to admin_product_import_path
rescue Faraday::Error,
Addressable::URI::InvalidURIError,
ActionController::ParameterMissing => e
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ en:
index:
title: "Importing a DFC product catalog"
imported_products: "Imported products:"
oauth_error_html: "Authentication error: %{message}. See %{oidc_settings_link}"
enterprise_fees:
index:
title: "Enterprise Fees"
Expand Down

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

24 changes: 24 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,30 @@
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" }
)
)
dacook marked this conversation as resolved.
Show resolved Hide resolved

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"

within ".flash" do
expect(page).to have_content "invalid_grant"
expect(page).to have_content "session not active"
expect(page).to have_link "OIDC Settings"
end
end

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