aker 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG.md +210 -0
  2. data/README.md +282 -0
  3. data/assets/aker/form/login.css +73 -0
  4. data/assets/aker/form/login.html.erb +44 -0
  5. data/lib/aker/authorities/automatic_access.rb +36 -0
  6. data/lib/aker/authorities/composite.rb +301 -0
  7. data/lib/aker/authorities/static.rb +283 -0
  8. data/lib/aker/authorities/support/find_sole_user.rb +24 -0
  9. data/lib/aker/authorities/support.rb +9 -0
  10. data/lib/aker/authorities.rb +46 -0
  11. data/lib/aker/cas/authority.rb +79 -0
  12. data/lib/aker/cas/configuration_helper.rb +85 -0
  13. data/lib/aker/cas/middleware/logout_responder.rb +49 -0
  14. data/lib/aker/cas/middleware/ticket_remover.rb +35 -0
  15. data/lib/aker/cas/middleware.rb +6 -0
  16. data/lib/aker/cas/proxy_mode.rb +108 -0
  17. data/lib/aker/cas/rack_proxy_callback.rb +188 -0
  18. data/lib/aker/cas/service_mode.rb +88 -0
  19. data/lib/aker/cas/service_url.rb +62 -0
  20. data/lib/aker/cas/user_ext.rb +64 -0
  21. data/lib/aker/cas.rb +31 -0
  22. data/lib/aker/central_parameters.rb +101 -0
  23. data/lib/aker/configuration.rb +534 -0
  24. data/lib/aker/deprecation.rb +105 -0
  25. data/lib/aker/form/custom_views_mode.rb +80 -0
  26. data/lib/aker/form/login_form_asset_provider.rb +56 -0
  27. data/lib/aker/form/middleware/custom_view_login_responder.rb +19 -0
  28. data/lib/aker/form/middleware/login_renderer.rb +72 -0
  29. data/lib/aker/form/middleware/login_responder.rb +71 -0
  30. data/lib/aker/form/middleware/logout_responder.rb +26 -0
  31. data/lib/aker/form/middleware.rb +10 -0
  32. data/lib/aker/form/mode.rb +118 -0
  33. data/lib/aker/form.rb +26 -0
  34. data/lib/aker/group.rb +67 -0
  35. data/lib/aker/group_membership.rb +162 -0
  36. data/lib/aker/ldap/authority.rb +392 -0
  37. data/lib/aker/ldap/user_ext.rb +19 -0
  38. data/lib/aker/ldap.rb +22 -0
  39. data/lib/aker/modes/base.rb +85 -0
  40. data/lib/aker/modes/http_basic.rb +100 -0
  41. data/lib/aker/modes/support/attempted_path.rb +22 -0
  42. data/lib/aker/modes/support/rfc_2617.rb +32 -0
  43. data/lib/aker/modes/support.rb +12 -0
  44. data/lib/aker/modes.rb +48 -0
  45. data/lib/aker/rack/authenticate.rb +37 -0
  46. data/lib/aker/rack/configuration_helper.rb +18 -0
  47. data/lib/aker/rack/default_logout_responder.rb +36 -0
  48. data/lib/aker/rack/environment_helper.rb +34 -0
  49. data/lib/aker/rack/facade.rb +102 -0
  50. data/lib/aker/rack/failure.rb +69 -0
  51. data/lib/aker/rack/logout.rb +63 -0
  52. data/lib/aker/rack/request_ext.rb +19 -0
  53. data/lib/aker/rack/session_timer.rb +95 -0
  54. data/lib/aker/rack/setup.rb +77 -0
  55. data/lib/aker/rack.rb +107 -0
  56. data/lib/aker/test/helpers.rb +22 -0
  57. data/lib/aker/test.rb +8 -0
  58. data/lib/aker/user.rb +231 -0
  59. data/lib/aker/version.rb +3 -0
  60. data/lib/aker.rb +51 -0
  61. data/spec/aker/aker-sample.yml +11 -0
  62. data/spec/aker/authorities/automatic_access_spec.rb +52 -0
  63. data/spec/aker/authorities/composite_spec.rb +488 -0
  64. data/spec/aker/authorities/nu-schema.jar +0 -0
  65. data/spec/aker/authorities/static_spec.rb +455 -0
  66. data/spec/aker/authorities/support/find_sole_user_spec.rb +33 -0
  67. data/spec/aker/authorities_spec.rb +16 -0
  68. data/spec/aker/cas/authority_spec.rb +106 -0
  69. data/spec/aker/cas/configuration_helper_spec.rb +92 -0
  70. data/spec/aker/cas/middleware/logout_responder_spec.rb +47 -0
  71. data/spec/aker/cas/middleware/ticket_remover_spec.rb +49 -0
  72. data/spec/aker/cas/proxy_mode_spec.rb +185 -0
  73. data/spec/aker/cas/rack_proxy_callback_spec.rb +190 -0
  74. data/spec/aker/cas/service_mode_spec.rb +122 -0
  75. data/spec/aker/cas/service_url_spec.rb +114 -0
  76. data/spec/aker/cas/user_ext_spec.rb +27 -0
  77. data/spec/aker/cas_spec.rb +19 -0
  78. data/spec/aker/central_parameters_spec.rb +44 -0
  79. data/spec/aker/configuration_spec.rb +465 -0
  80. data/spec/aker/deprecation_spec.rb +115 -0
  81. data/spec/aker/form/a_form_mode.rb +129 -0
  82. data/spec/aker/form/custom_views_mode_spec.rb +34 -0
  83. data/spec/aker/form/login_form_asset_provider_spec.rb +80 -0
  84. data/spec/aker/form/middleware/a_form_login_responder.rb +89 -0
  85. data/spec/aker/form/middleware/custom_view_login_responder_spec.rb +47 -0
  86. data/spec/aker/form/middleware/login_renderer_spec.rb +56 -0
  87. data/spec/aker/form/middleware/login_responder_spec.rb +34 -0
  88. data/spec/aker/form/middleware/logout_responder_spec.rb +55 -0
  89. data/spec/aker/form/mode_spec.rb +15 -0
  90. data/spec/aker/form_spec.rb +11 -0
  91. data/spec/aker/group_membership_spec.rb +208 -0
  92. data/spec/aker/group_spec.rb +66 -0
  93. data/spec/aker/ldap/authority_spec.rb +414 -0
  94. data/spec/aker/ldap/ldap-users.ldif +197 -0
  95. data/spec/aker/ldap_spec.rb +11 -0
  96. data/spec/aker/modes/a_aker_mode.rb +41 -0
  97. data/spec/aker/modes/http_basic_spec.rb +127 -0
  98. data/spec/aker/modes/support/attempted_path_spec.rb +32 -0
  99. data/spec/aker/modes_spec.rb +11 -0
  100. data/spec/aker/rack/authenticate_spec.rb +78 -0
  101. data/spec/aker/rack/default_logout_responder_spec.rb +67 -0
  102. data/spec/aker/rack/facade_spec.rb +154 -0
  103. data/spec/aker/rack/failure_spec.rb +151 -0
  104. data/spec/aker/rack/logout_spec.rb +63 -0
  105. data/spec/aker/rack/request_ext_spec.rb +29 -0
  106. data/spec/aker/rack/session_timer_spec.rb +134 -0
  107. data/spec/aker/rack/setup_spec.rb +87 -0
  108. data/spec/aker/rack_spec.rb +216 -0
  109. data/spec/aker/test/helpers_spec.rb +44 -0
  110. data/spec/aker/user_spec.rb +362 -0
  111. data/spec/aker_spec.rb +80 -0
  112. data/spec/deprecation_helper.rb +58 -0
  113. data/spec/java_helper.rb +5 -0
  114. data/spec/logger_helper.rb +17 -0
  115. data/spec/matchers.rb +31 -0
  116. data/spec/mock_builder.rb +25 -0
  117. data/spec/spec_helper.rb +52 -0
  118. metadata +265 -0
@@ -0,0 +1,197 @@
1
+ version: 1
2
+
3
+ # These records were derived from the NU LDAP servers on 2010-10-28.
4
+ # They've been obscured slightly.
5
+
6
+ dn: ou=People, dc=northwestern, dc=edu
7
+ objectClass: top
8
+ objectClass: organizationalUnit
9
+ ou: People
10
+
11
+ dn: uid=sbw, ou=People, dc=northwestern, dc=edu
12
+ objectClass: top
13
+ objectClass: inetOrgPerson
14
+ objectClass: organizationalPerson
15
+ objectClass: person
16
+ cn: b
17
+ cn: b whitaker
18
+ cn: sean
19
+ cn: sean b whitaker
20
+ cn: sean whitaker
21
+ cn: whitaker
22
+ cn: whitaker,sean
23
+ cn: whitaker,sean b
24
+ displayName: Sean B Whitaker
25
+ givenName: Sean
26
+ sn: Whitaker
27
+ uid: sbw
28
+ employeeNumber: 103
29
+ mail: s-whitaker@northwestern.edu
30
+ ou: NU Clinical and Translational Sciences Institute, Feinberg School of Med
31
+ icine
32
+ ou: People
33
+ telephoneNumber: +1 312 555 2310
34
+ title: Project Manager IT
35
+ # Password is 'sean'
36
+ userpassword: {SHA}1+GZMMwfQsLQeB9Nnm8f5Ykb+c8=
37
+
38
+ dn: uid=cbrinson, ou=People, dc=northwestern, dc=edu
39
+ objectClass: top
40
+ objectClass: inetOrgPerson
41
+ objectClass: organizationalPerson
42
+ objectClass: person
43
+ cn: brinson
44
+ cn: brinson,cate
45
+ cn: brinson,kate
46
+ cn: brinson,l catherine
47
+ cn: cate
48
+ cn: cate brinson
49
+ cn: cate kate
50
+ cn: catherine
51
+ cn: kate
52
+ cn: kate brinson
53
+ cn: l
54
+ cn: l catherine
55
+ cn: l catherine brinson
56
+ cn: l catherine cate
57
+ cn: l catherine cate kate brinson
58
+ cn: l catherine kate
59
+ displayName: L Catherine Brinson
60
+ givenName: L Catherine
61
+ sn: Brinson
62
+ uid: cbrinson
63
+ employeeNumber: 100
64
+ facsimileTelephoneNumber: +1 847 555 0540
65
+ mail: cbrinson@northwestern.edu
66
+ ou: McC Mechanical Engineering
67
+ ou: People
68
+ postalAddress: TECH 2145 Sheridan Rd$B226$EV 3111
69
+ telephoneNumber: +1 847 555 2347
70
+ title: Professor
71
+ title: Chairperson
72
+ # Password is 'cate'
73
+ userpassword: {SHA}9MmlgfQ7prbm5Zyjotth2/pu4ks=
74
+
75
+ dn: uid=wakibbe, ou=People, dc=northwestern, dc=edu
76
+ objectClass: top
77
+ objectClass: inetOrgPerson
78
+ objectClass: organizationalPerson
79
+ objectClass: person
80
+ cn: a
81
+ cn: a kibbe
82
+ cn: kibbe
83
+ cn: kibbe,wak
84
+ cn: kibbe,warren
85
+ cn: kibbe,warren a
86
+ cn: wak
87
+ cn: wak kibbe
88
+ cn: warren
89
+ cn: warren a kibbe
90
+ cn: warren a wak
91
+ cn: warren a wak kibbe
92
+ cn: warren kibbe
93
+ displayName: Warren A Kibbe
94
+ givenName: Warren
95
+ sn: Kibbe
96
+ uid: wakibbe
97
+ employeeNumber: 101
98
+ mail: wakibbe@northwestern.edu
99
+ ou: NU Clinical and Translational Sciences Institute, Feinberg School of Med
100
+ icine
101
+ ou: Center for Genetic Medicine, Feinberg School of Medicine
102
+ ou: People
103
+ postalAddress: RUBLOFF 750 N Lake Shore Dr$11th Floor$CH
104
+ telephoneNumber: +1 312 555 3229
105
+ title: Research Associate Professor
106
+ # Password is 'warren'
107
+ userpassword: {SHA}VV0B3Wo8+hIFksgRljY3LtlRWOQ=
108
+
109
+ dn: uid=rms, ou=People, dc=northwestern, dc=edu
110
+ objectClass: top
111
+ objectClass: inetOrgPerson
112
+ objectClass: organizationalPerson
113
+ objectClass: person
114
+ cn: m
115
+ cn: m sutphin
116
+ cn: rhett
117
+ cn: rhett m sutphin
118
+ cn: rhett sutphin
119
+ cn: sutphin
120
+ cn: sutphin,rhett
121
+ cn: sutphin,rhett m
122
+ displayName: Rhett M Sutphin
123
+ givenName: Rhett
124
+ sn: Sutphin
125
+ uid: rms377
126
+ employeeNumber: 105
127
+ mail: r-sutphin@northwestern.edu
128
+ ou: NU Clinical and Translational Sciences Institute, Feinberg School of Med
129
+ icine
130
+ ou: People
131
+ telephoneNumber: +1 312 555 2324
132
+ title: Systems Analyst/Programmer Senior
133
+ # Password is 'rhett'
134
+ userpassword: {SHA}0iimqqf1K2J9byT/Y60bE1o9vSE=
135
+
136
+ dn: uid=ega, ou=People, dc=northwestern, dc=edu
137
+ objectClass: top
138
+ objectClass: person
139
+ objectClass: organizationalPerson
140
+ objectClass: inetOrgPerson
141
+ cn: edgar
142
+ cn: edgar garcia
143
+ cn: garcia
144
+ cn: garcia,edgar
145
+ displayName: Edgar Garcia
146
+ givenName: Edgar
147
+ sn: Garcia
148
+ uid: ega
149
+ employeeNumber: 106
150
+ mail: edgar-garcia@northwestern.edu
151
+ ou: Lurie Cancer Center, Feinberg School of Medicine
152
+ ou: People
153
+ postalAddress: RUBLOFF 750 N Lake Shore Drive$11th Floor$CH
154
+ telephoneNumber: +1 312 555 2389
155
+ # Password is 'edgar'
156
+ userpassword: {SHA}njIw/etsfKsBVDVrwOcpTMvqKDE=
157
+
158
+ dn: uid=blc, ou=People, dc=northwestern, dc=edu
159
+ objectClass: top
160
+ objectClass: person
161
+ objectClass: organizationalPerson
162
+ objectClass: inetOrgPerson
163
+ cn: brian
164
+ cn: brian chamberlain
165
+ cn: brian lee chamberlain
166
+ cn: chamberlain
167
+ cn: chamberlain,brian
168
+ cn: chamberlain,brian lee
169
+ cn: lee
170
+ cn: lee chamberlain
171
+ displayName: Brian Lee Chamberlain
172
+ givenName: Brian
173
+ sn: Chamberlain
174
+ uid: blc
175
+ employeeNumber: 107
176
+ mail: b-chamberlain@northwestern.edu
177
+ ou: NU Clinical and Translational Sciences Institute, Feinberg School of Med
178
+ icine
179
+ ou: People
180
+ postalAddress: RUBLOFF 750 N Lake Shore Dr$11th Floor$CH
181
+ # Password is 'brian'
182
+ userpassword: {SHA}dg59qyg2hTxjgFAz5RRmgwH6nEc=
183
+
184
+ # User with bad sn/givenName
185
+ dn: uid=jka, ou=People, dc=northwestern, dc=edu
186
+ objectClass: top
187
+ objectClass: person
188
+ objectClass: organizationalPerson
189
+ objectClass: inetOrgPerson
190
+ cn: Jennifer Karp
191
+ cn: Jennifer
192
+ cn: Karp
193
+ displayName: Jennifer Karp
194
+ givenName: UNKNOWN
195
+ sn: UNKNOWN
196
+ uid: jka
197
+ ou: People
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Aker
4
+ describe Ldap::Slice do
5
+ let(:configuration) { Aker::Configuration.new(:slices => [Ldap::Slice.new]) }
6
+
7
+ it 'registers :ldap as an alias for the LDAP authority' do
8
+ configuration.authority_aliases[:ldap].should be Aker::Ldap::Authority
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ require File.expand_path("../../../spec_helper", __FILE__)
2
+ require 'warden'
3
+
4
+ ##
5
+ # Expects the following instance variables to be set:
6
+ #
7
+ # * @mode: an instance of the mode under test
8
+ # * @env: a Rack environment used by the mode
9
+ shared_examples_for "a aker mode" do
10
+ it "is a Warden strategy" do
11
+ (@mode.class < Warden::Strategies::Base).should be_true
12
+ end
13
+
14
+ describe '#interactive?' do
15
+ it "is true if 'aker.interactive' is true" do
16
+ @env['aker.interactive'] = true
17
+
18
+ @mode.interactive?.should == true
19
+ end
20
+
21
+ it "is false if 'aker.interactive' is false" do
22
+ @env['aker.interactive'] = false
23
+
24
+ @mode.interactive?.should == false
25
+ end
26
+ end
27
+
28
+ describe '#store?' do
29
+ it 'is true if #interactive? is true' do
30
+ @mode.stub!(:interactive? => true)
31
+
32
+ @mode.store?.should == true
33
+ end
34
+
35
+ it 'is false if #interactive? is false' do
36
+ @mode.stub!(:interactive? => false)
37
+
38
+ @mode.store?.should == false
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,127 @@
1
+ require File.expand_path("../../../spec_helper", __FILE__)
2
+ require File.expand_path("a_aker_mode", File.dirname(__FILE__))
3
+ require 'base64'
4
+ require 'rack'
5
+
6
+ module Aker::Modes
7
+ describe HttpBasic do
8
+ before do
9
+ @env = ::Rack::MockRequest.env_for("/")
10
+ @scope = mock
11
+ @mode = HttpBasic.new(@env, @scope)
12
+ @env['aker.configuration'] = Aker::Configuration.new
13
+ end
14
+
15
+ it_should_behave_like "a aker mode"
16
+
17
+ describe "#key" do
18
+ it "is :http_basic" do
19
+ HttpBasic.key.should == :http_basic
20
+ end
21
+ end
22
+
23
+ describe "#kind" do
24
+ it "is :user" do
25
+ @mode.kind.should == :user
26
+ end
27
+ end
28
+
29
+ describe "#credentials" do
30
+ it "returns username and password given an Authorization header" do
31
+ @env["HTTP_AUTHORIZATION"] = "Basic " + Base64.encode64("foo:bar")
32
+
33
+ @mode.credentials.should == ["foo", "bar"]
34
+ end
35
+
36
+ it "returns an empty array when no Authorization header is present" do
37
+ @mode.credentials.should == []
38
+ end
39
+
40
+ it "returns an empty array when the Authorization header isn't a valid response to a Basic challenge" do
41
+ @env["HTTP_AUTHORIZATION"] = "garbage"
42
+
43
+ @mode.credentials.should == []
44
+ end
45
+ end
46
+
47
+ describe "#valid?" do
48
+ it "is not valid if the Authorization header is blank" do
49
+ @mode.should_not be_valid
50
+ end
51
+
52
+ it "is not valid if the Authorization header does not contain 'Basic'" do
53
+ @env["HTTP_AUTHORIZATION"] = "Fake auth"
54
+
55
+ @mode.should_not be_valid
56
+ end
57
+
58
+ it "is not valid if the Authorization header contains malformed credentials" do
59
+ @env["HTTP_AUTHORIZATION"] = "Basic :?$"
60
+
61
+ @mode.should_not be_valid
62
+ end
63
+
64
+ it "is valid if the Authorization header contains 'Basic' followed by base64-encoded credentials" do
65
+ credentials = Base64.encode64("foo:bar")
66
+ @env["HTTP_AUTHORIZATION"] = "Basic #{credentials}"
67
+
68
+ @mode.should be_valid
69
+ end
70
+ end
71
+
72
+ describe "#authenticate!" do
73
+ before do
74
+ @authority = mock
75
+ @env['aker.authority'] = @authority
76
+ end
77
+
78
+ it "signals success if the username and password are good" do
79
+ @env["HTTP_AUTHORIZATION"] = "Basic " + Base64.encode64("foo:bar")
80
+ user = stub
81
+ @authority.should_receive(:valid_credentials?).with(:user, 'foo', 'bar').and_return(user)
82
+ @mode.should_receive(:success!).with(user)
83
+
84
+ @mode.authenticate!
85
+ end
86
+
87
+ it "does not signal success if the username or password are bad" do
88
+ @authority.stub(:valid_credentials? => nil)
89
+ @mode.should_not_receive(:success!)
90
+
91
+ @mode.authenticate!
92
+ end
93
+ end
94
+
95
+ describe "#realm" do
96
+ it "prefers the portal attribute of the configuration" do
97
+ @env['aker.configuration'].portal = "Realm"
98
+
99
+ @mode.realm.should == "Realm"
100
+ end
101
+
102
+ it "defaults to 'Aker'" do
103
+ @mode.realm.should == "Aker"
104
+ end
105
+ end
106
+
107
+ describe "#scheme" do
108
+ it "is Basic" do
109
+ @mode.scheme.should == "Basic"
110
+ end
111
+ end
112
+
113
+ describe "#on_ui_failure" do
114
+ before do
115
+ @response = @mode.on_ui_failure
116
+ end
117
+
118
+ it "returns 401 Unauthorized" do
119
+ @response.status.should == 401
120
+ end
121
+
122
+ it "returns a WWW-Authenticate header containing the Basic authentication scheme" do
123
+ @response.headers['WWW-Authenticate'].should == %q{Basic realm="Aker"}
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path("../../../../spec_helper", __FILE__)
2
+
3
+ module Aker::Modes::Support
4
+ describe AttemptedPath do
5
+ before do
6
+ @object = Object.new
7
+ @object.extend(AttemptedPath)
8
+ @env = {}
9
+ @object.stub!(:env => @env)
10
+ end
11
+
12
+ describe "#attempted_path" do
13
+ it "returns the value of :attempted_path in warden.options" do
14
+ @env["warden.options"] = {
15
+ :attempted_path => "http://www.example.edu"
16
+ }
17
+
18
+ @object.attempted_path.should == "http://www.example.edu"
19
+ end
20
+
21
+ it "returns nil if :attempted_path is nil" do
22
+ @env["warden.options"] = {}
23
+
24
+ @object.attempted_path.should be_nil
25
+ end
26
+
27
+ it "returns nil if warden.options is not in the Rack environment" do
28
+ @object.attempted_path.should be_nil
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Aker
4
+ describe Modes::Slice do
5
+ let(:configuration) { Configuration.new(:slices => [Modes::Slice.new]) }
6
+
7
+ it "registers the basic mode" do
8
+ configuration.registered_modes.should include(Aker::Modes::HttpBasic)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ module Aker::Rack
4
+ describe Authenticate do
5
+ let(:app) { lambda { |x| x } }
6
+
7
+ let(:configuration) do
8
+ Aker::Configuration.new do
9
+ ui_mode :cas
10
+ api_modes :basic, :cas_proxy
11
+ end
12
+ end
13
+
14
+ let(:middleware) { Aker::Rack::Authenticate.new(app) }
15
+
16
+ let(:env) do
17
+ { "aker.configuration" => configuration, "warden" => warden }
18
+ end
19
+
20
+ let(:warden) { mock }
21
+
22
+ def call
23
+ middleware.call(env)
24
+ end
25
+
26
+ describe "#call" do
27
+ before do
28
+ warden.stub!(:user)
29
+ end
30
+
31
+ it "calls the ui mode if interactive" do
32
+ env['aker.interactive'] = true
33
+
34
+ warden.should_receive(:authenticate).with(:cas)
35
+
36
+ call
37
+ end
38
+
39
+ it "calls all the api modes if not interactive" do
40
+ env['aker.interactive'] = false
41
+
42
+ warden.should_receive(:authenticate).with(:basic, :cas_proxy)
43
+
44
+ call
45
+ end
46
+
47
+ it "invokes the app" do
48
+ warden.stub!(:authenticate)
49
+
50
+ app.should_receive(:call)
51
+
52
+ call
53
+ end
54
+ end
55
+
56
+ describe "env['aker.check']" do
57
+ let(:user) { Aker::User.new("jo") }
58
+
59
+ before do
60
+ warden.stub!(:user => user, :authenticate => nil)
61
+ end
62
+
63
+ let(:facade) { call['aker.check'] }
64
+
65
+ it "is a facade" do
66
+ facade.should be_a(Facade)
67
+ end
68
+
69
+ it "has the user" do
70
+ facade.user.should == user
71
+ end
72
+
73
+ it "has the configuration" do
74
+ facade.configuration.should == configuration
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,67 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ require 'rack/test'
4
+
5
+ module Aker::Rack
6
+ describe DefaultLogoutResponder do
7
+ include Rack::Test::Methods
8
+
9
+ let(:app) do
10
+ Rack::Builder.new do
11
+ use DefaultLogoutResponder
12
+ run lambda { |env|
13
+ if env['PATH_INFO'] == '/missing/logout'
14
+ [404, {'Content-Type' => 'text/html'}, ['missing']]
15
+ elsif env['PATH_INFO'] == '/present/logout'
16
+ [200, {'Content-Type' => 'text/html'}, ['app logout']]
17
+ else
18
+ [200, {'Content-Type' => 'text/html'}, ['app']]
19
+ end
20
+ }
21
+ end
22
+ end
23
+
24
+ let(:configuration) do
25
+ p = path
26
+ Aker::Configuration.new {
27
+ rack_parameters :logout_path => p
28
+ }
29
+ end
30
+
31
+ let(:env) do
32
+ { 'aker.configuration' => configuration }
33
+ end
34
+
35
+ let(:path) { '/missing/logout' }
36
+
37
+ describe '#call' do
38
+ it 'responds to GET {the configured logout path} if the application 404s' do
39
+ get path, {}, env
40
+
41
+ last_response.status.should == 200
42
+ last_response.body.should == "You have been logged out."
43
+ end
44
+
45
+ it "leaves the application's logout response alone if there is one" do
46
+ configuration.parameters_for(:rack)[:logout_path] = '/present/logout'
47
+
48
+ get '/present/logout', {}, env
49
+
50
+ last_response.status.should == 200
51
+ last_response.body.should == "app logout"
52
+ end
53
+
54
+ it 'does not respond to other methods' do
55
+ post path, {}, env
56
+
57
+ last_response.body.should == 'missing'
58
+ end
59
+
60
+ it 'does not respond to other paths' do
61
+ get '/', {}, env
62
+
63
+ last_response.body.should == 'app'
64
+ end
65
+ end
66
+ end
67
+ end