Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c69f63
commit fe297b2
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
require "rspec/core/rake_task" | ||
|
||
RSpec::Core::RakeTask.new(:spec) do |spec| | ||
spec.pattern = FileList['spec/**/*_spec.rb'] | ||
end | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require File.expand_path('../spec_helper.rb', __FILE__) | ||
|
||
describe Rack::Policy::CookieLimiter do | ||
|
||
it 'preserves normal requests' do | ||
get('/').should be_ok | ||
last_response.body.should == 'ok' | ||
end | ||
|
||
it "does not meter where the middleware is inserted" | ||
|
||
context 'no consent' do | ||
it 'removes cookie session header' do | ||
mock_app with_headers('Set-Cookie' => "google=bot") | ||
get '/' | ||
last_response.should be_ok | ||
last_response.headers['Set-Cookie'].should be_nil | ||
end | ||
|
||
it 'revalidates caches' do | ||
mock_app with_headers('Set-Cookie' => "google=bot") | ||
get '/' | ||
last_response.should be_ok | ||
last_response.headers['Cache-control'].should_not be_nil | ||
end | ||
end | ||
|
||
context 'with consent' do | ||
it 'preserves cookie header' do | ||
mock_app with_headers('Set-Cookie' => "cookie_limiter=true; path=/;") | ||
get '/' | ||
last_response.should be_ok | ||
last_response.headers['Set-Cookie'].should_not be_nil | ||
end | ||
|
||
it 'sets consent cookie' do | ||
mock_app with_headers('Set-Cookie' => "cookie_limiter=true; path=/;") | ||
get '/' | ||
last_response.headers['Set-Cookie'].should =~ /cookie_limiter/ | ||
end | ||
|
||
it 'preserves other session cookies' do | ||
mock_app with_headers('Set-Cookie' => "cookie_limiter=true; path=/;\ngithub.com=bot") | ||
get '/' | ||
last_response.headers['Set-Cookie'].should =~ /github.com=bot/ | ||
end | ||
end | ||
|
||
end # Rack::Policy::CookieLimiter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'rubygems' | ||
|
||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
|
||
require 'rspec' | ||
require 'rack/test' | ||
require 'rack/policy' | ||
|
||
module DummyApp | ||
def self.call(env) | ||
Thread.current[:last_env] = env | ||
[200, {'Content-Type' => 'text/plain'}, ['ok']] | ||
end | ||
end | ||
|
||
module TestHelpers | ||
def app | ||
@app || mock_app(DummyApp) | ||
end | ||
|
||
def mock_app(app=nil, &block) | ||
app = block if app.nil? and block.arity == 1 | ||
if app | ||
klass = described_class | ||
mock_app do | ||
use klass | ||
run app | ||
end | ||
else | ||
@app = Rack::Lint.new Rack::Builder.new(&block).to_app | ||
end | ||
end | ||
|
||
def with_headers(headers) | ||
proc { [200, {'Content-Type' => 'text/plain' }.merge(headers), ['ok']] } | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.order = :rand | ||
config.expect_with :rspec, :stdlib | ||
config.include Rack::Test::Methods | ||
config.include TestHelpers | ||
end |