pebblebed 0.0.45 → 0.0.46

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -48,17 +48,17 @@ This exception has the fields `status` and `message`.
48
48
 
49
49
  Other helper methods provided by this extension:
50
50
 
51
- part(partspec, params = {}) # Include a part from a kit (See https://github.com/benglerpebbles/kits)
52
- parts_script_include_tags # All script tags required by the kits
53
- parts_stylesheet_include_tags # All stylesheet-tags required by the kits
54
- current_session # The hash string that identifies the current browser session
55
- pebbles # Common entrypoint for the Pebblebed::Connector
56
- current_identity # Returns the a DeepStruct record with the vital data for the current user
57
- require_identity # Halts with 403 if there is no current user
58
- require_god # Halts with 403 if the current user is not a god
59
- require_access_to_path(path) # Halts with 403 if the current user is not a member of a checkpoint access group with privileged access to that path
60
- require_action_allowed(action, uid) # Halts with 403 if the current user is not allowed by checkpoint to perform this action for that uid
61
- require_parameters(parameters, *keys) # Halts with 409 if the at least one of the provided keys is not in the params-hash
51
+ part(partspec, params = {}) # Include a part from a kit (See https://github.com/benglerpebbles/kits)
52
+ parts_script_include_tags # All script tags required by the kits
53
+ parts_stylesheet_include_tags # All stylesheet-tags required by the kits
54
+ current_session # The hash string that identifies the current browser session
55
+ pebbles # Common entrypoint for the Pebblebed::Connector
56
+ current_identity # Returns the a DeepStruct record with the vital data for the current user
57
+ require_identity # Halts with 403 if there is no current user
58
+ require_god # Halts with 403 if the current user is not a god
59
+ require_access_to_path(path) # Halts with 403 if the current user is not a member of a checkpoint access group with privileged access to that path
60
+ require_action_allowed(action, uid, options={}) # Halts with 403 if the current user is not allowed by checkpoint to perform this action for that uid. If a response :allowed => "default" (no policy found) is returned from checkpoint, options[:default] => [bool] is evaluated. options[:default] => true will allow the action on 'default'. Bool false will halt by 403. If no options is given, the method will halt 403 on everything but true.
61
+ require_parameters(parameters, *keys) # Halts with 409 if the at least one of the provided keys is not in the params-hash
62
62
 
63
63
  ### Testing Sinatra APIs
64
64
 
@@ -93,12 +93,13 @@ module Sinatra
93
93
  halt 403, "Access denied."
94
94
  end
95
95
 
96
- def require_action_allowed(action, uid)
96
+ def require_action_allowed(action, uid, options={})
97
97
  require_identity
98
98
  uid = ::Pebblebed::Uid.new(uid) if uid.is_a?(String)
99
99
  return if current_identity.god and uid.path.split(".")[0] == current_identity.realm
100
100
  res = pebbles.checkpoint.get("/callbacks/allowed/#{action}/#{uid}")
101
- return res['allowed'] if res['allowed']
101
+ return res['allowed'] if res['allowed'] == true or
102
+ (res['allowed'] == "default" and options[:default])
102
103
  halt 403, ":#{action} denied for #{uid} : #{res['reason']}"
103
104
  end
104
105
 
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.45"
2
+ VERSION = "0.0.46"
3
3
  end
data/spec/sinatra_spec.rb CHANGED
@@ -39,6 +39,16 @@ class TestApp < Sinatra::Base
39
39
  "You are creative"
40
40
  end
41
41
 
42
+ post '/create2/:uid' do |uid|
43
+ require_action_allowed(:create, uid, :default => false)
44
+ "You are creative"
45
+ end
46
+
47
+ post '/create3/:uid' do |uid|
48
+ require_action_allowed(:create, uid, :default => true)
49
+ "You are creative"
50
+ end
51
+
42
52
  get '/nonexistant' do
43
53
  raise Pebblebed::HttpNotFoundError, "Not found /nonexistant"
44
54
  end
@@ -199,6 +209,36 @@ describe Sinatra::Pebblebed do
199
209
  post '/create/post.foo:testrealm'
200
210
  last_response.body.should == "You are creative"
201
211
  end
212
+ context "with options[:default] => false" do
213
+ specify "is disallowed" do
214
+ user!
215
+ checkpoint.should_receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
216
+ checkpoint.should_receive(:get).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
217
+ Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
218
+ post '/create2/post.foo:testrealm'
219
+ last_response.status.should == 403
220
+ end
221
+ end
222
+ context "with no options given and allowed = default" do
223
+ specify "is disallowed" do
224
+ user!
225
+ checkpoint.should_receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
226
+ checkpoint.should_receive(:get).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
227
+ Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
228
+ post '/create/post.foo:testrealm'
229
+ last_response.status.should == 403
230
+ end
231
+ end
232
+ context "with options[:default] => true" do
233
+ specify "is allowed" do
234
+ user!
235
+ checkpoint.should_receive(:get).with("/identities/me").and_return(DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false}))
236
+ checkpoint.should_receive(:get).with("/callbacks/allowed/create/post.foo:testrealm").and_return(DeepStruct.wrap(:allowed => "default"))
237
+ Pebblebed::Connector.any_instance.stub(:checkpoint => checkpoint)
238
+ post '/create3/post.foo:testrealm'
239
+ last_response.body.should == "You are creative"
240
+ end
241
+ end
202
242
  end
203
243
  end
204
244
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.45
4
+ version: 0.0.46
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-02-13 00:00:00.000000000 Z
13
+ date: 2013-02-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -329,7 +329,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
329
329
  version: '0'
330
330
  segments:
331
331
  - 0
332
- hash: 237012637135084967
332
+ hash: 1194197050294638142
333
333
  required_rubygems_version: !ruby/object:Gem::Requirement
334
334
  none: false
335
335
  requirements:
@@ -338,7 +338,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
338
338
  version: '0'
339
339
  segments:
340
340
  - 0
341
- hash: 237012637135084967
341
+ hash: 1194197050294638142
342
342
  requirements: []
343
343
  rubyforge_project: pebblebed
344
344
  rubygems_version: 1.8.25