Skip to content

Commit 91d0296

Browse files
committed
Check content item is a sign in page before attempting to sign in
This works by checking that the path contains the string 'sign-in'. I was hoping to use a route constraint, but couldn't get it to work on a glob/catch all parameter.
1 parent c1afd34 commit 91d0296

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

app/controllers/content_items_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def show
2323
end
2424

2525
def service_sign_in_options
26+
return head :not_found unless is_sign_in_content_item_path?
27+
2628
if params[:option].blank?
2729
@error = true
2830
show
@@ -35,6 +37,10 @@ def service_sign_in_options
3537

3638
private
3739

40+
def is_sign_in_content_item_path?
41+
content_item_path.include?("sign-in")
42+
end
43+
3844
# Allow guides to pass access token to each part to allow
3945
# fact checking of all content
4046
def set_guide_draft_access_token

test/controllers/service_sign_in_content_item_controller_test.rb

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class ContentItemsControllerTest < ActionController::TestCase
5252
end
5353

5454

55+
test "raises a 404 for a content item which isn't a service_sign_in page" do
56+
path = "this/is/not/a/sign/in/page"
57+
post :service_sign_in_options, params: { path: path }
58+
assert_response :not_found
59+
end
5560

5661
test "service_sign_in_options with option param set" do
5762
content_item = content_store_has_schema_example("service_sign_in", "service_sign_in")

0 commit comments

Comments
 (0)