/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

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