aker 3.0.0.pre

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.
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,27 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ module Aker::Cas
4
+ describe UserExt do
5
+ let(:user) { Aker::User.new("jo") }
6
+
7
+ before do
8
+ user.extend(UserExt)
9
+ end
10
+
11
+ describe "#cas_proxy_ticket" do
12
+ let(:pgt) { "PGT-1foo" }
13
+ let(:service) { "https://example.org/service-a" }
14
+
15
+ before do
16
+ user.pgt = 'PGT-1foo'
17
+ end
18
+
19
+ it "allows you to request proxy tickets" do
20
+ user.should_receive(:issue_proxy_ticket).with(pgt, service).
21
+ once.and_return(stub(:ticket => "PT-ABC"))
22
+
23
+ user.cas_proxy_ticket("https://example.org/service-a").should == "PT-ABC"
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Aker
4
+ describe Cas::Slice do
5
+ let(:configuration) { Configuration.new(:slices => [Cas::Slice.new]) }
6
+
7
+ it "registers the cas authority" do
8
+ configuration.authority_aliases[:cas].should be Aker::Cas::Authority
9
+ end
10
+
11
+ it 'registers the cas interactive mode' do
12
+ configuration.registered_modes.should include(Aker::Cas::ServiceMode)
13
+ end
14
+
15
+ it 'registers the cas proxy mode' do
16
+ configuration.registered_modes.should include(Aker::Cas::ProxyMode)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ require 'aker/central_parameters'
4
+
5
+ module Aker
6
+ describe CentralParameters do
7
+ describe "creating from a YAML file" do
8
+ before do
9
+ @actual = CentralParameters.new(File.expand_path("../aker-sample.yml", __FILE__))
10
+ end
11
+
12
+ it "loads new keys" do
13
+ @actual[:netid][:user].should == "cn=foo"
14
+ end
15
+
16
+ it "loads top-level keys that aren't in the default set" do
17
+ @actual[:foo][:bar].should == 'baz'
18
+ end
19
+ end
20
+
21
+ describe "creating from a hash" do
22
+ before do
23
+ @source = {
24
+ :cc_pers => { :user => 'cc_pers_bar', :password => 'secret' },
25
+ :foo => { :bar => 'baz' }
26
+ }
27
+ @actual = CentralParameters.new(@source)
28
+ end
29
+
30
+ it "loads new keys" do
31
+ @actual[:cc_pers][:password].should == 'secret'
32
+ end
33
+
34
+ it "loads top-level keys that aren't in the default set" do
35
+ @actual[:foo][:bar].should == 'baz'
36
+ end
37
+
38
+ it "does not reflect changes to the source hash" do
39
+ @source[:cc_pers][:user] = 'cc_pers_etc'
40
+ @actual[:cc_pers][:user].should == 'cc_pers_bar'
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,465 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ describe Aker::Configuration do
4
+ before do
5
+ @config = blank_config
6
+ end
7
+
8
+ def config_from(options={}, &block)
9
+ Aker::Configuration.new(options, &block)
10
+ end
11
+
12
+ def blank_config
13
+ Aker::Configuration.new
14
+ end
15
+
16
+ describe "authorities" do
17
+ it "requires at least one" do
18
+ lambda { blank_config.authorities }.should raise_error("No authorities configured")
19
+ end
20
+
21
+ it "can be safely accessed if empty" do
22
+ blank_config.authorities?.should be_false
23
+ end
24
+ end
25
+
26
+ describe "portal" do
27
+ it "must be set" do
28
+ lambda { @config.portal }.should raise_error("No portal configured")
29
+ end
30
+
31
+ it "is always a symbol" do
32
+ @config.portal = "foo"
33
+ @config.portal.should == :foo
34
+ end
35
+
36
+ it "can be safely accessed if nil" do
37
+ @config.portal?.should be_false
38
+ end
39
+ end
40
+
41
+ describe "ui_mode" do
42
+ it "defaults to :form" do
43
+ @config.ui_mode.should == :form
44
+ end
45
+
46
+ it "is always a symbol" do
47
+ @config.ui_mode = "foo"
48
+ @config.ui_mode.should == :foo
49
+ end
50
+ end
51
+
52
+ describe "api_modes" do
53
+ it "defaults to an empty list" do
54
+ @config.api_modes.should == []
55
+ end
56
+
57
+ it "is always a list of symbols" do
58
+ @config.api_modes = %w(a b c)
59
+ @config.api_modes.should == [:a, :b, :c]
60
+ end
61
+
62
+ it "rejects one nil mode" do
63
+ @config.api_modes = nil
64
+ @config.api_modes.should be_empty
65
+ end
66
+
67
+ it "removes the nil modes from a list" do
68
+ @config.api_modes = [:a, nil, :c, nil, nil]
69
+ @config.api_modes.should == [:a, :c]
70
+ end
71
+ end
72
+
73
+ describe "#register_mode" do
74
+ class Aker::Spec::SomeMode < Aker::Modes::Base
75
+ def self.key
76
+ :some
77
+ end
78
+ end
79
+
80
+ let(:config) { Aker::Configuration.new(:slices => []) }
81
+
82
+ it 'registers the mode' do
83
+ config.register_mode Aker::Spec::SomeMode
84
+
85
+ config.registered_modes.should == [Aker::Spec::SomeMode]
86
+ end
87
+
88
+ it 'rejects objects that do not have keys' do
89
+ lambda { config.register_mode "No key here" }.
90
+ should raise_error(/"No key here" is not usable as a Aker mode/)
91
+ end
92
+ end
93
+
94
+ describe '#alias_authority' do
95
+ let(:new_auth) { Object.new }
96
+
97
+ it 'registers the alias' do
98
+ @config.alias_authority :some, new_auth
99
+ @config.authority_aliases[:some].should be new_auth
100
+ end
101
+
102
+ it 'registers a string alias as a symbol' do
103
+ @config.alias_authority 'some', new_auth
104
+ @config.authority_aliases[:some].should be new_auth
105
+ end
106
+ end
107
+
108
+ describe 'global middleware installers' do
109
+ let(:config) { Aker::Configuration.new(:slices => []) }
110
+
111
+ describe '#register_middleware_installer' do
112
+ [:before_authentication, :after_authentication].each do |k|
113
+ it "accepts the #{k.inspect} key" do
114
+ config.register_middleware_installer(k) { 'foo' }
115
+ config.middleware_installers[k].first.call.should == 'foo'
116
+ end
117
+ end
118
+
119
+ it 'rejects an unknown key' do
120
+ lambda { config.register_middleware_installer(:in_the_middle) { 'bar' } }.
121
+ should raise_error(/Unsupported middleware location :in_the_middle./)
122
+ end
123
+ end
124
+
125
+ describe '#install_middleware' do
126
+ let(:builder) { mock(Rack::Builder) }
127
+
128
+ before do
129
+ config.enhance {
130
+ before_authentication_middleware do |b|
131
+ b.use "Before!"
132
+ end
133
+ after_authentication_middleware do |b|
134
+ b.use "After!"
135
+ end
136
+ }
137
+ end
138
+
139
+ it 'installs before middleware for :before_authentication' do
140
+ builder.should_receive(:use).once.with("Before!")
141
+ config.install_middleware(:before_authentication, builder)
142
+ end
143
+
144
+ it 'installs after middleware for :after_authentication' do
145
+ builder.should_receive(:use).once.with("After!")
146
+ config.install_middleware(:after_authentication, builder)
147
+ end
148
+
149
+ it 'does nothing if there is no middleware of the specified type' do
150
+ config.middleware_installers.clear
151
+ builder.should_not_receive(:use)
152
+ lambda { config.install_middleware(:before_authentication, builder) }.
153
+ should_not raise_error
154
+ end
155
+
156
+ it 'fails for an unknown key' do
157
+ lambda { config.install_middleware(:in_the_sky, builder) }.
158
+ should raise_error(/Unsupported middleware location :in_the_sky./)
159
+ end
160
+ end
161
+ end
162
+
163
+ describe 'slices' do
164
+ let(:a_slice) { Aker::Configuration::Slice.new { portal 'from_slice' } }
165
+
166
+ before do
167
+ @original_slices = Aker::Configuration.default_slices.dup
168
+ Aker::Configuration.default_slices.clear
169
+ end
170
+
171
+ after do
172
+ Aker::Configuration.default_slices.clear
173
+ Aker::Configuration.default_slices.concat(@original_slices)
174
+ end
175
+
176
+ describe 'and initialization' do
177
+ before do
178
+ Aker::Configuration.add_default_slice a_slice
179
+ end
180
+
181
+ context 'without explicit slices' do
182
+ it 'applies the default slices' do
183
+ blank_config.portal.should == :from_slice
184
+ end
185
+
186
+ it 'applies any additional configuration after the default slices' do
187
+ config_from { portal 'from_block' }.portal.should == :from_block
188
+ end
189
+ end
190
+
191
+ context 'with explicit slices' do
192
+ let(:config) do
193
+ Aker::Configuration.new(:slices => [
194
+ Aker::Configuration::Slice.new { ui_mode :form },
195
+ Aker::Configuration::Slice.new { api_mode :http_basic }
196
+ ]
197
+ ) do
198
+ api_mode :cas_proxy
199
+ end
200
+ end
201
+
202
+ it 'applies the explicit slices' do
203
+ config.ui_mode.should == :form
204
+ end
205
+
206
+ it 'does not apply the default slices' do
207
+ config.portal?.should be_false
208
+ end
209
+
210
+ it 'applies any additional configuration after the explicit slices' do
211
+ config.api_modes.should == [:cas_proxy]
212
+ end
213
+ end
214
+ end
215
+
216
+ describe '.add_default_slice' do
217
+ it 'can add a slice from a slice instance' do
218
+ Aker::Configuration.add_default_slice(a_slice)
219
+
220
+ Aker::Configuration.default_slices.should == [ a_slice ]
221
+ end
222
+
223
+ it 'can add a slice from a block' do
224
+ Aker::Configuration.add_default_slice {
225
+ portal 'from_default'
226
+ }
227
+
228
+ Aker::Configuration.default_slices.first.should be_a Aker::Configuration::Slice
229
+ end
230
+ end
231
+ end
232
+
233
+ describe "#logger" do
234
+ before do
235
+ @captured_stderr = StringIO.new
236
+ @real_stderr, $stderr = $stderr, @captured_stderr
237
+ end
238
+
239
+ after do
240
+ $stderr = @real_stderr
241
+ end
242
+
243
+ it "defaults to something that prints to stderr" do
244
+ @config.logger.info("Hello, world")
245
+
246
+ @captured_stderr.string.should =~ /Hello, world/
247
+ end
248
+
249
+ it "can be set" do
250
+ lambda { @config.logger = Logger.new(STDOUT) }.should_not raise_error
251
+ end
252
+ end
253
+
254
+ describe "DSL" do
255
+ describe "for basic attributes" do
256
+ it "can set the portal" do
257
+ config_from { portal :ENU }.portal.should == :ENU
258
+ end
259
+
260
+ it "can set the UI mode" do
261
+ config_from { ui_mode :cas }.ui_mode.should == :cas
262
+ end
263
+
264
+ it "can set one API mode" do
265
+ config_from { api_mode :basic }.api_modes.should == [:basic]
266
+ end
267
+
268
+ it "can set several API modes" do
269
+ config_from { api_modes :basic, :api_key }.api_modes.should == [:basic, :api_key]
270
+ end
271
+ end
272
+
273
+ describe "for additional authority parameters" do
274
+ it "can set parameters for arbitrary groups" do
275
+ config_from { foo_parameters :server => "test.local" }.
276
+ parameters_for(:foo)[:server].should == "test.local"
277
+ end
278
+
279
+ it "can set (and name) one parameter at a time" do
280
+ config_from { foo_parameter :server => "test.bar" }.
281
+ parameters_for(:foo)[:server].should == "test.bar"
282
+ end
283
+
284
+ it "combines parameters from multiple calls" do
285
+ start = config_from { netid_parameters :server => "ldap.foo.edu" }
286
+ start.enhance { netid_parameters :username => "arb" }
287
+ start.parameters_for(:netid)[:server].should == "ldap.foo.edu"
288
+ start.parameters_for(:netid)[:username].should == "arb"
289
+ end
290
+
291
+ it 'combines arbitrarily nested hashes' do
292
+ c = config_from { foo_parameters :bar => { :a => { :one => 1 } } }
293
+ c.enhance { foo_parameters :bar => { :a => { :two => 2 }, :b => { :one => 4 } } }
294
+
295
+ c.parameters_for(:foo)[:bar][:a].should == { :one => 1, :two => 2 }
296
+ c.parameters_for(:foo)[:bar][:b].should == { :one => 4 }
297
+ end
298
+
299
+ it 'respects values set to nil when combining' do
300
+ c = config_from { foo_parameters :bar => :quux }
301
+ c.parameters_for(:foo)[:bar].should == :quux
302
+
303
+ c.enhance { foo_parameters :bar => nil }
304
+ c.parameters_for(:foo)[:bar].should be_nil
305
+ end
306
+
307
+ it 'respects values set to nil when deeply combining' do
308
+ c = config_from { foo_parameters :bar => { :a => { :two => 2 } } }
309
+ c.parameters_for(:foo)[:bar][:a][:two].should == 2
310
+
311
+ c.enhance { foo_parameters :bar => { :a => { :two => nil } } }
312
+ c.parameters_for(:foo)[:bar][:a][:two].should be_nil
313
+ end
314
+ end
315
+
316
+ describe "for authorities" do
317
+ def only_static_config(&block)
318
+ Aker::Configuration.new(
319
+ :slices => [Aker::Configuration::Slice.new {
320
+ alias_authority :static, Aker::Authorities::Static
321
+ }], &block)
322
+ end
323
+
324
+ it "can configure an authority from an alias symbol" do
325
+ only_static_config { authority :static }.
326
+ authorities.first.class.should == Aker::Authorities::Static
327
+ end
328
+
329
+ it "can configure an authority from an alias string" do
330
+ only_static_config { authority "static" }.authorities.first.class.
331
+ should == Aker::Authorities::Static
332
+ end
333
+
334
+ it 'can configure an authority from an alias to an alias' do
335
+ only_static_config {
336
+ alias_authority :moq, :static
337
+ authority :moq
338
+ }.authorities.first.should be_a Aker::Authorities::Static
339
+ end
340
+
341
+ it 'fails with a useful message with an unregistered alias' do
342
+ lambda {
343
+ only_static_config { authority :cas }
344
+ }.should raise_error(/Unknown authority alias :cas./)
345
+ end
346
+
347
+ it "can configure an authority from a class" do
348
+ only_static_config { authority Aker::Authorities::Static }.authorities.first.class.
349
+ should == Aker::Authorities::Static
350
+ end
351
+
352
+ it "can configure an authority from an instance" do
353
+ expected = Object.new
354
+ only_static_config { authority expected }.authorities.first.should be expected
355
+ end
356
+
357
+ it "it passes the configuration to an instantiated authority" do
358
+ actual = only_static_config { authority Struct.new(:config) }
359
+ actual.authorities.first.config.should be actual
360
+ end
361
+
362
+ it "defers instantiating the authorities until the configuration is complete" do
363
+ only_static_config {
364
+ portal :foo
365
+
366
+ authority Class.new {
367
+ attr_reader :initial_portal
368
+
369
+ def initialize(config)
370
+ @initial_portal = config.portal
371
+ end
372
+ }
373
+
374
+ portal :bar
375
+ }.authorities.first.initial_portal.should == :bar
376
+ end
377
+ end
378
+
379
+ describe "this" do
380
+ let(:config) { config_from { foo_parameters :this => this } }
381
+
382
+ it 'refers to the configuration being updated itself' do
383
+ config.parameters_for(:foo)[:this].should be config
384
+ end
385
+ end
386
+
387
+ describe "central parameters" do
388
+ before do
389
+ @actual = config_from { central File.expand_path("../aker-sample.yml", __FILE__) }
390
+ end
391
+
392
+ it "acquires the netid parameters" do
393
+ @actual.parameters_for(:netid)[:user].should == "cn=foo"
394
+ end
395
+
396
+ it "acquires the cc_pers parameters" do
397
+ @actual.parameters_for(:cc_pers)[:user].should == "cc_pers_foo"
398
+ end
399
+
400
+ it "acquires the cas parameters" do
401
+ @actual.parameters_for(:cas)[:base_url].should == "https://cas.example.edu"
402
+ @actual.parameters_for(:cas)[:proxy_retrieval_url].
403
+ should == "https://cas.example.edu/retrieve_pgt"
404
+ @actual.parameters_for(:cas)[:proxy_callback_url].
405
+ should == "https://cas.example.edu/receive_pgt"
406
+ end
407
+
408
+ it "acquires all top-level parameters" do
409
+ @actual.parameters_for(:foo)[:bar].should == "baz"
410
+ end
411
+ end
412
+
413
+ describe 'middleware' do
414
+ context 'before_authentication_middleware' do
415
+ it 'registers under the :before_authentication key' do
416
+ config_from { before_authentication_middleware { 'foob' } }.
417
+ middleware_installers[:before_authentication].last.call(nil).should == 'foob'
418
+ end
419
+ end
420
+
421
+ context 'after_authentication_middleware' do
422
+ it 'registers under the :after_authentication key' do
423
+ config_from { after_authentication_middleware { 'fooa' } }.
424
+ middleware_installers[:after_authentication].last.call(nil).should == 'fooa'
425
+ end
426
+ end
427
+ end
428
+ end
429
+
430
+ describe "#enhance" do
431
+ it "preserves previous configuration properties" do
432
+ config_from { ui_mode :form }.enhance { portal :NOTIS }.ui_mode.should == :form
433
+ end
434
+
435
+ it "sets new configuration properties" do
436
+ config_from { ui_mode :form }.enhance { portal :NOTIS }.portal.should == :NOTIS
437
+ end
438
+
439
+ it "overrides repeated configuration properties" do
440
+ config_from { portal :NOTIS }.enhance { portal :eNOTIS }.portal.should == :eNOTIS
441
+ end
442
+ end
443
+
444
+ describe "#composite_authority" do
445
+ it "returns a composite authority for the configured authorities" do
446
+ config_from { authorities :static, :static }.composite_authority.authorities.size.should == 2
447
+ end
448
+ end
449
+ end
450
+
451
+ class Aker::Configuration
452
+ describe Slice do
453
+ subject { Slice.new { array << 2 } }
454
+ let(:array) { [1] }
455
+
456
+ it 'saves the provided block' do
457
+ subject.contents.should be_a Proc
458
+ end
459
+
460
+ it 'is possible to evaluate the block later' do
461
+ subject.contents.call
462
+ array.should == [1, 2]
463
+ end
464
+ end
465
+ end
@@ -0,0 +1,115 @@
1
+ require File.expand_path("../../spec_helper", __FILE__)
2
+
3
+ require 'rational'
4
+
5
+ module Aker
6
+ describe Deprecation do
7
+ # adds a level of indirection so that we can test that
8
+ # notifications are reported on the caller of the method
9
+ # that calls notify.
10
+ def indirect_notify(*args)
11
+ Deprecation.notify(*args)
12
+ end
13
+
14
+ describe "for a future version" do
15
+ before do
16
+ indirect_notify("app_name is deprecated.", "7.8")
17
+ end
18
+
19
+ it "reports a deprecation warning" do
20
+ Deprecation.mode.messages.first[:message].should ==
21
+ "DEPRECATION WARNING: app_name is deprecated. " <<
22
+ "It will be removed from aker in version 7.8 or later. " <<
23
+ "(Called from deprecation_spec.rb:#{__LINE__ - 7}.)"
24
+ end
25
+
26
+ it "reports it as deprecated" do
27
+ Deprecation.mode.messages.first[:level].should == :deprecated
28
+ end
29
+ end
30
+
31
+ describe "for a past version" do
32
+ after do
33
+ Deprecation.mode.reset # prevent the very-obsolete spec failure
34
+ end
35
+
36
+ before do
37
+ indirect_notify("use_cas is deprecated. Please replace it with frob.", "1.7")
38
+ end
39
+
40
+ it "builds a useful message from the parameters" do
41
+ Deprecation.mode.messages.first[:message].should ==
42
+ "OBSOLETE API USED: use_cas is deprecated. Please replace it with frob. " <<
43
+ "It is no longer functional as of aker 1.7 " <<
44
+ "and could be removed in any future version. " <<
45
+ "(Called from deprecation_spec.rb:#{__LINE__ - 8}.)"
46
+ end
47
+
48
+ it "reports it as obsolete" do
49
+ Deprecation.mode.messages.first[:level].should == :obsolete
50
+ end
51
+ end
52
+
53
+ describe "for the current version" do
54
+ before do
55
+ indirect_notify("something is deprecated right now", Aker::VERSION)
56
+ end
57
+
58
+ it "reports it as obsolete" do
59
+ Deprecation.mode.messages.first[:level].should == :obsolete
60
+ end
61
+ end
62
+
63
+ describe "in test mode" do
64
+ # ... which is installed in spec_helper
65
+
66
+ after do
67
+ Deprecation.mode.reset # prevent the very-obsolete spec failure
68
+ end
69
+
70
+ it "does not raise an error for a slightly obsolete version" do
71
+ one_minor_back = Aker::VERSION.split('.').collect(&:to_i).tap { |v|
72
+ v[0,2] = ("%.1f" % (Rational(v[0] * 10 + v[1], 10) - Rational(1, 10))).split('.')
73
+ }.join(".")
74
+ indirect_notify("not too old", one_minor_back)
75
+ lambda { Deprecation.mode.fail_if_any_very_obsolete }.should_not raise_error
76
+ end
77
+
78
+ it "registers a spec failure for a very obsolete version" do
79
+ indirect_notify("particularly old", "1.0")
80
+ lambda { Deprecation.mode.fail_if_any_very_obsolete }.
81
+ should raise_error(RuntimeError, /OBSOLETE.*particularly old/)
82
+ end
83
+ end
84
+
85
+ describe "default mode" do
86
+ before do
87
+ @test_mode, Deprecation.mode = Deprecation.mode, nil
88
+ @err = StringIO.new
89
+ @old_err, $stderr = $stderr, @err
90
+ end
91
+
92
+ after do
93
+ Deprecation.mode = @test_mode
94
+ $stderr = @old_err
95
+ end
96
+
97
+ it "prints to stderr" do
98
+ indirect_notify("ldap_server is deprecated.", "8.4")
99
+ @err.string.should ==
100
+ "DEPRECATION WARNING: ldap_server is deprecated. " <<
101
+ "It will be removed from aker in version 8.4 or later. " +
102
+ "(Called from deprecation_spec.rb:#{__LINE__ - 4}.)\n"
103
+ end
104
+
105
+ it "throws an exception for older versions" do
106
+ lambda { indirect_notify("I'm sorry to tell you this.", "1.6") }.
107
+ should raise_error(Aker::Deprecation::ObsoleteError, /aker 1.6/)
108
+ end
109
+
110
+ it "does not fail for future versions" do
111
+ lambda { indirect_notify("bad news", "10.3.4") }.should_not raise_error
112
+ end
113
+ end
114
+ end
115
+ end