File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -1546,9 +1546,7 @@ describe('Cloud Code', () => {
1546
1546
1547
1547
request ( {
1548
1548
method : 'POST' ,
1549
- url : `http://${ Parse . applicationId } :${
1550
- Parse . masterKey
1551
- } @localhost:8378/1/jobs/myJob`,
1549
+ url : `http://${ Parse . applicationId } :${ Parse . masterKey } @localhost:8378/1/jobs/myJob` ,
1552
1550
} ) . then (
1553
1551
( ) => { } ,
1554
1552
err => {
@@ -2383,6 +2381,31 @@ describe('beforeLogin hook', () => {
2383
2381
done ( ) ;
2384
2382
} ) ;
2385
2383
2384
+ it ( 'should be able to block login if an error is thrown even if the user has a attached file' , async done => {
2385
+ let hit = 0 ;
2386
+ Parse . Cloud . beforeLogin ( req => {
2387
+ hit ++ ;
2388
+ if ( req . object . get ( 'isBanned' ) ) {
2389
+ throw new Error ( 'banned account' ) ;
2390
+ }
2391
+ } ) ;
2392
+
2393
+ const user = await Parse . User . signUp ( 'tupac' , 'shakur' ) ;
2394
+ const base64 = 'V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=' ;
2395
+ const file = new Parse . File ( 'myfile.txt' , { base64 } ) ;
2396
+ await file . save ( ) ;
2397
+ await user . save ( { isBanned : true , file } ) ;
2398
+
2399
+ try {
2400
+ await Parse . User . logIn ( 'tupac' , 'shakur' ) ;
2401
+ throw new Error ( 'should not have been logged in.' ) ;
2402
+ } catch ( e ) {
2403
+ expect ( e . message ) . toBe ( 'banned account' ) ;
2404
+ }
2405
+ expect ( hit ) . toBe ( 1 ) ;
2406
+ done ( ) ;
2407
+ } ) ;
2408
+
2386
2409
it ( 'should not run beforeLogin with incorrect credentials' , async done => {
2387
2410
let hit = 0 ;
2388
2411
Parse . Cloud . beforeLogin ( req => {
Original file line number Diff line number Diff line change @@ -241,6 +241,8 @@ export class UsersRouter extends ClassesRouter {
241
241
// Remove hidden properties.
242
242
UsersRouter . removeHiddenProperties ( user ) ;
243
243
244
+ req . config . filesController . expandFilesInObject ( req . config , user ) ;
245
+
244
246
// Before login trigger; throws if failure
245
247
await maybeRunTrigger (
246
248
TriggerTypes . beforeLogin ,
@@ -261,8 +263,6 @@ export class UsersRouter extends ClassesRouter {
261
263
262
264
user . sessionToken = sessionData . sessionToken ;
263
265
264
- req . config . filesController . expandFilesInObject ( req . config , user ) ;
265
-
266
266
await createSession ( ) ;
267
267
return { response : user } ;
268
268
}
You can’t perform that action at this time.
0 commit comments