|
4 | 4 | require "action_controller" |
5 | 5 | require "action_controller/base" |
6 | 6 | require "action_view/testing/resolvers" |
| 7 | +require "json" |
7 | 8 |
|
8 | 9 | class LoginProtectionController < ActionController::Base |
9 | 10 | include ShopifyApp::EmbeddedApp |
@@ -31,6 +32,13 @@ def redirect |
31 | 32 | fullpage_redirect_to("https://example.com") |
32 | 33 | end |
33 | 34 |
|
| 35 | + def shop_context |
| 36 | + render(json: { |
| 37 | + requested_shopify_domain: requested_shopify_domain, |
| 38 | + authenticated_shopify_domain: authenticated_shopify_domain, |
| 39 | + }) |
| 40 | + end |
| 41 | + |
34 | 42 | def raise_unauthorized |
35 | 43 | unauthorized_response = ShopifyAPI::Clients::HttpResponse.new(code: 401, headers: {}, body: "") |
36 | 44 | raise ShopifyAPI::Errors::HttpResponseError.new(response: unauthorized_response), "unauthorized" |
@@ -515,6 +523,22 @@ class LoginProtectionControllerTest < ActionController::TestCase |
515 | 523 | end |
516 | 524 | end |
517 | 525 |
|
| 526 | + test "shop domain helpers expose requested and authenticated domains separately" do |
| 527 | + requested_shop = "other-shop.myshopify.com" |
| 528 | + |
| 529 | + with_application_test_routes do |
| 530 | + assert @controller.respond_to?(:requested_shopify_domain, true) |
| 531 | + assert @controller.respond_to?(:authenticated_shopify_domain, true) |
| 532 | + |
| 533 | + get :shop_context, params: { shop: requested_shop } |
| 534 | + |
| 535 | + assert_response :ok |
| 536 | + context = JSON.parse(response.body) |
| 537 | + assert_equal requested_shop, context["requested_shopify_domain"] |
| 538 | + assert_equal @shop, context["authenticated_shopify_domain"] |
| 539 | + end |
| 540 | + end |
| 541 | + |
518 | 542 | test "#fullpage_redirect_to sends a post message to that shop in the shop param" do |
519 | 543 | with_application_test_routes do |
520 | 544 | example_shop = "shop.myshopify.com" |
@@ -650,6 +674,7 @@ def with_application_test_routes |
650 | 674 | get "/" => "login_protection#index" |
651 | 675 | get "/second_login" => "login_protection#second_login" |
652 | 676 | get "/redirect" => "login_protection#redirect" |
| 677 | + get "/shop_context" => "login_protection#shop_context" |
653 | 678 | get "/raise_unauthorized" => "login_protection#raise_unauthorized" |
654 | 679 | get "/raise_not_found" => "login_protection#raise_not_found" |
655 | 680 | get "/index_with_headers" => "login_protection#index_with_headers" |
|
0 commit comments