Skip to content

Commit

Permalink
Fix the specs I broke in #478 🤦
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDaugherty committed Sep 24, 2020
1 parent eae8285 commit 41eb0ad
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions spec/better_errors/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ def initialize(message, original_exception = nil)
context 'when a CSRF token cookie is not specified' do
it 'includes a newly-generated CSRF token cookie' do
expect(headers).to include(
'Set-Cookie' => /BetterErrors-CSRF-Token=[-a-z0-9]+; HttpOnly; SameSite=Strict/
'Set-Cookie' => /BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=[-a-z0-9]+; path=\/; HttpOnly; SameSite=Strict/,
)
end
end

context 'when a CSRF token cookie is specified' do
let(:response_env) { app.call({ 'HTTP_COOKIE' => 'BetterErrors-CSRF-Token=abc123' }) }
let(:response_env) { app.call({ 'HTTP_COOKIE' => "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=abc123" }) }

it 'does not set a new CSRF token cookie' do
expect(headers).not_to include('Set-Cookie')
Expand All @@ -230,14 +230,14 @@ def initialize(message, original_exception = nil)
end

it 'includes the newly-generated CSRF token in the body of the page' do
matches = headers['Set-Cookie'].match(/BetterErrors-CSRF-Token=(?<tok>[-a-z0-9]+); HttpOnly; SameSite=Strict/)
matches = headers['Set-Cookie'].match(/BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=(?<tok>[-a-z0-9]+); path=\/; HttpOnly; SameSite=Strict/)
expect(body).to include(matches[:tok])
end

context 'when a CSRF token cookie is specified' do
let(:response_env) {
app.call({
'HTTP_COOKIE' => 'BetterErrors-CSRF-Token=csrfTokenGHI',
'HTTP_COOKIE' => "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=csrfTokenGHI",
"HTTP_ACCEPT" => "text/html,application/xhtml+xml;q=0.9,*/*",
})
}
Expand Down Expand Up @@ -353,7 +353,7 @@ def initialize(message, original_exception = nil)
context 'when the body csrfToken matches the CSRF token cookie' do
let(:request_body_data) { { "index" => 0, "csrfToken" => "csrfToken123" } }
before do
request_env["HTTP_COOKIE"] = "BetterErrors-CSRF-Token=csrfToken123"
request_env["HTTP_COOKIE"] = "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=csrfToken123"
end

context 'when the Content-Type of the request is application/json' do
Expand Down Expand Up @@ -386,7 +386,7 @@ def initialize(message, original_exception = nil)
context 'when the body csrfToken does not match the CSRF token cookie' do
let(:request_body_data) { { "index" => 0, "csrfToken" => "csrfToken123" } }
before do
request_env["HTTP_COOKIE"] = "BetterErrors-CSRF-Token=csrfToken456"
request_env["HTTP_COOKIE"] = "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=csrfToken456"
end

it 'returns a JSON error' do
Expand Down Expand Up @@ -476,7 +476,7 @@ def initialize(message, original_exception = nil)
context 'when the body csrfToken matches the CSRF token cookie' do
let(:request_body_data) { { "index" => 0, "csrfToken" => "csrfToken123" } }
before do
request_env["HTTP_COOKIE"] = "BetterErrors-CSRF-Token=csrfToken123"
request_env["HTTP_COOKIE"] = "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=csrfToken123"
end

context 'when the Content-Type of the request is application/json' do
Expand Down Expand Up @@ -510,7 +510,7 @@ def initialize(message, original_exception = nil)
context 'when the body csrfToken does not match the CSRF token cookie' do
let(:request_body_data) { { "index" => 0, "csrfToken" => "csrfToken123" } }
before do
request_env["HTTP_COOKIE"] = "BetterErrors-CSRF-Token=csrfToken456"
request_env["HTTP_COOKIE"] = "BetterErrors-#{BetterErrors::VERSION}-CSRF-Token=csrfToken456"
end

it 'returns a JSON error' do
Expand Down

0 comments on commit 41eb0ad

Please sign in to comment.