pebblebed 0.0.46 → 0.0.47

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjI1ZmZkZTFmNDI5YjM0NWViYWNiZjU2ODM0NjkxZjkxODY5ZWE3Yg==
5
+ data.tar.gz: !binary |-
6
+ YWE2MjJlZThjMjg5ZmEwNDkxYWY2NWE4MWU1MzM2MzNjMmY5MDM4OQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NDMzYTYwYWNhM2JmNGE1NzU3ZWRhMmUwNzE1ZGExNGEyNWUxZDIwM2NkNWY0
10
+ ODc1YzMxYTM0OGM0ZDc5MWQxZTgyNjQ3YmFiMTBkM2JjNTQ2ZjUyZDNkYTdh
11
+ M2MxOWZmODM3OWY1NTFkOWRhNjg0ODVjYjdlMzYzMzUxMTMwOTg=
12
+ data.tar.gz: !binary |-
13
+ MDFjZTY0YTg1MmMzNGJjOGFmMDRlODRkMTMxYzI5NmY1MTU0YTc4MDE2NzA4
14
+ YTgzOGI5MTIwMjM2OTQ4NzE3ZDEzNjQxNzY3NWUxOWIwYjY3OTcxMWMyZmU3
15
+ MzcxMGQ1MTIxYzZkMWRjNDg3ZjBmMjkwMjFlYzdkNTUwYzYwNjI=
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in pebblebed.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Pebblebed
2
2
  =========
3
3
 
4
+ [![Build Status](https://semaphoreapp.com/api/v1/projects/0e497128541445910ba532d3ea1990799ae4e2a6/28288/badge.png)](https://semaphoreapp.com/projects/1582/branches/28288)
5
+
4
6
  This gem contains a number of tools for ruby that wants to be a good pebble.
5
7
 
6
8
  Usage
@@ -0,0 +1,89 @@
1
+ module Pebblebed
2
+ module Security
3
+ class RoleSchema
4
+
5
+ class UndefinedRole < Exception; end
6
+
7
+ attr_reader :connector, :identity
8
+
9
+ class << self
10
+ attr_reader :roles
11
+ end
12
+
13
+ def initialize(connector, identity)
14
+ @connector = connector
15
+ @identity = identity
16
+ @role = find_current_role
17
+ end
18
+
19
+ def role
20
+ {
21
+ :current => @role[:name],
22
+ :capabilities => @role[:capabilities],
23
+ :upgrades => @role[:upgrades]
24
+ }
25
+ end
26
+
27
+ def missing_requirements_for_role(role)
28
+ roles = self.class.roles
29
+ current_role = roles.select {|r| r[:name] == @role[:name] }.first
30
+ for_role = roles.select {|r| role.to_sym == r[:name] }.first
31
+ raise UndefinedRole, "The role :#{role} is not defined." unless for_role
32
+ roles[roles.index(current_role)..roles.index(for_role)].map{|r| r[:requirements]}.flatten.uniq
33
+ end
34
+
35
+ def self.requirements_for_role(role)
36
+ the_role = @roles.select {|r| r[:name] == role.to_sym }.first
37
+ raise UndefinedRole, "The role :#{role} is not defined." unless the_role
38
+ @roles[0..@roles.index(the_role)].map{|r| r[:requirements]}.flatten.uniq
39
+ end
40
+
41
+ def self.role(name, options)
42
+ @roles ||= []
43
+ @role_rank_level ||= 0
44
+ @roles << options.merge(:name => name, :role_rank => @role_rank_level)
45
+ @roles.sort!{|a,b| a[:role_rank] <=> b[:role_rank]}
46
+ @role_rank_level += 1
47
+ end
48
+
49
+ private
50
+
51
+ def find_current_role
52
+ the_role = begin
53
+ collected_roles = []
54
+ self.class.roles.each do |role|
55
+ collected_capabilities = []
56
+ if role[:requirements].any?
57
+ role[:requirements].each do |requirement|
58
+ # Check based on implemented check-methods in the subclass.
59
+ begin
60
+ if __send__("check_#{requirement}".to_sym)
61
+ collected_capabilities << requirement
62
+ end
63
+ rescue NoMethodError
64
+ raise NoMethodError, "You must implement method named :check_#{requirement} that returns true or false"
65
+ end
66
+ end
67
+ if (role[:requirements] & collected_capabilities) == role[:requirements]
68
+ the_role = role
69
+ collected_roles << role
70
+ end
71
+ else
72
+ the_role = role
73
+ collected_roles << role
74
+ end
75
+ end
76
+ the_role.merge(:upgrades => begin
77
+ result = {}
78
+ (self.class.roles - collected_roles).each{|r|
79
+ result[:"#{r[:name]}"] = r[:requirements]
80
+ }
81
+ result
82
+ end
83
+ )
84
+ end
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -1,3 +1,3 @@
1
1
  module Pebblebed
2
- VERSION = "0.0.46"
2
+ VERSION = "0.0.47"
3
3
  end
@@ -0,0 +1,133 @@
1
+ require 'spec_helper'
2
+ require 'deepstruct'
3
+ require 'pebblebed/config'
4
+ require 'pebblebed/connector'
5
+ require 'pebblebed/security/role_schema'
6
+
7
+
8
+ describe Pebblebed::Security::RoleSchema do
9
+
10
+ class InvalidRoleSchema < Pebblebed::Security::RoleSchema
11
+ role :guest, :capabilities => [], :requirements => []
12
+ role :contributor, :capabilities => [:comment, :kudo], :requirements => [:logged_in]
13
+ end
14
+
15
+ class CustomRoleSchema < Pebblebed::Security::RoleSchema
16
+ role :guest, :capabilities => [], :requirements => []
17
+ role :identified, :capabilities => [:kudo], :requirements => [:logged_in]
18
+ role :contributor, :capabilities => [:comment, :kudo], :requirements => [:logged_in, :verified_mobile]
19
+
20
+ def check_logged_in
21
+ return true if identity and identity['identity']
22
+ false
23
+ end
24
+
25
+ def check_verified_mobile
26
+ return true if identity and identity['identity'] and identity['identity']['verified_mobile']
27
+ false
28
+ end
29
+
30
+ end
31
+
32
+ let(:connector) {
33
+ Pebblebed::Connector.new("session_key")
34
+ }
35
+
36
+ let(:guest) {
37
+ DeepStruct.wrap({})
38
+ }
39
+
40
+ let(:contributor) {
41
+ DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false})
42
+ }
43
+
44
+ let(:contributor_with_mobile) {
45
+ DeepStruct.wrap(:identity => {:realm => 'testrealm', :id => 1, :god => false, :verified_mobile => true})
46
+ }
47
+
48
+ context "invalid role schema" do
49
+
50
+ let(:schema) {
51
+ InvalidRoleSchema.new(connector, guest)
52
+ }
53
+
54
+ it "raises a NoMethodError with explaination about what you need to implement" do
55
+ expect {
56
+ schema.role
57
+ }.to raise_error(NoMethodError, "You must implement method named :check_logged_in that returns true or false")
58
+ end
59
+ end
60
+
61
+ context "basics" do
62
+ let(:schema) {
63
+ CustomRoleSchema.new(connector, guest)
64
+ }
65
+
66
+ it "has connector and identity attributes" do
67
+ schema.connector.should eq connector
68
+ schema.identity.should eq guest
69
+ end
70
+
71
+ it "has the correct roles defined" do
72
+ CustomRoleSchema.roles.should == [{:capabilities=>[], :requirements=>[], :name=>:guest, :role_rank=>0}, {:capabilities=>[:kudo], :requirements=>[:logged_in], :name=>:identified, :role_rank=>1}, {:capabilities=>[:comment, :kudo], :requirements=>[:logged_in, :verified_mobile], :name=>:contributor, :role_rank=>2}]
73
+ end
74
+
75
+ it "has an answer to requirements for a role" do
76
+ CustomRoleSchema.requirements_for_role(:identified).should == [:logged_in]
77
+ CustomRoleSchema.requirements_for_role(:contributor).should == [:logged_in, :verified_mobile]
78
+ end
79
+
80
+ it "gives a exception when the role is not found" do
81
+ expect {
82
+ CustomRoleSchema.requirements_for_role(:foo)
83
+ }.to raise_error(Pebblebed::Security::RoleSchema::UndefinedRole)
84
+ end
85
+
86
+ it "gives the missing requirements for current role compared to a role" do
87
+ schema.missing_requirements_for_role(:identified).should == [:logged_in]
88
+ schema.missing_requirements_for_role(:contributor).should == [:logged_in, :verified_mobile]
89
+ end
90
+
91
+ end
92
+
93
+ context "as guest" do
94
+
95
+ let(:schema) {
96
+ CustomRoleSchema.new(connector, guest)
97
+ }
98
+
99
+ it "returns the guest role" do
100
+ schema.role.should == {:current=>:guest, :capabilities=>[], :upgrades=>{:identified=>[:logged_in], :contributor=>[:logged_in, :verified_mobile]}}
101
+ end
102
+
103
+ end
104
+
105
+ context "as contributor" do
106
+
107
+ context "with a contributor without verified mobile" do
108
+
109
+ let(:schema) {
110
+ CustomRoleSchema.new(connector, contributor)
111
+ }
112
+
113
+ it "returns the idenitified role" do
114
+ schema.role.should == {:current=>:identified, :capabilities=>[:kudo], :upgrades=>{:contributor=>[:logged_in, :verified_mobile]}}
115
+ end
116
+
117
+ end
118
+
119
+ context "with a contributor with a verified mobile" do
120
+
121
+ let(:schema) {
122
+ CustomRoleSchema.new(connector, contributor_with_mobile)
123
+ }
124
+
125
+ it "returns the contributor role" do
126
+ schema.role.should == {:current=>:contributor, :capabilities=>[:comment, :kudo], :upgrades=>{}}
127
+ end
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pebblebed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.46
5
- prerelease:
4
+ version: 0.0.47
6
5
  platform: ruby
7
6
  authors:
8
7
  - Katrina Owen
@@ -10,12 +9,11 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-02-15 00:00:00.000000000 Z
12
+ date: 2013-04-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rspec
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
@@ -23,7 +21,6 @@ dependencies:
23
21
  type: :development
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
25
  - - ! '>='
29
26
  - !ruby/object:Gem::Version
@@ -31,7 +28,6 @@ dependencies:
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
32
  - - ! '>='
37
33
  - !ruby/object:Gem::Version
@@ -39,7 +35,6 @@ dependencies:
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
39
  - - ! '>='
45
40
  - !ruby/object:Gem::Version
@@ -47,7 +42,6 @@ dependencies:
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: simplecov
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
46
  - - ! '>='
53
47
  - !ruby/object:Gem::Version
@@ -55,7 +49,6 @@ dependencies:
55
49
  type: :development
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
53
  - - ! '>='
61
54
  - !ruby/object:Gem::Version
@@ -63,7 +56,6 @@ dependencies:
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: sinatra
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
60
  - - ! '>='
69
61
  - !ruby/object:Gem::Version
@@ -71,7 +63,6 @@ dependencies:
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
67
  - - ! '>='
77
68
  - !ruby/object:Gem::Version
@@ -79,7 +70,6 @@ dependencies:
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: rack-test
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
74
  - - ! '>='
85
75
  - !ruby/object:Gem::Version
@@ -87,7 +77,6 @@ dependencies:
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
81
  - - ! '>='
93
82
  - !ruby/object:Gem::Version
@@ -95,7 +84,6 @@ dependencies:
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: memcache_mock
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - ! '>='
101
89
  - !ruby/object:Gem::Version
@@ -103,7 +91,6 @@ dependencies:
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - ! '>='
109
96
  - !ruby/object:Gem::Version
@@ -111,7 +98,6 @@ dependencies:
111
98
  - !ruby/object:Gem::Dependency
112
99
  name: deepstruct
113
100
  requirement: !ruby/object:Gem::Requirement
114
- none: false
115
101
  requirements:
116
102
  - - ! '>='
117
103
  - !ruby/object:Gem::Version
@@ -119,7 +105,6 @@ dependencies:
119
105
  type: :runtime
120
106
  prerelease: false
121
107
  version_requirements: !ruby/object:Gem::Requirement
122
- none: false
123
108
  requirements:
124
109
  - - ! '>='
125
110
  - !ruby/object:Gem::Version
@@ -127,7 +112,6 @@ dependencies:
127
112
  - !ruby/object:Gem::Dependency
128
113
  name: curb
129
114
  requirement: !ruby/object:Gem::Requirement
130
- none: false
131
115
  requirements:
132
116
  - - ! '>='
133
117
  - !ruby/object:Gem::Version
@@ -135,7 +119,6 @@ dependencies:
135
119
  type: :runtime
136
120
  prerelease: false
137
121
  version_requirements: !ruby/object:Gem::Requirement
138
- none: false
139
122
  requirements:
140
123
  - - ! '>='
141
124
  - !ruby/object:Gem::Version
@@ -143,7 +126,6 @@ dependencies:
143
126
  - !ruby/object:Gem::Dependency
144
127
  name: yajl-ruby
145
128
  requirement: !ruby/object:Gem::Requirement
146
- none: false
147
129
  requirements:
148
130
  - - ! '>='
149
131
  - !ruby/object:Gem::Version
@@ -151,7 +133,6 @@ dependencies:
151
133
  type: :runtime
152
134
  prerelease: false
153
135
  version_requirements: !ruby/object:Gem::Requirement
154
- none: false
155
136
  requirements:
156
137
  - - ! '>='
157
138
  - !ruby/object:Gem::Version
@@ -159,7 +140,6 @@ dependencies:
159
140
  - !ruby/object:Gem::Dependency
160
141
  name: queryparams
161
142
  requirement: !ruby/object:Gem::Requirement
162
- none: false
163
143
  requirements:
164
144
  - - ! '>='
165
145
  - !ruby/object:Gem::Version
@@ -167,7 +147,6 @@ dependencies:
167
147
  type: :runtime
168
148
  prerelease: false
169
149
  version_requirements: !ruby/object:Gem::Requirement
170
- none: false
171
150
  requirements:
172
151
  - - ! '>='
173
152
  - !ruby/object:Gem::Version
@@ -175,7 +154,6 @@ dependencies:
175
154
  - !ruby/object:Gem::Dependency
176
155
  name: futurevalue
177
156
  requirement: !ruby/object:Gem::Requirement
178
- none: false
179
157
  requirements:
180
158
  - - ! '>='
181
159
  - !ruby/object:Gem::Version
@@ -183,7 +161,6 @@ dependencies:
183
161
  type: :runtime
184
162
  prerelease: false
185
163
  version_requirements: !ruby/object:Gem::Requirement
186
- none: false
187
164
  requirements:
188
165
  - - ! '>='
189
166
  - !ruby/object:Gem::Version
@@ -191,7 +168,6 @@ dependencies:
191
168
  - !ruby/object:Gem::Dependency
192
169
  name: pathbuilder
193
170
  requirement: !ruby/object:Gem::Requirement
194
- none: false
195
171
  requirements:
196
172
  - - ! '>='
197
173
  - !ruby/object:Gem::Version
@@ -199,7 +175,6 @@ dependencies:
199
175
  type: :runtime
200
176
  prerelease: false
201
177
  version_requirements: !ruby/object:Gem::Requirement
202
- none: false
203
178
  requirements:
204
179
  - - ! '>='
205
180
  - !ruby/object:Gem::Version
@@ -207,7 +182,6 @@ dependencies:
207
182
  - !ruby/object:Gem::Dependency
208
183
  name: nokogiri
209
184
  requirement: !ruby/object:Gem::Requirement
210
- none: false
211
185
  requirements:
212
186
  - - ! '>='
213
187
  - !ruby/object:Gem::Version
@@ -215,7 +189,6 @@ dependencies:
215
189
  type: :runtime
216
190
  prerelease: false
217
191
  version_requirements: !ruby/object:Gem::Requirement
218
- none: false
219
192
  requirements:
220
193
  - - ! '>='
221
194
  - !ruby/object:Gem::Version
@@ -223,7 +196,6 @@ dependencies:
223
196
  - !ruby/object:Gem::Dependency
224
197
  name: i18n
225
198
  requirement: !ruby/object:Gem::Requirement
226
- none: false
227
199
  requirements:
228
200
  - - ! '>='
229
201
  - !ruby/object:Gem::Version
@@ -231,7 +203,6 @@ dependencies:
231
203
  type: :runtime
232
204
  prerelease: false
233
205
  version_requirements: !ruby/object:Gem::Requirement
234
- none: false
235
206
  requirements:
236
207
  - - ! '>='
237
208
  - !ruby/object:Gem::Version
@@ -239,7 +210,6 @@ dependencies:
239
210
  - !ruby/object:Gem::Dependency
240
211
  name: activesupport
241
212
  requirement: !ruby/object:Gem::Requirement
242
- none: false
243
213
  requirements:
244
214
  - - ! '>='
245
215
  - !ruby/object:Gem::Version
@@ -247,7 +217,6 @@ dependencies:
247
217
  type: :runtime
248
218
  prerelease: false
249
219
  version_requirements: !ruby/object:Gem::Requirement
250
- none: false
251
220
  requirements:
252
221
  - - ! '>='
253
222
  - !ruby/object:Gem::Version
@@ -255,7 +224,6 @@ dependencies:
255
224
  - !ruby/object:Gem::Dependency
256
225
  name: bunny
257
226
  requirement: !ruby/object:Gem::Requirement
258
- none: false
259
227
  requirements:
260
228
  - - ! '>='
261
229
  - !ruby/object:Gem::Version
@@ -263,7 +231,6 @@ dependencies:
263
231
  type: :runtime
264
232
  prerelease: false
265
233
  version_requirements: !ruby/object:Gem::Requirement
266
- none: false
267
234
  requirements:
268
235
  - - ! '>='
269
236
  - !ruby/object:Gem::Version
@@ -297,6 +264,7 @@ files:
297
264
  - lib/pebblebed/security/access_data.rb
298
265
  - lib/pebblebed/security/client.rb
299
266
  - lib/pebblebed/security/listener.rb
267
+ - lib/pebblebed/security/role_schema.rb
300
268
  - lib/pebblebed/sinatra.rb
301
269
  - lib/pebblebed/uid.rb
302
270
  - lib/pebblebed/version.rb
@@ -312,38 +280,32 @@ files:
312
280
  - spec/security/access_data_spec.rb
313
281
  - spec/security/client_spec.rb
314
282
  - spec/security/listener_spec.rb
283
+ - spec/security/role_shema_spec.rb
315
284
  - spec/sinatra_spec.rb
316
285
  - spec/spec_helper.rb
317
286
  - spec/uid_spec.rb
318
287
  homepage: ''
319
288
  licenses: []
289
+ metadata: {}
320
290
  post_install_message:
321
291
  rdoc_options: []
322
292
  require_paths:
323
293
  - lib
324
294
  required_ruby_version: !ruby/object:Gem::Requirement
325
- none: false
326
295
  requirements:
327
296
  - - ! '>='
328
297
  - !ruby/object:Gem::Version
329
298
  version: '0'
330
- segments:
331
- - 0
332
- hash: 1194197050294638142
333
299
  required_rubygems_version: !ruby/object:Gem::Requirement
334
- none: false
335
300
  requirements:
336
301
  - - ! '>='
337
302
  - !ruby/object:Gem::Version
338
303
  version: '0'
339
- segments:
340
- - 0
341
- hash: 1194197050294638142
342
304
  requirements: []
343
305
  rubyforge_project: pebblebed
344
- rubygems_version: 1.8.25
306
+ rubygems_version: 2.0.3
345
307
  signing_key:
346
- specification_version: 3
308
+ specification_version: 4
347
309
  summary: Development tools for working with Pebblebed
348
310
  test_files:
349
311
  - spec/config_spec.rb
@@ -357,6 +319,8 @@ test_files:
357
319
  - spec/security/access_data_spec.rb
358
320
  - spec/security/client_spec.rb
359
321
  - spec/security/listener_spec.rb
322
+ - spec/security/role_shema_spec.rb
360
323
  - spec/sinatra_spec.rb
361
324
  - spec/spec_helper.rb
362
325
  - spec/uid_spec.rb
326
+ has_rdoc: