Skip to content

Commit

Permalink
Merge pull request #3 from jamesdavidson/jd_add_test_cases
Browse files Browse the repository at this point in the history
Adds a couple of test cases
  • Loading branch information
beegibson committed Aug 26, 2015
2 parents 68baa49 + 69cabeb commit 6e916aa
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion spec/functional/honour_origin_cache_headers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
describe 'honour_origin_cache_headers' do

let(:a_date_in_the_future) { 'Thu, 01 Dec 2015 07:00:00 GMT' }
let(:a_date_in_the_future_plus_one) { 'Thu, 01 Dec 2015 07:01:00 GMT' }

it 'should succeed when headers are the same' do
origin = 'http://www.example.com/stuff'
headers = { 'cache-control' => 'private, max-age=0, no-store', 'expires' => 'Thu, 01 Dec 2015 07:00:00 GMT' }
headers = { 'cache-control' => 'private, max-age=0, no-store', 'expires' => a_date_in_the_future }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers)
stub_request(:any, origin).to_return(body: 'body', headers: headers)
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
end

it 'should fail when max age is slightly smaller' do
origin = 'http://www.example.com/stuff'
headers1 = { 'cache-control' => 'public, max-age=120', 'expires' => a_date_in_the_future }
headers2 = { 'cache-control' => 'public, max-age=60', 'expires' => a_date_in_the_future }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers1)
stub_request(:any, origin).to_return(body: 'body', headers: headers2)
expect {
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
}.to raise_error(/Akamai sent a max-age greater than Origin/)
end

it 'should succeed when max age is slightly larger' do
origin = 'http://www.example.com/stuff'
headers1 = { 'cache-control' => 'public, max-age=60', 'expires' => a_date_in_the_future }
headers2 = { 'cache-control' => 'public, max-age=120', 'expires' => a_date_in_the_future }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers1)
stub_request(:any, origin).to_return(body: 'body', headers: headers2)
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
end

it 'should fail when Akamai changes the cache-control values' do
origin = 'http://www.example.com/stuff'
headers1 = { 'cache-control' => 'private, max-age=0', 'expires' => a_date_in_the_future }
headers2 = { 'cache-control' => 'public, max-age=0', 'expires' => a_date_in_the_future }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers1)
stub_request(:any, origin).to_return(body: 'body', headers: headers2)
expect {
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
}.to raise_error(/Origin sent .* but Akamai did not/)
end

it 'should fail when Akamai changes the cache-control values' do
origin = 'http://www.example.com/stuff'
headers1 = { 'cache-control' => 'public, max-age=0, no-store', 'expires' => a_date_in_the_future }
headers2 = { 'cache-control' => 'public, max-age=0, no-cache', 'expires' => a_date_in_the_future }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers1)
stub_request(:any, origin).to_return(body: 'body', headers: headers2)
expect {
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
}.to raise_error(/Origin sent .* but Akamai did not/)
end

it 'should fail if the expires value are not identical' do
origin = 'http://www.example.com/stuff'
headers1 = { 'cache-control' => 'public, max-age=0, no-store', 'expires' => a_date_in_the_future }
headers2 = { 'cache-control' => 'public, max-age=0, no-store', 'expires' => a_date_in_the_future_plus_one }
stub_request(:any, DOMAIN + '/stuff').to_return(body: 'body', headers: headers1)
stub_request(:any, origin).to_return(body: 'body', headers: headers2)
expect {
expect(DOMAIN + '/stuff').to honour_origin_cache_headers(origin)
}.to raise_error(/Origin sent .* but Akamai sent/)
end
end

0 comments on commit 6e916aa

Please sign in to comment.