Skip to content

Commit

Permalink
Adding tests for new 401 handling
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Feb 8, 2024
1 parent 5cb6dc0 commit 6e6e161
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion test/shopify_app/controller_concerns/login_protection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,20 @@ class LoginProtectionControllerTest < ActionController::TestCase
cookies.encrypted[ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME] = "cookie"

get :raise_unauthorized, params: { shop: "foobar" }
assert_redirected_to "/login?shop=foobar.myshopify.com"
assert_redirected_to "/login?return_to=%2Fraise_unauthorized%3Fshop%3Dfoobar.myshopify.com&shop=foobar.myshopify.com"
assert_nil cookies.encrypted[ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME]
end
end

test "#activate_shopify_session when rescuing from unauthorized access, breaks out of iframe in XHR requests" do
with_application_test_routes do
get :raise_unauthorized, params: { shop: "foobar" }, xhr: true
assert_equal 401, response.status
assert_match "1", response.headers["X-Shopify-API-Request-Failure-Reauthorize"]
assert_match "/login?shop=foobar", response.headers["X-Shopify-API-Request-Failure-Reauthorize-Url"]
end
end

test "#activate_shopify_session when rescuing from non 401 errors, does not close session" do
with_application_test_routes do
cookies.encrypted[ShopifyAPI::Auth::Oauth::SessionCookie::SESSION_COOKIE_NAME] = "cookie"
Expand Down

0 comments on commit 6e6e161

Please sign in to comment.