Skip to content

Commit

Permalink
Replace Sinatra::Test by Rack::Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sr committed Mar 19, 2009
1 parent ce83fa2 commit afed1e0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/authorization_test.rb
@@ -1,5 +1,5 @@
require "test/unit"
require "sinatra/test"
require "rack/test"
require "context"
require "pending"

Expand All @@ -25,7 +25,7 @@ def authorization_realm

class SinatraAuthorizationTest < Test::Unit::TestCase
before do
@session = Sinatra::TestHarness.new(AuthorizationApp)
@session = Rack::Test::Session.new(AuthorizationApp)
end

def basic_auth(user="user", password="test")
Expand All @@ -35,9 +35,9 @@ def basic_auth(user="user", password="test")
end

it "is authorized with correct credentials" do
@session.get "/", :env => basic_auth
assert_equal 200, @session.status
assert_equal "Welcome in protected zone", @session.body
@session.get "/", {}, basic_auth
assert_equal 200, @session.last_response.status
assert_equal ["Welcome in protected zone"], @session.last_response.body
end

it "sets REMOTE_USER" do
Expand All @@ -46,21 +46,21 @@ def basic_auth(user="user", password="test")

it "is unauthorized without credentials" do
@session.get "/"
assert_equal 401, @session.status
assert_equal 401, @session.last_response.status
end

it "is unauthorized with incorrect credentials" do
@session.get "/", :env => basic_auth("evil", "wrong")
assert_equal 401, @session.status
@session.get "/", {}, basic_auth("evil", "wrong")
assert_equal 401, @session.last_response.status
end

it "returns specified realm" do
@session.get "/"
assert_equal %Q(Basic realm="Move on"), @session["WWW-Authenticate"]
assert_equal %Q(Basic realm="Move on"), @session.last_response["WWW-Authenticate"]
end

it "returns a 400, Bad Request if not basic auth" do
@session.get "/", :env => { "HTTP_AUTHORIZATION" => "Foo bar" }
assert_equal 400, @session.status
@session.get "/", {}, { "HTTP_AUTHORIZATION" => "Foo bar" }
assert_equal 400, @session.last_response.status
end
end

0 comments on commit afed1e0

Please sign in to comment.