PageRenderTime 22ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rack-protection-1.5.3/spec/base_spec.rb

https://github.com/delowong/logstash
Ruby | 40 lines | 32 code | 8 blank | 0 comment | 4 complexity | ebe1b23c5ca58fbbc09ce653112ec822 MD5 | raw file
 1require File.expand_path('../spec_helper.rb', __FILE__)
 2
 3describe Rack::Protection::Base do
 4
 5  subject { described_class.new(lambda {}) }
 6
 7  describe "#random_string" do
 8    it "outputs a string of 32 characters" do
 9      subject.random_string.length.should == 32
10    end
11  end
12
13  describe "#referrer" do
14    it "Reads referrer from Referer header" do
15      env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "http://bar.com/valid"}
16      subject.referrer(env).should == "bar.com"
17    end
18
19    it "Reads referrer from Host header when Referer header is relative" do
20      env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "/valid"}
21      subject.referrer(env).should == "foo.com"
22    end
23
24    it "Reads referrer from Host header when Referer header is missing" do
25      env = {"HTTP_HOST" => "foo.com"}
26      subject.referrer(env).should == "foo.com"
27    end
28
29    it "Returns nil when Referer header is missing and allow_empty_referrer is false" do
30      env = {"HTTP_HOST" => "foo.com"}
31      subject.options[:allow_empty_referrer] = false
32      subject.referrer(env).should be_nil
33    end
34
35    it "Returns nil when Referer header is invalid" do
36      env = {"HTTP_HOST" => "foo.com", "HTTP_REFERER" => "http://bar.com/bad|uri"}
37      subject.referrer(env).should be_nil
38    end
39  end
40end