kastner-rack 0.3.171
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +8 -0
- data/COPYING +18 -0
- data/KNOWN-ISSUES +18 -0
- data/README +273 -0
- data/Rakefile +185 -0
- data/bin/rackup +172 -0
- data/contrib/rack_logo.svg +111 -0
- data/example/lobster.ru +4 -0
- data/example/protectedlobster.rb +14 -0
- data/example/protectedlobster.ru +8 -0
- data/lib/rack.rb +85 -0
- data/lib/rack/adapter/camping.rb +22 -0
- data/lib/rack/auth/abstract/handler.rb +28 -0
- data/lib/rack/auth/abstract/request.rb +37 -0
- data/lib/rack/auth/basic.rb +58 -0
- data/lib/rack/auth/digest/md5.rb +124 -0
- data/lib/rack/auth/digest/nonce.rb +51 -0
- data/lib/rack/auth/digest/params.rb +55 -0
- data/lib/rack/auth/digest/request.rb +40 -0
- data/lib/rack/auth/openid.rb +437 -0
- data/lib/rack/builder.rb +67 -0
- data/lib/rack/cascade.rb +36 -0
- data/lib/rack/commonlogger.rb +61 -0
- data/lib/rack/conditionalget.rb +42 -0
- data/lib/rack/deflater.rb +63 -0
- data/lib/rack/directory.rb +149 -0
- data/lib/rack/file.rb +84 -0
- data/lib/rack/handler.rb +46 -0
- data/lib/rack/handler/cgi.rb +57 -0
- data/lib/rack/handler/evented_mongrel.rb +8 -0
- data/lib/rack/handler/fastcgi.rb +86 -0
- data/lib/rack/handler/lsws.rb +52 -0
- data/lib/rack/handler/mongrel.rb +78 -0
- data/lib/rack/handler/scgi.rb +57 -0
- data/lib/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/rack/handler/webrick.rb +61 -0
- data/lib/rack/head.rb +19 -0
- data/lib/rack/lint.rb +463 -0
- data/lib/rack/lobster.rb +65 -0
- data/lib/rack/methodoverride.rb +21 -0
- data/lib/rack/mime.rb +204 -0
- data/lib/rack/mock.rb +160 -0
- data/lib/rack/recursive.rb +57 -0
- data/lib/rack/reloader.rb +64 -0
- data/lib/rack/request.rb +217 -0
- data/lib/rack/response.rb +171 -0
- data/lib/rack/session/abstract/id.rb +140 -0
- data/lib/rack/session/cookie.rb +89 -0
- data/lib/rack/session/memcache.rb +97 -0
- data/lib/rack/session/pool.rb +73 -0
- data/lib/rack/showexceptions.rb +348 -0
- data/lib/rack/showstatus.rb +105 -0
- data/lib/rack/static.rb +38 -0
- data/lib/rack/urlmap.rb +48 -0
- data/lib/rack/utils.rb +318 -0
- data/rack.gemspec +31 -0
- data/test/cgi/lighttpd.conf +20 -0
- data/test/cgi/test +9 -0
- data/test/cgi/test.fcgi +8 -0
- data/test/cgi/test.ru +7 -0
- data/test/spec_rack_auth_basic.rb +69 -0
- data/test/spec_rack_auth_digest.rb +169 -0
- data/test/spec_rack_auth_openid.rb +137 -0
- data/test/spec_rack_builder.rb +84 -0
- data/test/spec_rack_camping.rb +51 -0
- data/test/spec_rack_cascade.rb +50 -0
- data/test/spec_rack_cgi.rb +89 -0
- data/test/spec_rack_commonlogger.rb +32 -0
- data/test/spec_rack_conditionalget.rb +41 -0
- data/test/spec_rack_deflater.rb +70 -0
- data/test/spec_rack_directory.rb +56 -0
- data/test/spec_rack_fastcgi.rb +89 -0
- data/test/spec_rack_file.rb +57 -0
- data/test/spec_rack_handler.rb +24 -0
- data/test/spec_rack_head.rb +30 -0
- data/test/spec_rack_lint.rb +371 -0
- data/test/spec_rack_lobster.rb +45 -0
- data/test/spec_rack_methodoverride.rb +31 -0
- data/test/spec_rack_mock.rb +152 -0
- data/test/spec_rack_mongrel.rb +170 -0
- data/test/spec_rack_recursive.rb +77 -0
- data/test/spec_rack_request.rb +426 -0
- data/test/spec_rack_response.rb +173 -0
- data/test/spec_rack_session_cookie.rb +78 -0
- data/test/spec_rack_session_memcache.rb +132 -0
- data/test/spec_rack_session_pool.rb +84 -0
- data/test/spec_rack_showexceptions.rb +21 -0
- data/test/spec_rack_showstatus.rb +72 -0
- data/test/spec_rack_static.rb +37 -0
- data/test/spec_rack_urlmap.rb +175 -0
- data/test/spec_rack_utils.rb +174 -0
- data/test/spec_rack_webrick.rb +123 -0
- data/test/testrequest.rb +45 -0
- metadata +177 -0
data/rack.gemspec
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = %q{rack}
|
|
3
|
+
s.version = "0.3.171"
|
|
4
|
+
|
|
5
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
|
+
s.authors = ["Christian Neukirchen"]
|
|
7
|
+
s.date = %q{2008-11-28}
|
|
8
|
+
s.default_executable = %q{rackup}
|
|
9
|
+
s.description = %q{Rack provides minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. Also see http://rack.rubyforge.org.}
|
|
10
|
+
s.email = %q{chneukirchen@gmail.com}
|
|
11
|
+
s.executables = ["rackup"]
|
|
12
|
+
s.extra_rdoc_files = ["README", "KNOWN-ISSUES"]
|
|
13
|
+
s.files = ["AUTHORS", "COPYING", "KNOWN-ISSUES", "README", "Rakefile", "bin/rackup", "contrib/rack_logo.svg", "example/lobster.ru", "example/protectedlobster.rb", "example/protectedlobster.ru", "lib/rack.rb", "lib/rack/adapter/camping.rb", "lib/rack/auth/abstract/handler.rb", "lib/rack/auth/abstract/request.rb", "lib/rack/auth/basic.rb", "lib/rack/auth/digest/md5.rb", "lib/rack/auth/digest/nonce.rb", "lib/rack/auth/digest/params.rb", "lib/rack/auth/digest/request.rb", "lib/rack/auth/openid.rb", "lib/rack/builder.rb", "lib/rack/cascade.rb", "lib/rack/commonlogger.rb", "lib/rack/conditionalget.rb", "lib/rack/deflater.rb", "lib/rack/directory.rb", "lib/rack/file.rb", "lib/rack/handler.rb", "lib/rack/handler/cgi.rb", "lib/rack/handler/evented_mongrel.rb", "lib/rack/handler/fastcgi.rb", "lib/rack/handler/lsws.rb", "lib/rack/handler/mongrel.rb", "lib/rack/handler/scgi.rb", "lib/rack/handler/swiftiplied_mongrel.rb", "lib/rack/handler/webrick.rb", "lib/rack/head.rb", "lib/rack/lint.rb", "lib/rack/lobster.rb", "lib/rack/methodoverride.rb", "lib/rack/mime.rb", "lib/rack/mock.rb", "lib/rack/recursive.rb", "lib/rack/reloader.rb", "lib/rack/request.rb", "lib/rack/response.rb", "lib/rack/session/abstract/id.rb", "lib/rack/session/cookie.rb", "lib/rack/session/memcache.rb", "lib/rack/session/pool.rb", "lib/rack/showexceptions.rb", "lib/rack/showstatus.rb", "lib/rack/static.rb", "lib/rack/urlmap.rb", "lib/rack/utils.rb", "rack.gemspec", "test/cgi/lighttpd.conf", "test/cgi/test", "test/cgi/test.fcgi", "test/cgi/test.ru", "test/spec_rack_auth_basic.rb", "test/spec_rack_auth_digest.rb", "test/spec_rack_auth_openid.rb", "test/spec_rack_builder.rb", "test/spec_rack_camping.rb", "test/spec_rack_cascade.rb", "test/spec_rack_cgi.rb", "test/spec_rack_commonlogger.rb", "test/spec_rack_conditionalget.rb", "test/spec_rack_deflater.rb", "test/spec_rack_directory.rb", "test/spec_rack_fastcgi.rb", "test/spec_rack_file.rb", "test/spec_rack_handler.rb", "test/spec_rack_head.rb", "test/spec_rack_lint.rb", "test/spec_rack_lobster.rb", "test/spec_rack_methodoverride.rb", "test/spec_rack_mock.rb", "test/spec_rack_mongrel.rb", "test/spec_rack_recursive.rb", "test/spec_rack_request.rb", "test/spec_rack_response.rb", "test/spec_rack_session_cookie.rb", "test/spec_rack_session_memcache.rb", "test/spec_rack_session_pool.rb", "test/spec_rack_showexceptions.rb", "test/spec_rack_showstatus.rb", "test/spec_rack_static.rb", "test/spec_rack_urlmap.rb", "test/spec_rack_utils.rb", "test/spec_rack_webrick.rb", "test/testrequest.rb"]
|
|
14
|
+
s.has_rdoc = true
|
|
15
|
+
s.homepage = %q{http://rack.rubyforge.org}
|
|
16
|
+
s.require_paths = ["lib"]
|
|
17
|
+
s.rubyforge_project = %q{rack}
|
|
18
|
+
s.rubygems_version = %q{1.2.0}
|
|
19
|
+
s.summary = %q{a modular Ruby webserver interface}
|
|
20
|
+
s.test_files = ["test/spec_rack_auth_basic.rb", "test/spec_rack_auth_digest.rb", "test/spec_rack_auth_openid.rb", "test/spec_rack_builder.rb", "test/spec_rack_camping.rb", "test/spec_rack_cascade.rb", "test/spec_rack_cgi.rb", "test/spec_rack_commonlogger.rb", "test/spec_rack_conditionalget.rb", "test/spec_rack_deflater.rb", "test/spec_rack_directory.rb", "test/spec_rack_fastcgi.rb", "test/spec_rack_file.rb", "test/spec_rack_handler.rb", "test/spec_rack_head.rb", "test/spec_rack_lint.rb", "test/spec_rack_lobster.rb", "test/spec_rack_methodoverride.rb", "test/spec_rack_mock.rb", "test/spec_rack_mongrel.rb", "test/spec_rack_recursive.rb", "test/spec_rack_request.rb", "test/spec_rack_response.rb", "test/spec_rack_session_cookie.rb", "test/spec_rack_session_memcache.rb", "test/spec_rack_session_pool.rb", "test/spec_rack_showexceptions.rb", "test/spec_rack_showstatus.rb", "test/spec_rack_static.rb", "test/spec_rack_urlmap.rb", "test/spec_rack_utils.rb", "test/spec_rack_webrick.rb"]
|
|
21
|
+
|
|
22
|
+
if s.respond_to? :specification_version then
|
|
23
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
24
|
+
s.specification_version = 2
|
|
25
|
+
|
|
26
|
+
if current_version >= 3 then
|
|
27
|
+
else
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
server.modules = ("mod_fastcgi", "mod_cgi")
|
|
2
|
+
server.document-root = "."
|
|
3
|
+
server.errorlog = "lighttpd.errors"
|
|
4
|
+
server.port = 9203
|
|
5
|
+
|
|
6
|
+
server.event-handler = "freebsd-kqueue"
|
|
7
|
+
|
|
8
|
+
cgi.assign = ("/test" => "",
|
|
9
|
+
# ".ru" => ""
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
fastcgi.server = ("test.fcgi" => ("localhost" =>
|
|
13
|
+
("min-procs" => 1,
|
|
14
|
+
"socket" => "/tmp/rack-test-fcgi",
|
|
15
|
+
"bin-path" => "test.fcgi")),
|
|
16
|
+
"test.ru" => ("localhost" =>
|
|
17
|
+
("min-procs" => 1,
|
|
18
|
+
"socket" => "/tmp/rack-test-ru-fcgi",
|
|
19
|
+
"bin-path" => "test.ru")),
|
|
20
|
+
)
|
data/test/cgi/test
ADDED
data/test/cgi/test.fcgi
ADDED
data/test/cgi/test.ru
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
require 'test/spec'
|
|
2
|
+
|
|
3
|
+
require 'rack/auth/basic'
|
|
4
|
+
require 'rack/mock'
|
|
5
|
+
|
|
6
|
+
context 'Rack::Auth::Basic' do
|
|
7
|
+
|
|
8
|
+
def realm
|
|
9
|
+
'WallysWorld'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def unprotected_app
|
|
13
|
+
lambda { |env| [ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ] }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def protected_app
|
|
17
|
+
app = Rack::Auth::Basic.new(unprotected_app) { |username, password| 'Boss' == username }
|
|
18
|
+
app.realm = realm
|
|
19
|
+
app
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
setup do
|
|
23
|
+
@request = Rack::MockRequest.new(protected_app)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def request_with_basic_auth(username, password, &block)
|
|
27
|
+
request 'HTTP_AUTHORIZATION' => 'Basic ' + ["#{username}:#{password}"].pack("m*"), &block
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def request(headers = {})
|
|
31
|
+
yield @request.get('/', headers)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def assert_basic_auth_challenge(response)
|
|
35
|
+
response.should.be.a.client_error
|
|
36
|
+
response.status.should.equal 401
|
|
37
|
+
response.should.include 'WWW-Authenticate'
|
|
38
|
+
response.headers['WWW-Authenticate'].should =~ /Basic realm="/
|
|
39
|
+
response.body.should.be.empty
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
specify 'should challenge correctly when no credentials are specified' do
|
|
43
|
+
request do |response|
|
|
44
|
+
assert_basic_auth_challenge response
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
specify 'should rechallenge if incorrect credentials are specified' do
|
|
49
|
+
request_with_basic_auth 'joe', 'password' do |response|
|
|
50
|
+
assert_basic_auth_challenge response
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
specify 'should return application output if correct credentials are specified' do
|
|
55
|
+
request_with_basic_auth 'Boss', 'password' do |response|
|
|
56
|
+
response.status.should.equal 200
|
|
57
|
+
response.body.to_s.should.equal 'Hi Boss'
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
specify 'should return 400 Bad Request if different auth scheme used' do
|
|
62
|
+
request 'HTTP_AUTHORIZATION' => 'Digest params' do |response|
|
|
63
|
+
response.should.be.a.client_error
|
|
64
|
+
response.status.should.equal 400
|
|
65
|
+
response.should.not.include 'WWW-Authenticate'
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
end
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
require 'test/spec'
|
|
2
|
+
|
|
3
|
+
require 'rack/auth/digest/md5'
|
|
4
|
+
require 'rack/mock'
|
|
5
|
+
|
|
6
|
+
context 'Rack::Auth::Digest::MD5' do
|
|
7
|
+
|
|
8
|
+
def realm
|
|
9
|
+
'WallysWorld'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def unprotected_app
|
|
13
|
+
lambda do |env|
|
|
14
|
+
[ 200, {'Content-Type' => 'text/plain'}, ["Hi #{env['REMOTE_USER']}"] ]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def protected_app
|
|
19
|
+
app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username|
|
|
20
|
+
{ 'Alice' => 'correct-password' }[username]
|
|
21
|
+
end
|
|
22
|
+
app.realm = realm
|
|
23
|
+
app.opaque = 'this-should-be-secret'
|
|
24
|
+
app
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def protected_app_with_hashed_passwords
|
|
28
|
+
app = Rack::Auth::Digest::MD5.new(unprotected_app) do |username|
|
|
29
|
+
username == 'Alice' ? Digest::MD5.hexdigest("Alice:#{realm}:correct-password") : nil
|
|
30
|
+
end
|
|
31
|
+
app.realm = realm
|
|
32
|
+
app.opaque = 'this-should-be-secret'
|
|
33
|
+
app.passwords_hashed = true
|
|
34
|
+
app
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
setup do
|
|
38
|
+
@request = Rack::MockRequest.new(protected_app)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(path, headers = {}, &block)
|
|
42
|
+
response = @request.get(path, headers)
|
|
43
|
+
block.call(response) if block
|
|
44
|
+
return response
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class MockDigestRequest
|
|
48
|
+
def initialize(params)
|
|
49
|
+
@params = params
|
|
50
|
+
end
|
|
51
|
+
def method_missing(sym)
|
|
52
|
+
if @params.has_key? k = sym.to_s
|
|
53
|
+
return @params[k]
|
|
54
|
+
end
|
|
55
|
+
super
|
|
56
|
+
end
|
|
57
|
+
def method
|
|
58
|
+
'GET'
|
|
59
|
+
end
|
|
60
|
+
def response(password)
|
|
61
|
+
Rack::Auth::Digest::MD5.new(nil).send :digest, self, password
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def request_with_digest_auth(path, username, password, options = {}, &block)
|
|
66
|
+
response = request('/')
|
|
67
|
+
|
|
68
|
+
return response unless response.status == 401
|
|
69
|
+
|
|
70
|
+
if wait = options.delete(:wait)
|
|
71
|
+
sleep wait
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
challenge = response['WWW-Authenticate'].split(' ', 2).last
|
|
75
|
+
|
|
76
|
+
params = Rack::Auth::Digest::Params.parse(challenge)
|
|
77
|
+
|
|
78
|
+
params['username'] = username
|
|
79
|
+
params['nc'] = '00000001'
|
|
80
|
+
params['cnonce'] = 'nonsensenonce'
|
|
81
|
+
params['uri'] = path
|
|
82
|
+
|
|
83
|
+
params.update options
|
|
84
|
+
|
|
85
|
+
params['response'] = MockDigestRequest.new(params).response(password)
|
|
86
|
+
|
|
87
|
+
request(path, { 'HTTP_AUTHORIZATION' => "Digest #{params}" }, &block)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def assert_digest_auth_challenge(response)
|
|
91
|
+
response.should.be.a.client_error
|
|
92
|
+
response.status.should.equal 401
|
|
93
|
+
response.should.include 'WWW-Authenticate'
|
|
94
|
+
response.headers['WWW-Authenticate'].should =~ /^Digest /
|
|
95
|
+
response.body.should.be.empty
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def assert_bad_request(response)
|
|
99
|
+
response.should.be.a.client_error
|
|
100
|
+
response.status.should.equal 400
|
|
101
|
+
response.should.not.include 'WWW-Authenticate'
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
specify 'should challenge when no credentials are specified' do
|
|
105
|
+
request '/' do |response|
|
|
106
|
+
assert_digest_auth_challenge response
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
specify 'should return application output if correct credentials given' do
|
|
111
|
+
request_with_digest_auth '/', 'Alice', 'correct-password' do |response|
|
|
112
|
+
response.status.should.equal 200
|
|
113
|
+
response.body.to_s.should.equal 'Hi Alice'
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
specify 'should return application output if correct credentials given (hashed passwords)' do
|
|
118
|
+
@request = Rack::MockRequest.new(protected_app_with_hashed_passwords)
|
|
119
|
+
|
|
120
|
+
request_with_digest_auth '/', 'Alice', 'correct-password' do |response|
|
|
121
|
+
response.status.should.equal 200
|
|
122
|
+
response.body.to_s.should.equal 'Hi Alice'
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
specify 'should rechallenge if incorrect username given' do
|
|
127
|
+
request_with_digest_auth '/', 'Bob', 'correct-password' do |response|
|
|
128
|
+
assert_digest_auth_challenge response
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
specify 'should rechallenge if incorrect password given' do
|
|
133
|
+
request_with_digest_auth '/', 'Alice', 'wrong-password' do |response|
|
|
134
|
+
assert_digest_auth_challenge response
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
specify 'should rechallenge with stale parameter if nonce is stale' do
|
|
139
|
+
begin
|
|
140
|
+
Rack::Auth::Digest::Nonce.time_limit = 1
|
|
141
|
+
|
|
142
|
+
request_with_digest_auth '/', 'Alice', 'correct-password', :wait => 2 do |response|
|
|
143
|
+
assert_digest_auth_challenge response
|
|
144
|
+
response.headers['WWW-Authenticate'].should =~ /\bstale=true\b/
|
|
145
|
+
end
|
|
146
|
+
ensure
|
|
147
|
+
Rack::Auth::Digest::Nonce.time_limit = nil
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
specify 'should return 400 Bad Request if incorrect qop given' do
|
|
152
|
+
request_with_digest_auth '/', 'Alice', 'correct-password', 'qop' => 'auth-int' do |response|
|
|
153
|
+
assert_bad_request response
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
specify 'should return 400 Bad Request if incorrect uri given' do
|
|
158
|
+
request_with_digest_auth '/', 'Alice', 'correct-password', 'uri' => '/foo' do |response|
|
|
159
|
+
assert_bad_request response
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
specify 'should return 400 Bad Request if different auth scheme used' do
|
|
164
|
+
request '/', 'HTTP_AUTHORIZATION' => 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==' do |response|
|
|
165
|
+
assert_bad_request response
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
require 'test/spec'
|
|
2
|
+
|
|
3
|
+
begin
|
|
4
|
+
# requires the ruby-openid gem
|
|
5
|
+
require 'rack/auth/openid'
|
|
6
|
+
|
|
7
|
+
context "Rack::Auth::OpenID" do
|
|
8
|
+
OID = Rack::Auth::OpenID
|
|
9
|
+
realm = 'http://path/arf'
|
|
10
|
+
ruri = %w{arf arf/blargh}
|
|
11
|
+
auri = ruri.map{|u|'/'+u}
|
|
12
|
+
furi = auri.map{|u|'http://path'+u}
|
|
13
|
+
|
|
14
|
+
specify 'realm uri should be absolute and have a path' do
|
|
15
|
+
lambda{OID.new('/path')}.
|
|
16
|
+
should.raise ArgumentError
|
|
17
|
+
lambda{OID.new('http://path')}.
|
|
18
|
+
should.raise ArgumentError
|
|
19
|
+
lambda{OID.new('http://path/')}.
|
|
20
|
+
should.not.raise
|
|
21
|
+
lambda{OID.new('http://path/arf')}.
|
|
22
|
+
should.not.raise
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
specify 'uri options should be absolute' do
|
|
26
|
+
[:login_good, :login_fail, :login_quit, :return_to].each do |param|
|
|
27
|
+
ruri.each do |uri|
|
|
28
|
+
lambda{OID.new(realm, {param=>uri})}.
|
|
29
|
+
should.raise ArgumentError
|
|
30
|
+
end
|
|
31
|
+
auri.each do |uri|
|
|
32
|
+
lambda{OID.new(realm, {param=>uri})}.
|
|
33
|
+
should.raise ArgumentError
|
|
34
|
+
end
|
|
35
|
+
furi.each do |uri|
|
|
36
|
+
lambda{OID.new(realm, {param=>uri})}.
|
|
37
|
+
should.not.raise
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
specify 'return_to should be absolute and be under the realm' do
|
|
43
|
+
lambda{OID.new(realm, {:return_to => 'http://path'})}.
|
|
44
|
+
should.raise ArgumentError
|
|
45
|
+
lambda{OID.new(realm, {:return_to => 'http://path/'})}.
|
|
46
|
+
should.raise ArgumentError
|
|
47
|
+
lambda{OID.new(realm, {:return_to => 'http://path/arf'})}.
|
|
48
|
+
should.not.raise
|
|
49
|
+
lambda{OID.new(realm, {:return_to => 'http://path/arf/'})}.
|
|
50
|
+
should.not.raise
|
|
51
|
+
lambda{OID.new(realm, {:return_to => 'http://path/arf/blargh'})}.
|
|
52
|
+
should.not.raise
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
specify 'extensions should be a module' do
|
|
56
|
+
ext = Object.new
|
|
57
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
58
|
+
should.raise(TypeError).
|
|
59
|
+
message.should.match(/not a module/)
|
|
60
|
+
ext2 = Module.new
|
|
61
|
+
lambda{OID.new(realm).add_extension(ext2)}.
|
|
62
|
+
should.raise(ArgumentError).
|
|
63
|
+
message.should.not.match(/not a module/)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
specify 'extensions should have required constants defined' do
|
|
67
|
+
ext = Module.new
|
|
68
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
69
|
+
should.raise(ArgumentError).
|
|
70
|
+
message.should.match(/missing/)
|
|
71
|
+
ext::Request = nil
|
|
72
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
73
|
+
should.raise(ArgumentError).
|
|
74
|
+
message.should.match(/missing/).
|
|
75
|
+
should.not.match(/Request/)
|
|
76
|
+
ext::Response = nil
|
|
77
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
78
|
+
should.raise(ArgumentError).
|
|
79
|
+
message.should.match(/missing/).
|
|
80
|
+
should.not.match(/Response/)
|
|
81
|
+
ext::NS_URI = nil
|
|
82
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
83
|
+
should.raise(TypeError).
|
|
84
|
+
message.should.not.match(/missing/)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
specify 'extensions should have Request and Response defined and inherit from OpenID::Extension' do
|
|
88
|
+
$-w, w = nil, $-w # yuck
|
|
89
|
+
ext = Module.new
|
|
90
|
+
ext::Request = nil
|
|
91
|
+
ext::Response = nil
|
|
92
|
+
ext::NS_URI = nil
|
|
93
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
94
|
+
should.raise(TypeError).
|
|
95
|
+
message.should.match(/not a class/)
|
|
96
|
+
ext::Request = Class.new()
|
|
97
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
98
|
+
should.raise(TypeError).
|
|
99
|
+
message.should.match(/not a class/)
|
|
100
|
+
ext::Response = Class.new()
|
|
101
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
102
|
+
should.raise(ArgumentError).
|
|
103
|
+
message.should.match(/not a decendant/)
|
|
104
|
+
ext::Request = Class.new(::OpenID::Extension)
|
|
105
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
106
|
+
should.raise(ArgumentError).
|
|
107
|
+
message.should.match(/not a decendant/)
|
|
108
|
+
ext::Response = Class.new(::OpenID::Extension)
|
|
109
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
110
|
+
should.raise(TypeError).
|
|
111
|
+
message.should.match(/NS_URI/)
|
|
112
|
+
$-w = w
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
specify 'extensions should have NS_URI defined and be a string of an absolute http uri' do
|
|
116
|
+
$-w, w = nil, $-w # yuck
|
|
117
|
+
ext = Module.new
|
|
118
|
+
ext::Request = Class.new(::OpenID::Extension)
|
|
119
|
+
ext::Response = Class.new(::OpenID::Extension)
|
|
120
|
+
ext::NS_URI = nil
|
|
121
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
122
|
+
should.raise(TypeError).
|
|
123
|
+
message.should.match(/not a string/)
|
|
124
|
+
ext::NS_URI = 'openid.net'
|
|
125
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
126
|
+
should.raise(ArgumentError).
|
|
127
|
+
message.should.match(/not an http uri/)
|
|
128
|
+
ext::NS_URI = 'http://openid.net'
|
|
129
|
+
lambda{OID.new(realm).add_extension(ext)}.
|
|
130
|
+
should.not.raise
|
|
131
|
+
$-w = w
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
rescue LoadError
|
|
136
|
+
$stderr.puts "Skipping Rack::Auth::OpenID tests (ruby-openid 2 is required). `gem install ruby-openid` and try again."
|
|
137
|
+
end
|