strelka 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +35 -3
- data/History.rdoc +13 -0
- data/lib/strelka.rb +2 -2
- data/lib/strelka/app/auth.rb +3 -20
- data/lib/strelka/authprovider.rb +1 -2
- data/lib/strelka/httprequest/auth.rb +42 -0
- data/lib/strelka/mixins.rb +8 -0
- data/lib/strelka/session/db.rb +1 -3
- data/lib/strelka/testing.rb +2 -0
- data/spec/strelka/app/auth_spec.rb +16 -32
- data/spec/strelka/httprequest/acceptparams_spec.rb +1 -1
- data/spec/strelka/httprequest/auth_spec.rb +127 -9
- data/spec/strelka/router_spec.rb +1 -1
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23f3a2bf90987379d646fd64f813d403057ba894
|
4
|
+
data.tar.gz: 7df48c8764cf88fc8e357fd6d4e70ab84bc7af9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0d5356fbb5c03eccdb77d055796a6b120aabfd8702a590725b16b8b9446a42ad157fdd05841e96ab761ce91e74bdb8ade89893c4365d4cb5b7f34bc698f2ac1
|
7
|
+
data.tar.gz: 6993272bb47fd7874689853b7439b70581b27788ab3b1195125180eedca958bdc9a4e25bef06bf7d3587ea331dd70fd09d2d5a565fca256e2ec92b546679160b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/ChangeLog
CHANGED
@@ -1,8 +1,40 @@
|
|
1
|
+
2015-12-29 Mahlon E. Smith <mahlon@martini.nu>
|
2
|
+
|
3
|
+
* lib/strelka/app/auth.rb, lib/strelka/authprovider.rb,
|
4
|
+
spec/strelka/app/auth_spec.rb:
|
5
|
+
If authentication fails, throw from the request processing path
|
6
|
+
instead of the authprovider API.
|
7
|
+
[4ec61e15b3b3] [tip]
|
8
|
+
|
9
|
+
2015-11-18 Michael Granger <ged@FaerieMUD.org>
|
10
|
+
|
11
|
+
* lib/strelka/app/auth.rb, lib/strelka/httprequest/auth.rb,
|
12
|
+
lib/strelka/mixins.rb, lib/strelka/testing.rb,
|
13
|
+
spec/strelka/app/auth_spec.rb,
|
14
|
+
spec/strelka/httprequest/auth_spec.rb:
|
15
|
+
Add a mechanism for deferring authentication to request handlers
|
16
|
+
[92cfae454ef1] [github/master]
|
17
|
+
|
18
|
+
* lib/strelka/app/auth.rb, spec/strelka/app/auth_spec.rb:
|
19
|
+
Back out the auth hook before adding deferred auth
|
20
|
+
[62beb1c355cb]
|
21
|
+
|
22
|
+
2015-11-16 Michael Granger <ged@FaerieMUD.org>
|
23
|
+
|
24
|
+
* lib/strelka/session/db.rb:
|
25
|
+
Fix Sqlite session table schema
|
26
|
+
[ee4051a888a1]
|
27
|
+
|
28
|
+
* spec/strelka/httprequest/acceptparams_spec.rb,
|
29
|
+
spec/strelka/router_spec.rb:
|
30
|
+
Fix empty raise_error()s
|
31
|
+
[142dd3a71307]
|
32
|
+
|
1
33
|
2015-10-01 Mahlon E. Smith <mahlon@laika.com>
|
2
34
|
|
3
35
|
* .hgsigs:
|
4
36
|
Added signature for changeset 2e4e4c78a588
|
5
|
-
[50bc1d12bad4]
|
37
|
+
[50bc1d12bad4]
|
6
38
|
|
7
39
|
* .hgtags:
|
8
40
|
Added tag v0.10.0 for changeset 2aae0e98c859
|
@@ -135,7 +167,7 @@
|
|
135
167
|
|
136
168
|
* strelka.gemspec:
|
137
169
|
Update the gemspec
|
138
|
-
[92c894486289]
|
170
|
+
[92c894486289]
|
139
171
|
|
140
172
|
* Rakefile:
|
141
173
|
Fix the fivefish version
|
@@ -757,7 +789,7 @@
|
|
757
789
|
spec/strelka/app/parameters_spec.rb,
|
758
790
|
spec/strelka/paramvalidator_spec.rb:
|
759
791
|
Add a paramvalidator constraint for JSON fields
|
760
|
-
[ac11b12f9366]
|
792
|
+
[ac11b12f9366] [github/no-notes-auto-vivify]
|
761
793
|
|
762
794
|
2013-01-25 Michael Granger <ged@FaerieMUD.org>
|
763
795
|
|
data/History.rdoc
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
== v0.11.0 [2016-01-20] Mahlon E. Smith <mahlon@martini.nu>
|
2
|
+
|
3
|
+
Enhancements:
|
4
|
+
|
5
|
+
- Add a mechanism for deferring authentication to request handlers
|
6
|
+
- If authentication fails, throw from the request processing path
|
7
|
+
instead of the authprovider API.
|
8
|
+
|
9
|
+
Bugfixes:
|
10
|
+
|
11
|
+
- Fix Sqlite session table schema
|
12
|
+
|
13
|
+
|
1
14
|
== v0.10.0 [2015-10-01] Mahlon E. Smith <mahlon@martini.nu>
|
2
15
|
|
3
16
|
- Allow authentication to be optional for a route.
|
data/lib/strelka.rb
CHANGED
@@ -24,10 +24,10 @@ module Strelka
|
|
24
24
|
log_as :strelka
|
25
25
|
|
26
26
|
# Library version constant
|
27
|
-
VERSION = '0.
|
27
|
+
VERSION = '0.11.0'
|
28
28
|
|
29
29
|
# Version-control revision constant
|
30
|
-
REVISION = %q$Revision:
|
30
|
+
REVISION = %q$Revision: d794173d505f $
|
31
31
|
|
32
32
|
require 'strelka/mixins'
|
33
33
|
require 'strelka/constants'
|
data/lib/strelka/app/auth.rb
CHANGED
@@ -473,6 +473,7 @@ module Strelka::App::Auth
|
|
473
473
|
def handle_request( request, &block )
|
474
474
|
self.log.debug "[:auth] Wrapping request in auth with a %p" % [ self.auth_provider ]
|
475
475
|
|
476
|
+
request.auth_provider = self.auth_provider
|
476
477
|
self.authenticate_and_authorize( request )
|
477
478
|
|
478
479
|
super
|
@@ -495,7 +496,8 @@ module Strelka::App::Auth
|
|
495
496
|
def provide_authentication( request )
|
496
497
|
provider = self.auth_provider
|
497
498
|
self.log.info "Authenticating request using provider: %p" % [ provider ]
|
498
|
-
|
499
|
+
credentials = provider.authenticate( request ) or finish_with( HTTP::AUTH_REQUIRED, "Authentication required." )
|
500
|
+
return credentials
|
499
501
|
end
|
500
502
|
|
501
503
|
|
@@ -570,25 +572,6 @@ module Strelka::App::Auth
|
|
570
572
|
alias_method :required_perms_for, :perms_required_for
|
571
573
|
|
572
574
|
|
573
|
-
### Normally, the authentication plugin manages authing a user
|
574
|
-
### automatically. There are cases where we want to perform this
|
575
|
-
### manually, such as a route that provides alternate data for an
|
576
|
-
### authenticated user, but still allows non-authed access.
|
577
|
-
###
|
578
|
-
### Returns the authenticated user object, or nil if unsuccessful.
|
579
|
-
###
|
580
|
-
### This essentially makes authentication optional for a route, instead
|
581
|
-
### of simply "on" or "off".
|
582
|
-
def authenticate( request )
|
583
|
-
acct = nil
|
584
|
-
catch( :finish ) do
|
585
|
-
acct = self.auth_provider.authenticate( request )
|
586
|
-
request.authenticated_user = acct
|
587
|
-
end
|
588
|
-
return acct
|
589
|
-
end
|
590
|
-
|
591
|
-
|
592
575
|
#########
|
593
576
|
protected
|
594
577
|
#########
|
data/lib/strelka/authprovider.rb
CHANGED
@@ -63,8 +63,7 @@ class Strelka::AuthProvider
|
|
63
63
|
|
64
64
|
|
65
65
|
### You should override this method if you want to authenticate the +request+. It should
|
66
|
-
### return a credentials object if authentication is successful, or
|
67
|
-
### response if it fails.
|
66
|
+
### return a credentials object if authentication is successful, or a false value if it fails.
|
68
67
|
def authenticate( request )
|
69
68
|
self.log.debug "No authentication provided, returning anonymous credentials."
|
70
69
|
return 'anonymous'
|
@@ -13,6 +13,7 @@ module Strelka::HTTPRequest::Auth
|
|
13
13
|
### Extension callback -- add instance variables to extended objects.
|
14
14
|
def initialize( * )
|
15
15
|
super
|
16
|
+
@auth_provider = nil
|
16
17
|
@authenticated_user = nil
|
17
18
|
end
|
18
19
|
|
@@ -25,6 +26,47 @@ module Strelka::HTTPRequest::Auth
|
|
25
26
|
attr_accessor :authenticated_user
|
26
27
|
alias_method :authenticated?, :authenticated_user
|
27
28
|
|
29
|
+
# The Strelka::AuthProvider the app uses for authentication (if any)
|
30
|
+
attr_accessor :auth_provider
|
31
|
+
|
32
|
+
|
33
|
+
### Try to authenticate the request using the specified +block+. If a +block+ is not provided,
|
34
|
+
### the #authenticate method of the app's AuthProvider is used instead.
|
35
|
+
###
|
36
|
+
### Valid +options+ are:
|
37
|
+
###
|
38
|
+
### [+:optional+] if this is set to a true value, don't throw a 401 Requires Authentication
|
39
|
+
### if the authentication fails.
|
40
|
+
###
|
41
|
+
def authenticate( options={}, &block )
|
42
|
+
block ||= self.auth_provider.method( :authenticate )
|
43
|
+
result = block.call( self )
|
44
|
+
|
45
|
+
finish_with( HTTP::UNAUTHORIZED, "Authorization failed" ) unless result || options[:optional]
|
46
|
+
self.authenticated_user = result
|
47
|
+
|
48
|
+
return result
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
### Try to check authorization using the specified +block+. If a +block+ is not
|
53
|
+
### provided, the #authorize method of the app's AuthProvider is used instead.
|
54
|
+
### If the request doesn't already have an +authenticated_user+ set,
|
55
|
+
### #authenticate will be called with no arguments to try to provide one.
|
56
|
+
### The provided +perms+ are passed either to the block or the AuthProvider if
|
57
|
+
### no block is given. If successful, the authenticated user that was used is returned.
|
58
|
+
def authorize( *perms, &block )
|
59
|
+
if block
|
60
|
+
results = block.call or
|
61
|
+
finish_with( HTTP::FORBIDDEN, "You are not authorized to access this resource." )
|
62
|
+
return results
|
63
|
+
else
|
64
|
+
self.log.debug "Deferred authorization via %p" % [ self.auth_provider ]
|
65
|
+
credentials = self.authenticated_user || self.authenticate
|
66
|
+
self.auth_provider.authorize( credentials, self, perms )
|
67
|
+
return credentials
|
68
|
+
end
|
69
|
+
end
|
28
70
|
|
29
71
|
end # module Strelka::HTTPRequest::Auth
|
30
72
|
|
data/lib/strelka/mixins.rb
CHANGED
@@ -329,8 +329,16 @@ module Strelka
|
|
329
329
|
|
330
330
|
# A collection of functions for generating responses.
|
331
331
|
module ResponseHelpers
|
332
|
+
extend Loggability
|
332
333
|
include Strelka::Constants
|
333
334
|
|
335
|
+
log_to :strelka
|
336
|
+
|
337
|
+
|
338
|
+
###############
|
339
|
+
module_function
|
340
|
+
###############
|
341
|
+
|
334
342
|
### Abort the current execution and return a response with the specified
|
335
343
|
### http_status code immediately. The specified +message+ will be logged,
|
336
344
|
### and will be included in any message that is returned as part of the
|
data/lib/strelka/session/db.rb
CHANGED
@@ -72,11 +72,9 @@ class Strelka::Session::Db < Strelka::Session::Default
|
|
72
72
|
else
|
73
73
|
self.log.debug "Creating new sessions table for %p" % [ db ]
|
74
74
|
self.db.create_table( self.table_name.to_sym ) do
|
75
|
-
text :session_id, :
|
75
|
+
text :session_id, :primary_key => true
|
76
76
|
text :session
|
77
77
|
timestamp :created
|
78
|
-
|
79
|
-
primary_key :session_id
|
80
78
|
end
|
81
79
|
end
|
82
80
|
|
data/lib/strelka/testing.rb
CHANGED
@@ -87,6 +87,8 @@ module Strelka::Testing
|
|
87
87
|
nil
|
88
88
|
end
|
89
89
|
|
90
|
+
Loggability[ Strelka ].debug "Test proc called; status info is: %p" % [ status_info ]
|
91
|
+
|
90
92
|
return self.check_finish( status_info ) &&
|
91
93
|
self.check_status_code( status_info ) &&
|
92
94
|
self.check_message( status_info ) &&
|
@@ -27,6 +27,13 @@ describe Strelka::App::Auth do
|
|
27
27
|
it_should_behave_like( "A Strelka Plugin" )
|
28
28
|
|
29
29
|
|
30
|
+
RSpec::Matchers.define( :require_auth_for_request ) do |request|
|
31
|
+
match do |app|
|
32
|
+
app.request_should_auth?( request )
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
30
37
|
it "gives including apps a default authprovider" do
|
31
38
|
app = Class.new( Strelka::App ) do
|
32
39
|
plugins :auth
|
@@ -62,7 +69,6 @@ describe Strelka::App::Auth do
|
|
62
69
|
def handle_request( req )
|
63
70
|
super do
|
64
71
|
res = req.response
|
65
|
-
self.authenticate( req ) if req.uri.to_s =~ /\/optional$/
|
66
72
|
res.status = HTTP::OK
|
67
73
|
res.content_type = 'text/plain'
|
68
74
|
res.puts "Ran successfully."
|
@@ -125,14 +131,6 @@ describe Strelka::App::Auth do
|
|
125
131
|
expect( subclass.negative_perms_criteria ).to_not equal( @app.negative_perms_criteria )
|
126
132
|
end
|
127
133
|
|
128
|
-
|
129
|
-
RSpec::Matchers.define( :require_auth_for_request ) do |request|
|
130
|
-
match do |app|
|
131
|
-
app.request_should_auth?( request )
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
134
|
it "allows auth criteria to be declared with a string" do
|
137
135
|
@app.require_auth_for( '/string' )
|
138
136
|
app = @app.new
|
@@ -319,7 +317,6 @@ describe Strelka::App::Auth do
|
|
319
317
|
|
320
318
|
end
|
321
319
|
|
322
|
-
|
323
320
|
it "allows perms criteria to be declared with a string" do
|
324
321
|
@app.require_perms_for( '/string', :stringperm )
|
325
322
|
app = @app.new
|
@@ -574,7 +571,7 @@ describe Strelka::App::Auth do
|
|
574
571
|
req = @request_factory.get( '/api/v1/onlyauth' )
|
575
572
|
|
576
573
|
app = @app.new
|
577
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
574
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
578
575
|
expect( app.auth_provider ).to_not receive( :authorize )
|
579
576
|
|
580
577
|
app.handle( req )
|
@@ -584,7 +581,7 @@ describe Strelka::App::Auth do
|
|
584
581
|
req = @request_factory.get( '/api/v1/both' )
|
585
582
|
|
586
583
|
app = @app.new
|
587
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
584
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
588
585
|
expect( app.auth_provider ).to receive( :authorize )
|
589
586
|
|
590
587
|
app.handle( req )
|
@@ -623,7 +620,7 @@ describe Strelka::App::Auth do
|
|
623
620
|
req = @request_factory.get( '/api/v1/onlyauth' )
|
624
621
|
|
625
622
|
app = @app.new
|
626
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
623
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
627
624
|
expect( app.auth_provider ).to receive( :authorize )
|
628
625
|
|
629
626
|
app.handle( req )
|
@@ -633,7 +630,7 @@ describe Strelka::App::Auth do
|
|
633
630
|
req = @request_factory.get( '/api/v1/both' )
|
634
631
|
|
635
632
|
app = @app.new
|
636
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
633
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
637
634
|
expect( app.auth_provider ).to_not receive( :authorize )
|
638
635
|
|
639
636
|
app.handle( req )
|
@@ -659,20 +656,6 @@ describe Strelka::App::Auth do
|
|
659
656
|
before( :each ) do
|
660
657
|
@app.no_auth_for( '/onlyauth' )
|
661
658
|
@app.no_auth_for( '/both' )
|
662
|
-
@app.no_auth_for( '/optional' )
|
663
|
-
end
|
664
|
-
|
665
|
-
context "and optional auth for a route" do
|
666
|
-
|
667
|
-
it "checks auth without throwing HTTP::AUTH_REQUIRED" do
|
668
|
-
req = @request_factory.get( '/api/v1/optional' )
|
669
|
-
|
670
|
-
app = @app.new
|
671
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
672
|
-
expect( app.auth_provider ).to receive( :authorize )
|
673
|
-
|
674
|
-
app.handle( req )
|
675
|
-
end
|
676
659
|
end
|
677
660
|
|
678
661
|
context "and positive perms criteria" do
|
@@ -686,7 +669,7 @@ describe Strelka::App::Auth do
|
|
686
669
|
req = @request_factory.get( '/api/v1/onlyperms' )
|
687
670
|
|
688
671
|
app = @app.new
|
689
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
672
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
690
673
|
expect( app.auth_provider ).to receive( :authorize )
|
691
674
|
|
692
675
|
app.handle( req )
|
@@ -716,7 +699,7 @@ describe Strelka::App::Auth do
|
|
716
699
|
req = @request_factory.get( '/api/v1/neither' )
|
717
700
|
|
718
701
|
app = @app.new
|
719
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
702
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
720
703
|
expect( app.auth_provider ).to_not receive( :authorize )
|
721
704
|
|
722
705
|
app.handle( req )
|
@@ -735,7 +718,7 @@ describe Strelka::App::Auth do
|
|
735
718
|
req = @request_factory.get( '/api/v1/onlyperms' )
|
736
719
|
|
737
720
|
app = @app.new
|
738
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
721
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
739
722
|
expect( app.auth_provider ).to_not receive( :authorize )
|
740
723
|
|
741
724
|
app.handle( req )
|
@@ -765,7 +748,7 @@ describe Strelka::App::Auth do
|
|
765
748
|
req = @request_factory.get( '/api/v1/neither' )
|
766
749
|
|
767
750
|
app = @app.new
|
768
|
-
expect( app.auth_provider ).to receive( :authenticate )
|
751
|
+
expect( app.auth_provider ).to receive( :authenticate ).and_return( true )
|
769
752
|
expect( app.auth_provider ).to receive( :authorize )
|
770
753
|
|
771
754
|
app.handle( req )
|
@@ -796,6 +779,7 @@ describe Strelka::App::Auth do
|
|
796
779
|
|
797
780
|
end
|
798
781
|
|
782
|
+
|
799
783
|
end
|
800
784
|
|
801
785
|
end
|
@@ -6,6 +6,7 @@ require_relative '../../helpers'
|
|
6
6
|
require 'rspec'
|
7
7
|
|
8
8
|
require 'strelka'
|
9
|
+
require 'strelka/authprovider'
|
9
10
|
require 'strelka/httprequest/auth'
|
10
11
|
|
11
12
|
|
@@ -19,22 +20,139 @@ describe Strelka::HTTPRequest::Auth do
|
|
19
20
|
@request_factory = Mongrel2::RequestFactory.new( route: '/service/user' )
|
20
21
|
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
@
|
23
|
+
|
24
|
+
let( :request ) do
|
25
|
+
request = @request_factory.get( '/service/user/astark' )
|
26
|
+
request.extend( described_class )
|
27
|
+
request
|
25
28
|
end
|
26
29
|
|
27
30
|
|
31
|
+
|
28
32
|
it "adds an authenticated? predicate" do
|
29
|
-
expect(
|
30
|
-
|
31
|
-
expect(
|
33
|
+
expect( request ).to_not be_authenticated()
|
34
|
+
request.authenticated_user = 'anonymous'
|
35
|
+
expect( request ).to be_authenticated()
|
32
36
|
end
|
33
37
|
|
34
38
|
it "adds an authenticated_user attribute" do
|
35
|
-
expect(
|
36
|
-
|
37
|
-
expect(
|
39
|
+
expect( request.authenticated_user ).to be_nil()
|
40
|
+
request.authenticated_user = 'someone'
|
41
|
+
expect( request.authenticated_user ).to eq( 'someone' )
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
context "authentication method" do
|
46
|
+
|
47
|
+
it "sets the authenticated user to the result of the authenticate block" do
|
48
|
+
request.authenticate do
|
49
|
+
:the_user
|
50
|
+
end
|
51
|
+
|
52
|
+
expect( request.authenticated_user ).to eq( :the_user )
|
53
|
+
end
|
54
|
+
|
55
|
+
it "calls #authenticate on the request's auth_provider if no block is given" do
|
56
|
+
request.auth_provider = instance_double( Strelka::AuthProvider )
|
57
|
+
|
58
|
+
expect( request.auth_provider ).to receive( :authenticate ).with( request ).
|
59
|
+
and_return( :the_user )
|
60
|
+
|
61
|
+
expect( request.authenticate ).to eq( :the_user )
|
62
|
+
expect( request.authenticated_user ).to eq( :the_user )
|
63
|
+
end
|
64
|
+
|
65
|
+
it "finishes with a 401 Auth Required if the provided block returns a false value" do
|
66
|
+
expect {
|
67
|
+
request.authenticate { false }
|
68
|
+
}.to finish_with( HTTP::UNAUTHORIZED )
|
69
|
+
end
|
70
|
+
|
71
|
+
it "doesn't 401 if provided block returns false when called with optional: true" do
|
72
|
+
expect {
|
73
|
+
request.authenticate( optional: true ) { false }
|
74
|
+
}.to_not finish_with( HTTP::UNAUTHORIZED )
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
context "authorization method" do
|
81
|
+
|
82
|
+
it "is a noop if the provided block returns true" do
|
83
|
+
expect {
|
84
|
+
request.authorize { :the_user }
|
85
|
+
}.to_not finish_with( HTTP::FORBIDDEN )
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
it "calls #authorize on the request's auth_provider if no block is given" do
|
90
|
+
request.authenticated_user = :the_user
|
91
|
+
request.auth_provider = instance_double( Strelka::AuthProvider )
|
92
|
+
|
93
|
+
expect( request.auth_provider ).to_not receive( :authenticate )
|
94
|
+
expect( request.auth_provider ).to receive( :authorize ).
|
95
|
+
with( :the_user, request, [] ).
|
96
|
+
and_return( true )
|
97
|
+
|
98
|
+
result = request.authorize
|
99
|
+
|
100
|
+
expect( result ).to eq( :the_user )
|
101
|
+
expect( request.authenticated_user ).to eq( :the_user )
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
it "trys to authenticate if called without a block and the request doesn't have an authorized_user" do
|
106
|
+
request.authenticated_user = nil
|
107
|
+
request.auth_provider = instance_double( Strelka::AuthProvider )
|
108
|
+
|
109
|
+
expect( request.auth_provider ).to receive( :authenticate ).with( request ).
|
110
|
+
and_return( :the_user )
|
111
|
+
expect( request.auth_provider ).to receive( :authorize ).
|
112
|
+
with( :the_user, request, [] ).
|
113
|
+
and_return( true )
|
114
|
+
|
115
|
+
result = request.authorize
|
116
|
+
|
117
|
+
expect( result ).to eq( :the_user )
|
118
|
+
expect( request.authenticated_user ).to eq( :the_user )
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
it "finishes with a 401 Auth Required if calling #authorize without a block and auth fails" do
|
123
|
+
request.auth_provider = instance_double( Strelka::AuthProvider )
|
124
|
+
|
125
|
+
expect( request.auth_provider ).to receive( :authenticate ) do |arg|
|
126
|
+
expect( arg ).to be( request )
|
127
|
+
Strelka::ResponseHelpers.finish_with( HTTP::UNAUTHORIZED )
|
128
|
+
end
|
129
|
+
|
130
|
+
expect { request.authorize }.to finish_with( HTTP::UNAUTHORIZED )
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
it "finishes with a 403 Forbidden if it returns a false value" do
|
135
|
+
expect {
|
136
|
+
request.authorize { false }
|
137
|
+
}.to finish_with( HTTP::FORBIDDEN )
|
138
|
+
end
|
139
|
+
|
140
|
+
|
141
|
+
it "passes permissions to the auth provider" do
|
142
|
+
request.authenticated_user = :the_user
|
143
|
+
request.auth_provider = instance_double( Strelka::AuthProvider )
|
144
|
+
|
145
|
+
expect( request.auth_provider ).to receive( :authorize ).
|
146
|
+
with( :the_user, request, [ :hand, :meat ] ).
|
147
|
+
and_return( true )
|
148
|
+
|
149
|
+
result = request.authorize( :hand, :meat )
|
150
|
+
|
151
|
+
expect( result ).to eq( :the_user )
|
152
|
+
expect( request.authenticated_user ).to eq( :the_user )
|
153
|
+
end
|
154
|
+
|
38
155
|
end
|
39
156
|
|
157
|
+
|
40
158
|
end
|
data/spec/strelka/router_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strelka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mahlon E. Smith
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
G8LHR7EjtPPmqCCunfyecJ6MmCNaiJCBxq2NYzyNmluPyHT8+0fuB5kccUVZm6CD
|
32
32
|
xn3DzOkDE6NYbk8gC9rTsA==
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date:
|
34
|
+
date: 2016-01-20 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: configurability
|
@@ -297,14 +297,14 @@ dependencies:
|
|
297
297
|
requirements:
|
298
298
|
- - "~>"
|
299
299
|
- !ruby/object:Gem::Version
|
300
|
-
version: '3.
|
300
|
+
version: '3.14'
|
301
301
|
type: :development
|
302
302
|
prerelease: false
|
303
303
|
version_requirements: !ruby/object:Gem::Requirement
|
304
304
|
requirements:
|
305
305
|
- - "~>"
|
306
306
|
- !ruby/object:Gem::Version
|
307
|
-
version: '3.
|
307
|
+
version: '3.14'
|
308
308
|
description: |-
|
309
309
|
Strelka is a framework for creating and deploying
|
310
310
|
Mongrel2[http://mongrel2.org/] web applications in Ruby.
|
@@ -485,7 +485,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
485
485
|
version: '0'
|
486
486
|
requirements: []
|
487
487
|
rubyforge_project:
|
488
|
-
rubygems_version: 2.4.
|
488
|
+
rubygems_version: 2.4.8
|
489
489
|
signing_key:
|
490
490
|
specification_version: 4
|
491
491
|
summary: Strelka is a framework for creating and deploying Mongrel2[http://mongrel2.org/]
|
metadata.gz.sig
CHANGED
Binary file
|