File tree Expand file tree Collapse file tree 4 files changed +50
-2
lines changed
test-harness/tests/specs/unit Expand file tree Collapse file tree 4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" :" ColdBox Security" ,
3
- "version" :" 2.10 .0" ,
3
+ "version" :" 2.11 .0" ,
4
4
"location" :
" https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbsecurity/@build.version@/[email protected] @.zip" ,
5
5
"author" :
" Ortus Solutions.com <[email protected] >" ,
6
6
"slug" :" cbsecurity" ,
Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
----
9
9
10
+ ## [ 2.11.0] => 2021-MAR-10
11
+
12
+ ### Added
13
+
14
+ * Add a ` secureSameUser ` method to throw when passed a different user #29 (https://github.com/coldbox-modules/cbsecurity/pull/29 )
15
+
16
+ ----
17
+
10
18
## [ 2.10.0] => 2021-FEB-12
11
19
12
20
### Added
Original file line number Diff line number Diff line change @@ -258,9 +258,33 @@ component singleton accessors="true" {
258
258
}
259
259
if ( results ) {
260
260
throw ( type = " NotAuthorized" , message = arguments .message );
261
+ }
262
+ return this ;
263
+ }
264
+
265
+ /**
266
+ * Verifies that the passed in user object must be the same as the authenticated user.
267
+ * Equality is done by evaluating the `getid()` method on both objects.
268
+ * If the equality check fails, a `NotAuthorized` exception is thrown.
269
+ *
270
+ * @throws NoUserLoggedIn
271
+ * @throws NotAuthorized
272
+ *
273
+ * @user The user to test for equality
274
+ * @message The error message to throw in the exception
275
+ */
276
+ CBSecurity function secureSameUser (
277
+ required user ,
278
+ message = variables .DEFAULT_ERROR_MESSAGE
279
+ ){
280
+ if ( ! sameUser ( arguments .user ) ) {
281
+ throw (
282
+ type = " NotAuthorized" ,
283
+ message = arguments .message
284
+ );
261
285
}
262
286
return this ;
263
- }
287
+ }
264
288
265
289
/**
266
290
* Alias proxy if somebody is coming from cbguard, proxies to the secure() method
Original file line number Diff line number Diff line change @@ -301,6 +301,22 @@ component extends="coldbox.system.testing.BaseModelTest" model="cbsecurity.model
301
301
cbsecurity .secureWhen ( function ( user ){ return false ; } );
302
302
});
303
303
});
304
+ describe ( " secureSameUser() method" , function (){
305
+ it ( " can secure if the logged in user is not the user passed" , function (){
306
+ mockUser .$( " getId" , 1 );
307
+ var testUser = createStub ().$( " getId" , 2 );
308
+
309
+ expect ( function (){
310
+ cbsecurity .secureSameUser ( testUser );
311
+ }).toThrow ( " NotAuthorized" );
312
+ });
313
+
314
+ it ( " can allow if the logged in user is the user passed" , function (){
315
+ mockUser .$( " getId" , 1 );
316
+ var testUser = createStub ().$( " getId" , 1 );
317
+ cbsecurity .secureSameUser ( testUser );
318
+ });
319
+ });
304
320
});
305
321
306
322
});
You can’t perform that action at this time.
0 commit comments