|
| 1 | +require 'rack' |
| 2 | + |
| 3 | +describe Rack::Auth do |
| 4 | + it "should have all common authentication schemes" do |
| 5 | + Rack::Auth.schemes.should.include? 'basic' |
| 6 | + Rack::Auth.schemes.should.include? 'digest' |
| 7 | + Rack::Auth.schemes.should.include? 'bearer' |
| 8 | + Rack::Auth.schemes.should.include? 'token' |
| 9 | + end |
| 10 | + |
| 11 | + it "should allow registration of new auth schemes" do |
| 12 | + Rack::Auth.schemes.should.not.include "test" |
| 13 | + Rack::Auth.add_scheme "test" |
| 14 | + Rack::Auth.schemes.should.include "test" |
| 15 | + end |
| 16 | +end |
| 17 | + |
| 18 | +describe Rack::Auth::AbstractRequest do |
| 19 | + it "should symbolize known auth schemes" do |
| 20 | + env = Rack::MockRequest.env_for('/') |
| 21 | + env['HTTP_AUTHORIZATION'] = 'Basic aXJyZXNwb25zaWJsZQ==' |
| 22 | + req = Rack::Auth::AbstractRequest.new(env) |
| 23 | + req.scheme.should == :basic |
| 24 | + |
| 25 | + |
| 26 | + env['HTTP_AUTHORIZATION'] = 'Digest aXJyZXNwb25zaWJsZQ==' |
| 27 | + req = Rack::Auth::AbstractRequest.new(env) |
| 28 | + req.scheme.should == :digest |
| 29 | + |
| 30 | + env['HTTP_AUTHORIZATION'] = 'Bearer aXJyZXNwb25zaWJsZQ==' |
| 31 | + req = Rack::Auth::AbstractRequest.new(env) |
| 32 | + req.scheme.should == :bearer |
| 33 | + |
| 34 | + env['HTTP_AUTHORIZATION'] = 'MAC aXJyZXNwb25zaWJsZQ==' |
| 35 | + req = Rack::Auth::AbstractRequest.new(env) |
| 36 | + req.scheme.should == :mac |
| 37 | + |
| 38 | + env['HTTP_AUTHORIZATION'] = 'Token aXJyZXNwb25zaWJsZQ==' |
| 39 | + req = Rack::Auth::AbstractRequest.new(env) |
| 40 | + req.scheme.should == :token |
| 41 | + |
| 42 | + env['HTTP_AUTHORIZATION'] = 'OAuth aXJyZXNwb25zaWJsZQ==' |
| 43 | + req = Rack::Auth::AbstractRequest.new(env) |
| 44 | + req.scheme.should == :oauth |
| 45 | + |
| 46 | + env['HTTP_AUTHORIZATION'] = 'OAuth2 aXJyZXNwb25zaWJsZQ==' |
| 47 | + req = Rack::Auth::AbstractRequest.new(env) |
| 48 | + req.scheme.should == :oauth2 |
| 49 | + end |
| 50 | + |
| 51 | + it "should not symbolize unknown auth schemes" do |
| 52 | + env = Rack::MockRequest.env_for('/') |
| 53 | + env['HTTP_AUTHORIZATION'] = 'magic aXJyZXNwb25zaWJsZQ==' |
| 54 | + req = Rack::Auth::AbstractRequest.new(env) |
| 55 | + req.scheme.should == "magic" |
| 56 | + end |
| 57 | +end |
0 commit comments