Skip to content

Commit 928ca26

Browse files
Add a request spec exercising XSRF-TOKEN continuity across common multi-request logout flows
1 parent 6dea1ca commit 928ca26

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class InertiaSessionContinuityTestController < ApplicationController
2+
def initialize_session
3+
render inertia: 'TestNewSessionComponent'
4+
end
5+
6+
def submit_form_to_test_csrf
7+
render inertia: 'TestComponent'
8+
end
9+
10+
def clear_session
11+
session.clear
12+
13+
return redirect_to initialize_session_path
14+
end
15+
end

spec/dummy/config/routes.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,8 @@
4141
get 'merge_instance_props' => 'inertia_merge_instance_props#merge_instance_props'
4242

4343
get 'lamda_shared_props' => 'inertia_lambda_shared_props#lamda_shared_props'
44+
45+
get 'initialize_session' => 'inertia_session_continuity_test#initialize_session'
46+
post 'submit_form_to_test_csrf' => 'inertia_session_continuity_test#submit_form_to_test_csrf'
47+
delete 'clear_session' => 'inertia_session_continuity_test#clear_session'
4448
end

spec/inertia/request_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,27 @@
131131
it { is_expected.to be_nil }
132132
end
133133
end
134+
135+
it 'sets the XSRF-TOKEN cookie after the session is cleared during an inertia call' do
136+
with_forgery_protection do
137+
get initialize_session_path
138+
expect(response).to have_http_status(:ok)
139+
initial_xsrf_token_cookie = response.cookies['XSRF-TOKEN']
140+
141+
post submit_form_to_test_csrf_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => initial_xsrf_token_cookie }
142+
expect(response).to have_http_status(:ok)
143+
144+
delete clear_session_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => initial_xsrf_token_cookie }
145+
expect(response).to have_http_status(:see_other)
146+
expect(response.headers['Location']).to eq('http://www.example.com/initialize_session')
147+
148+
post_logout_xsrf_token_cookie = response.cookies['XSRF-TOKEN']
149+
expect(post_logout_xsrf_token_cookie).not_to be_nil
150+
expect(post_logout_xsrf_token_cookie).not_to eq(initial_xsrf_token_cookie)
151+
152+
post submit_form_to_test_csrf_path, headers: { 'X-Inertia' => true, 'X-XSRF-Token' => post_logout_xsrf_token_cookie }
153+
expect(response).to have_http_status(:ok)
154+
end
155+
end
134156
end
135157
end

0 commit comments

Comments
 (0)