This repository has been archived by the owner on May 16, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from statianzo/invalid-referer
Discard invalid Referer header
- Loading branch information
Showing
2 changed files
with
33 additions
and
1 deletion.
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
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,9 +1,40 @@ | ||
require File.expand_path('../spec_helper.rb', __FILE__) | ||
|
||
describe Rack::Protection::Base do | ||
|
||
subject { described_class.new(lambda {}) } | ||
|
||
describe "#random_string" do | ||
it "outputs a string of 32 characters" do | ||
described_class.new(lambda {}).random_string.length.should == 32 | ||
subject.random_string.length.should == 32 | ||
end | ||
end | ||
|
||
describe "#referrer" do | ||
it "Reads referrer from Referer header" do | ||
env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "http://bar.com/valid"} | ||
subject.referrer(env).should == "bar.com" | ||
end | ||
|
||
it "Reads referrer from Host header when Referer header is relative" do | ||
env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "/valid"} | ||
subject.referrer(env).should == "foo.com" | ||
end | ||
|
||
it "Reads referrer from Host header when Referer header is missing" do | ||
env = {"HTTP_HOST" => "foo.com"} | ||
subject.referrer(env).should == "foo.com" | ||
end | ||
|
||
it "Returns nil when Referer header is missing and allow_empty_referrer is false" do | ||
env = {"HTTP_HOST" => "foo.com"} | ||
subject.options[:allow_empty_referrer] = false | ||
subject.referrer(env).should be_nil | ||
end | ||
|
||
it "Returns nil when Referer header is invalid" do | ||
env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "http://bar.com/bad|uri"} | ||
subject.referrer(env).should be_nil | ||
end | ||
end | ||
end |