spec/rack_api_key_spec.rb
def app

    Rack::Builder.new do
      map '/' do 
        use RackApiKey, :api_key_proc => Proc.new { |val| ApiKey.find(val) }
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end

      map "/no-api-proc" do
        use RackApiKey
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end

      map "/all-options" do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :rack_api_key => "account.api.key",
          :header_key => "HTTP_X_CUSTOM_API_HEADER"
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end

      map "/url-restricted" do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :url_restriction => [/url-restricted\/foo/]
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end

      map '/url-exclusion' do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :url_exclusion => [/url-exclusion\/foo/]
        run lambda { |env| [200, { 'Content-Type' => 'text/html' }, 'Testing Middleware'] }
      end

    end

  end
# simple test app for the middleware test
simple test app for the middleware test
simple test app for the middleware test
def app
    Rack::Builder.new do
      map '/' do 
        use RackApiKey, :api_key_proc => Proc.new { |val| ApiKey.find(val) }
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end
      map "/no-api-proc" do
        use RackApiKey
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end
      map "/all-options" do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :rack_api_key => "account.api.key",
          :header_key => "HTTP_X_CUSTOM_API_HEADER"
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end
      map "/url-restricted" do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :url_restriction => [/url-restricted\/foo/]
        run lambda { |env| [200, {"Content-Type" => "text/html"}, "Testing Middleware"] }
      end
      map '/url-exclusion' do
        use RackApiKey,
          :api_key_proc => Proc.new { |val| ApiKey.find(val) },
          :url_exclusion => [/url-exclusion\/foo/]
        run lambda { |env| [200, { 'Content-Type' => 'text/html' }, 'Testing Middleware'] }
      end
    end
  end
def app Rack :: Builder . new do map '/' do use RackApiKey , :api_key_proc => Proc . new { | val | ApiKey . find ( val ) } run lambda { | env | [ 200 , { "Content-Type" => "text/html" } , "Testing Middleware" ] } end map "/no-api-proc" do use RackApiKey run lambda { | env | [ 200 , { "Content-Type" => "text/html" } , "Testing Middleware" ] } end map "/all-options" do use RackApiKey , :api_key_proc => Proc . new { | val | ApiKey . find ( val ) } , :rack_api_key => "account.api.key" , :header_key => "HTTP_X_CUSTOM_API_HEADER" run lambda { | env | [ 200 , { "Content-Type" => "text/html" } , "Testing Middleware" ] } end map "/url-restricted" do use RackApiKey , :api_key_proc => Proc . new { | val | ApiKey . find ( val ) } , :url_restriction => [ / url-restricted \/ foo / ] run lambda { | env | [ 200 , { "Content-Type" => "text/html" } , "Testing Middleware" ] } end map '/url-exclusion' do use RackApiKey , :api_key_proc => Proc . new { | val | ApiKey . find ( val ) } , :url_exclusion => [ / url-exclusion \/ foo / ] run lambda { | env | [ 200 , { 'Content-Type' => 'text/html' } , 'Testing Middleware' ] } end end end
simple test app for the middleware test
simple test app for the middleware test