Sha256: a368dd2e37abaf3914d27b8d2731ae90da0d3779690f83c4bbafe482cd0b2871

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'
require 'ronin/web/middleware/router'

require 'web/helpers/rack_app'

describe Web::Middleware::Router do
  include Helpers::Web::RackApp

  before(:all) do
    self.app = Class.new(Sinatra::Base) do
      FakeApp = Class.new(Sinatra::Base) do

        get '/test/1' do
          'fake'
        end

        get '/test/2' do
          'fake'
        end

      end

      use Ronin::Web::Middleware::Router do |router|
        router.draw :referer => /google\.com/, :to => FakeApp

        router.draw :user_agent => /MSIE/,
                    :referer => /myspace\.com/,
                    :to => FakeApp
      end

      get '/test/1' do
        'real'
      end

      get '/test/2' do
        'real'
      end

    end
  end

  it "should route matched requests to other apps" do
    get '/test/1', {}, {'HTTP_REFERER' => 'http://www.google.com/'}

    last_response.should be_ok
    last_response.body.should == 'fake'
  end

  it "should not route requests that do not match all rules" do
    get '/test/2', {}, {
      'HTTP_REFERER' => 'http://www.myspace.com/',
      'HTTP_USER_AGENT' => 'Curl'
    }

    last_response.should be_ok
    last_response.body.should_not == 'fake'
  end

  it "should still route un-matched requests to the app" do
    get '/test/1'

    last_response.should be_ok
    last_response.body.should == 'real'
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ronin-web-0.3.0.rc1 spec/web/middleware/router_spec.rb
ronin-web-0.3.0.pre2 spec/web/middleware/router_spec.rb
ronin-web-0.3.0.pre1 spec/web/middleware/router_spec.rb