trust 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,123 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ # Copyright (c) 2012 Patrick Hanevold
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require 'test_helper'
26
+
27
+ class MongoAccountsControllerTest < ActionController::TestCase
28
+ context 'with all permissions' do
29
+ setup do
30
+ login_as(:system_admin)
31
+ @client = MongoClient.create
32
+ @account = MongoAccount.create(:mongo_client_id => @client.id) #accounts(:one)
33
+ end
34
+
35
+ should "get index" do
36
+ get :index, mongo_client_id: @client
37
+ assert_response :success
38
+ assert_not_nil assigns(:mongo_accounts)
39
+ end
40
+
41
+ should "get new" do
42
+ get :new, mongo_client_id: @client
43
+ assert_response :success
44
+ end
45
+
46
+ should "create account" do
47
+ assert_difference('MongoAccount.count') do
48
+ post :create, mongo_client_id: @client, mongo_account: { name: @account.name }
49
+ end
50
+
51
+ assert_redirected_to mongo_client_mongo_account_path(@client,assigns(:mongo_account))
52
+ end
53
+
54
+ should "show account" do
55
+ get :show, mongo_client_id: @client.id, id: @account.id
56
+ assert_response :success
57
+ end
58
+
59
+ should "get edit" do
60
+ get :edit, mongo_client_id: @client, id: @account
61
+ assert_response :success
62
+ end
63
+
64
+ should "update account" do
65
+ put :update, mongo_client_id: @client, id: @account, mongo_account: { name: @account.name }
66
+ assert_redirected_to mongo_client_mongo_account_path(assigns(:mongo_account))
67
+ end
68
+
69
+ should "destroy account" do
70
+ assert_difference('MongoAccount.count', -1) do
71
+ delete :destroy, mongo_client_id: @client, id: @account
72
+ end
73
+
74
+ assert_redirected_to mongo_client_mongo_accounts_path
75
+ end
76
+ end
77
+
78
+ context 'with limited permissions' do
79
+ setup do
80
+ login_as(:accountant)
81
+ @client = MongoClient.create
82
+ @account = @client.mongo_accounts.create
83
+ flunk unless @account
84
+ end
85
+
86
+ should 'deny access on index' do
87
+ assert_raises Trust::AccessDenied do
88
+ get :index, mongo_client_id: @client
89
+ end
90
+ end
91
+ should 'deny access on new' do
92
+ assert_raises Trust::AccessDenied do
93
+ get :new, mongo_client_id: @client
94
+ end
95
+ end
96
+ should 'deny access on show' do
97
+ assert_raises Trust::AccessDenied do
98
+ get :show, mongo_client_id: @client, id: @account
99
+ end
100
+ end
101
+ should 'deny access on destroy' do
102
+ assert_raises Trust::AccessDenied do
103
+ delete :destroy, mongo_client_id: @client, id: @account
104
+ end
105
+ end
106
+ context 'but having ownership' do
107
+ should 'allow updates' do
108
+ put :update, mongo_client_id: @client, id: @account, mongo_account: { name: @account.name }
109
+ assert_redirected_to mongo_client_mongo_account_path(assigns(:mongo_account))
110
+ end
111
+ end
112
+ context 'having no ownership' do
113
+ should 'deny access' do
114
+ login_as(:guest)
115
+ assert_raises Trust::AccessDenied do
116
+ put :update, mongo_client_id: @client, id: @account, mongo_account: { name: @account.name }
117
+ end
118
+ end
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,74 @@
1
+ # Copyright (c) 2012 Bingo Entreprenøren AS
2
+ # Copyright (c) 2012 Teknobingo Scandinavia AS
3
+ # Copyright (c) 2012 Knut I. Stenmark
4
+ # Copyright (c) 2012 Patrick Hanevold
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining
7
+ # a copy of this software and associated documentation files (the
8
+ # "Software"), to deal in the Software without restriction, including
9
+ # without limitation the rights to use, copy, modify, merge, publish,
10
+ # distribute, sublicense, and/or sell copies of the Software, and to
11
+ # permit persons to whom the Software is furnished to do so, subject to
12
+ # the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be
15
+ # included in all copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
+
25
+ require 'test_helper'
26
+
27
+ class MongoClientsControllerTest < ActionController::TestCase
28
+ setup do
29
+ @client = MongoClient.create #clients(:one)
30
+ login_as(:system_admin)
31
+ end
32
+
33
+ test "should get index" do
34
+ get :index
35
+ assert_response :success
36
+ assert_not_nil assigns(:mongo_clients)
37
+ end
38
+
39
+ test "should get new" do
40
+ get :new
41
+ assert_response :success
42
+ end
43
+
44
+ test "should create client" do
45
+ assert_difference('MongoClient.count') do
46
+ post :create, mongo_client: { name: @client.name }
47
+ end
48
+
49
+ assert_redirected_to mongo_client_path(assigns(:mongo_client))
50
+ end
51
+
52
+ test "should show client" do
53
+ get :show, id: @client
54
+ assert_response :success
55
+ end
56
+
57
+ test "should get edit" do
58
+ get :edit, id: @client
59
+ assert_response :success
60
+ end
61
+
62
+ test "should update client" do
63
+ put :update, id: @client, mongo_client: { name: @client.name }
64
+ assert_redirected_to mongo_client_path(assigns(:mongo_client))
65
+ end
66
+
67
+ test "should destroy client" do
68
+ assert_difference('MongoClient.count', -1) do
69
+ delete :destroy, id: @client
70
+ end
71
+
72
+ assert_redirected_to mongo_clients_path
73
+ end
74
+ end
@@ -142,6 +142,118 @@ class PermissionsTest < ActiveSupport::TestCase
142
142
  assert !account.permits?(:update)
143
143
  end
144
144
  end
145
+ context 'MongoClient' do
146
+ should 'be managed by system admins' do
147
+ login_as(:system_admin)
148
+ assert MongoClient.permits?(:create)
149
+ assert MongoClient.new.permits?(:create)
150
+ end
151
+ should 'be audited by system admins' do
152
+ login_as(:system_admin)
153
+ assert MongoClient.permits?(:audit)
154
+ assert MongoClient.new.permits?(:audit)
155
+ end
156
+ should 'be managed by accauntants' do
157
+ login_as(:accountant)
158
+ assert MongoClient.permits?(:create)
159
+ assert MongoClient.new.permits?(:create)
160
+ end
161
+ should 'not be managed by guests' do
162
+ login_as(:guest)
163
+ assert !MongoClient.permits?(:create)
164
+ assert !MongoClient.new.permits?(:create)
165
+ end
166
+ should 'be read by all roles' do
167
+ Permissions::Default.all do |role|
168
+ login_as(role)
169
+ assert MongoClient.permits?(:read)
170
+ assert MongoClient.new.permits?(:read)
171
+ end
172
+ end
173
+ should 'not be read by other roles' do
174
+ login_as(:blind_man)
175
+ assert !MongoClient.permits?(:read)
176
+ assert !MongoClient.new.permits?(:read)
177
+ end
178
+ end
179
+ context 'MongoAccount' do
180
+ should 'be managed by system admins' do
181
+ login_as(:system_admin)
182
+ assert MongoAccount.permits?(:create)
183
+ assert MongoAccount.new.permits?(:create)
184
+ end
185
+ should 'be audited by system admins' do
186
+ login_as(:system_admin)
187
+ assert MongoAccount.permits?(:audit)
188
+ assert MongoAccount.new.permits?(:audit)
189
+ end
190
+ should 'not be managed by accauntants' do
191
+ login_as(:accountant)
192
+ assert !MongoAccount.permits?(:destroy)
193
+ assert !MongoAccount.new.permits?(:destroy)
194
+ assert !MongoAccount.permits?(:create)
195
+ assert !MongoAccount.new.permits?(:create)
196
+ end
197
+ should 'be created by accauntants associated to clients' do
198
+ login_as(:accountant)
199
+ parent = MongoClient.new
200
+ parent.expects(:accountant).returns(@user.name).twice
201
+ assert MongoAccount.permits?(:create,parent)
202
+ assert MongoAccount.new.permits?(:create,parent)
203
+ end
204
+ should 'not be created by accauntants unless associated to clients' do
205
+ login_as(:accountant)
206
+ parent = MongoClient.new
207
+ parent.expects(:accountant).returns(stub('bogus', :accountant => :bogus)).times(4)
208
+ assert !MongoAccount.permits?(:create,stub('bogus', :accountant => :bogus))
209
+ assert !MongoAccount.new.permits?(:create,stub('bogus', :accountant => :bogus))
210
+ assert !MongoAccount.permits?(:create,parent)
211
+ assert !MongoAccount.new.permits?(:create,parent)
212
+ end
213
+ should 'be created by department managers if parent is superspecial' do
214
+ login_as(:department_manager)
215
+ parent = MongoClient.new
216
+ parent.expects(:accountant).returns(:superspecial).twice
217
+ assert MongoAccount.permits?(:create,parent)
218
+ assert MongoAccount.new.permits?(:create,parent)
219
+ end
220
+ should 'be created by accauntants if parent is superspecial' do
221
+ login_as(:accountant)
222
+ parent = MongoClient.new
223
+ parent.expects(:accountant).returns(:superspecial).times(4)
224
+ assert MongoAccount.permits?(:create,parent)
225
+ assert MongoAccount.new.permits?(:create,parent)
226
+ end
227
+ should 'not be created by department managers unless parent is superspecial' do
228
+ login_as(:department_manager)
229
+ parent = MongoClient.new
230
+ parent.expects(:accountant).returns(:not_so_superspecial).twice
231
+ assert !MongoAccount.permits?(:create,parent)
232
+ assert !MongoAccount.new.permits?(:create,parent)
233
+ end
234
+ should 'not be created by accauntants unless parent is superspecial' do
235
+ login_as(:accountant)
236
+ parent = MongoClient.new
237
+ parent.expects(:accountant).returns(:not_so_superspecial).times(4)
238
+ assert !MongoAccount.permits?(:create,parent)
239
+ assert !MongoAccount.new.permits?(:create,parent)
240
+ end
241
+ should 'not be created by guests if parent' do
242
+ login_as(:guest)
243
+ assert !MongoAccount.permits?(:create)
244
+ assert !MongoAccount.new.permits?(:create)
245
+ end
246
+ should 'be updateable by creator' do
247
+ login_as(:accountant)
248
+ assert MongoAccount.create.permits?(:update)
249
+ end
250
+ should 'be not be updateable by others' do
251
+ login_as(:guest)
252
+ account = MongoAccount.create
253
+ login_as(:accountant)
254
+ assert !account.permits?(:update)
255
+ end
256
+ end
145
257
  context 'Account::Credit' do
146
258
  should 'be managed by system admins' do
147
259
  login_as(:system_admin)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trust
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.1
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Patrick Hanevold
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2012-06-06 00:00:00 Z
14
+ date: 2012-06-12 00:00:00 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
@@ -76,6 +76,8 @@ files:
76
76
  - test/dummy/app/controllers/accounts_controller.rb
77
77
  - test/dummy/app/controllers/application_controller.rb
78
78
  - test/dummy/app/controllers/clients_controller.rb
79
+ - test/dummy/app/controllers/mongo_accounts_controller.rb
80
+ - test/dummy/app/controllers/mongo_clients_controller.rb
79
81
  - test/dummy/app/controllers/savings_accounts_controller.rb
80
82
  - test/dummy/app/controllers/settlements_controller.rb
81
83
  - test/dummy/app/controllers/users_controller.rb
@@ -86,6 +88,8 @@ files:
86
88
  - test/dummy/app/models/account/credit.rb
87
89
  - test/dummy/app/models/account.rb
88
90
  - test/dummy/app/models/client.rb
91
+ - test/dummy/app/models/mongo_account.rb
92
+ - test/dummy/app/models/mongo_client.rb
89
93
  - test/dummy/app/models/permissions.rb
90
94
  - test/dummy/app/models/savings_account.rb
91
95
  - test/dummy/app/models/user.rb
@@ -100,6 +104,16 @@ files:
100
104
  - test/dummy/app/views/clients/new.html.erb
101
105
  - test/dummy/app/views/clients/show.html.erb
102
106
  - test/dummy/app/views/layouts/application.html.erb
107
+ - test/dummy/app/views/mongo_accounts/_form.html.erb
108
+ - test/dummy/app/views/mongo_accounts/edit.html.erb
109
+ - test/dummy/app/views/mongo_accounts/index.html.erb
110
+ - test/dummy/app/views/mongo_accounts/new.html.erb
111
+ - test/dummy/app/views/mongo_accounts/show.html.erb
112
+ - test/dummy/app/views/mongo_clients/_form.html.erb
113
+ - test/dummy/app/views/mongo_clients/edit.html.erb
114
+ - test/dummy/app/views/mongo_clients/index.html.erb
115
+ - test/dummy/app/views/mongo_clients/new.html.erb
116
+ - test/dummy/app/views/mongo_clients/show.html.erb
103
117
  - test/dummy/app/views/users/_form.html.erb
104
118
  - test/dummy/app/views/users/edit.html.erb
105
119
  - test/dummy/app/views/users/index.html.erb
@@ -119,6 +133,7 @@ files:
119
133
  - test/dummy/config/initializers/session_store.rb
120
134
  - test/dummy/config/initializers/wrap_parameters.rb
121
135
  - test/dummy/config/locales/en.yml
136
+ - test/dummy/config/mongoid.yml
122
137
  - test/dummy/config/routes.rb
123
138
  - test/dummy/config.ru
124
139
  - test/dummy/db/development.sqlite3
@@ -141,6 +156,8 @@ files:
141
156
  - test/dummy/test/fixtures/users.yml
142
157
  - test/dummy/test/functional/accounts_controller_test.rb
143
158
  - test/dummy/test/functional/clients_controller_test.rb
159
+ - test/dummy/test/functional/mongo_accounts_controller_test.rb
160
+ - test/dummy/test/functional/mongo_clients_controller_test.rb
144
161
  - test/dummy/test/functional/users_controller_test.rb
145
162
  - test/dummy/test/unit/account_test.rb
146
163
  - test/dummy/test/unit/client_test.rb
@@ -171,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
188
  requirements:
172
189
  - - ">="
173
190
  - !ruby/object:Gem::Version
174
- hash: -3354325464732942508
191
+ hash: 3291721563323064298
175
192
  segments:
176
193
  - 0
177
194
  version: "0"
@@ -180,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
197
  requirements:
181
198
  - - ">="
182
199
  - !ruby/object:Gem::Version
183
- hash: -3354325464732942508
200
+ hash: 3291721563323064298
184
201
  segments:
185
202
  - 0
186
203
  version: "0"
@@ -204,6 +221,8 @@ test_files:
204
221
  - test/dummy/app/controllers/accounts_controller.rb
205
222
  - test/dummy/app/controllers/application_controller.rb
206
223
  - test/dummy/app/controllers/clients_controller.rb
224
+ - test/dummy/app/controllers/mongo_accounts_controller.rb
225
+ - test/dummy/app/controllers/mongo_clients_controller.rb
207
226
  - test/dummy/app/controllers/savings_accounts_controller.rb
208
227
  - test/dummy/app/controllers/settlements_controller.rb
209
228
  - test/dummy/app/controllers/users_controller.rb
@@ -214,6 +233,8 @@ test_files:
214
233
  - test/dummy/app/models/account/credit.rb
215
234
  - test/dummy/app/models/account.rb
216
235
  - test/dummy/app/models/client.rb
236
+ - test/dummy/app/models/mongo_account.rb
237
+ - test/dummy/app/models/mongo_client.rb
217
238
  - test/dummy/app/models/permissions.rb
218
239
  - test/dummy/app/models/savings_account.rb
219
240
  - test/dummy/app/models/user.rb
@@ -228,6 +249,16 @@ test_files:
228
249
  - test/dummy/app/views/clients/new.html.erb
229
250
  - test/dummy/app/views/clients/show.html.erb
230
251
  - test/dummy/app/views/layouts/application.html.erb
252
+ - test/dummy/app/views/mongo_accounts/_form.html.erb
253
+ - test/dummy/app/views/mongo_accounts/edit.html.erb
254
+ - test/dummy/app/views/mongo_accounts/index.html.erb
255
+ - test/dummy/app/views/mongo_accounts/new.html.erb
256
+ - test/dummy/app/views/mongo_accounts/show.html.erb
257
+ - test/dummy/app/views/mongo_clients/_form.html.erb
258
+ - test/dummy/app/views/mongo_clients/edit.html.erb
259
+ - test/dummy/app/views/mongo_clients/index.html.erb
260
+ - test/dummy/app/views/mongo_clients/new.html.erb
261
+ - test/dummy/app/views/mongo_clients/show.html.erb
231
262
  - test/dummy/app/views/users/_form.html.erb
232
263
  - test/dummy/app/views/users/edit.html.erb
233
264
  - test/dummy/app/views/users/index.html.erb
@@ -247,6 +278,7 @@ test_files:
247
278
  - test/dummy/config/initializers/session_store.rb
248
279
  - test/dummy/config/initializers/wrap_parameters.rb
249
280
  - test/dummy/config/locales/en.yml
281
+ - test/dummy/config/mongoid.yml
250
282
  - test/dummy/config/routes.rb
251
283
  - test/dummy/config.ru
252
284
  - test/dummy/db/development.sqlite3
@@ -269,6 +301,8 @@ test_files:
269
301
  - test/dummy/test/fixtures/users.yml
270
302
  - test/dummy/test/functional/accounts_controller_test.rb
271
303
  - test/dummy/test/functional/clients_controller_test.rb
304
+ - test/dummy/test/functional/mongo_accounts_controller_test.rb
305
+ - test/dummy/test/functional/mongo_clients_controller_test.rb
272
306
  - test/dummy/test/functional/users_controller_test.rb
273
307
  - test/dummy/test/unit/account_test.rb
274
308
  - test/dummy/test/unit/client_test.rb