Skip to content

Commit 3017ef2

Browse files
committed
Merge branch 'master' of https://github.com/parse-community/parse-server into ldap-auth-support
2 parents 6c97b00 + 5ed0885 commit 3017ef2

File tree

7 files changed

+273
-15
lines changed

7 files changed

+273
-15
lines changed

package-lock.json

Lines changed: 150 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/CloudCode.spec.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,10 +2219,14 @@ describe('afterFind hooks', () => {
22192219
it('should validate triggers correctly', () => {
22202220
expect(() => {
22212221
Parse.Cloud.beforeSave('_Session', () => {});
2222-
}).toThrow('Triggers are not supported for _Session class.');
2222+
}).toThrow(
2223+
'Only the afterLogout trigger is allowed for the _Session class.'
2224+
);
22232225
expect(() => {
22242226
Parse.Cloud.afterSave('_Session', () => {});
2225-
}).toThrow('Triggers are not supported for _Session class.');
2227+
}).toThrow(
2228+
'Only the afterLogout trigger is allowed for the _Session class.'
2229+
);
22262230
expect(() => {
22272231
Parse.Cloud.beforeSave('_PushStatus', () => {});
22282232
}).toThrow('Only afterSave is allowed on _PushStatus');
@@ -2247,6 +2251,22 @@ describe('afterFind hooks', () => {
22472251
expect(() => {
22482252
Parse.Cloud.beforeLogin('SomeClass', () => {});
22492253
}).toThrow('Only the _User class is allowed for the beforeLogin trigger');
2254+
expect(() => {
2255+
Parse.Cloud.afterLogout(() => {});
2256+
}).not.toThrow();
2257+
expect(() => {
2258+
Parse.Cloud.afterLogout('_Session', () => {});
2259+
}).not.toThrow();
2260+
expect(() => {
2261+
Parse.Cloud.afterLogout('_User', () => {});
2262+
}).toThrow(
2263+
'Only the _Session class is allowed for the afterLogout trigger.'
2264+
);
2265+
expect(() => {
2266+
Parse.Cloud.afterLogout('SomeClass', () => {});
2267+
}).toThrow(
2268+
'Only the _Session class is allowed for the afterLogout trigger.'
2269+
);
22502270
});
22512271

22522272
it('should skip afterFind hooks for aggregate', done => {
@@ -2436,6 +2456,22 @@ describe('beforeLogin hook', () => {
24362456
done();
24372457
});
24382458

2459+
it('should trigger afterLogout hook on logout', async done => {
2460+
let userId;
2461+
Parse.Cloud.afterLogout(req => {
2462+
expect(req.object.className).toEqual('_Session');
2463+
expect(req.object.id).toBeDefined();
2464+
const user = req.object.get('user');
2465+
expect(user).toBeDefined();
2466+
userId = user.id;
2467+
});
2468+
2469+
const user = await Parse.User.signUp('user', 'pass');
2470+
await Parse.User.logOut();
2471+
expect(user.id).toBe(userId);
2472+
done();
2473+
});
2474+
24392475
it('should have expected data in request', async done => {
24402476
Parse.Cloud.beforeLogin(req => {
24412477
expect(req.object).toBeDefined();

spec/LdapAuth.spec.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ it('Should fail with missing options', done => {
1111
});
1212

1313
it('Should succeed with right credentials', done => {
14-
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
14+
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
1515
const options = {
1616
suffix: 'o=example',
17-
url: 'ldap://localhost:1010',
17+
url: 'ldap://localhost:12345',
1818
dn: 'uid={{id}}, o=example',
1919
};
2020
ldap
@@ -26,10 +26,10 @@ it('Should succeed with right credentials', done => {
2626
});
2727

2828
it('Should fail with wrong credentials', done => {
29-
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
29+
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
3030
const options = {
3131
suffix: 'o=example',
32-
url: 'ldap://localhost:1010',
32+
url: 'ldap://localhost:12345',
3333
dn: 'uid={{id}}, o=example',
3434
};
3535
ldap
@@ -44,10 +44,10 @@ it('Should fail with wrong credentials', done => {
4444
});
4545

4646
it('Should succeed if user is in given group', done => {
47-
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
47+
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
4848
const options = {
4949
suffix: 'o=example',
50-
url: 'ldap://localhost:1010',
50+
url: 'ldap://localhost:12345',
5151
dn: 'uid={{id}}, o=example',
5252
groupCn: 'powerusers',
5353
groupFilter:
@@ -63,12 +63,12 @@ it('Should succeed if user is in given group', done => {
6363
});
6464

6565
it('Should fail if user is not in given group', done => {
66-
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
66+
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
6767
const options = {
6868
suffix: 'o=example',
69-
url: 'ldap://localhost:1010',
69+
url: 'ldap://localhost:12345',
7070
dn: 'uid={{id}}, o=example',
71-
groupDn: 'ou=somegroup, o=example',
71+
groupCn: 'ou=somegroup, o=example',
7272
groupFilter:
7373
'(&(uniqueMember=uid={{id}}, o=example)(objectClass=groupOfUniqueNames))',
7474
};

spec/ParseUser.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,24 @@ describe('Parse.User testing', () => {
15231523
done();
15241524
});
15251525

1526+
it('logout with provider should call afterLogout trigger', async done => {
1527+
const provider = getMockFacebookProvider();
1528+
Parse.User._registerAuthenticationProvider(provider);
1529+
1530+
let userId;
1531+
Parse.Cloud.afterLogout(req => {
1532+
expect(req.object.className).toEqual('_Session');
1533+
expect(req.object.id).toBeDefined();
1534+
const user = req.object.get('user');
1535+
expect(user).toBeDefined();
1536+
userId = user.id;
1537+
});
1538+
const user = await Parse.User._logInWith('facebook');
1539+
await Parse.User.logOut();
1540+
expect(user.id).toBe(userId);
1541+
done();
1542+
});
1543+
15261544
it('link with provider', async done => {
15271545
const provider = getMockFacebookProvider();
15281546
Parse.User._registerAuthenticationProvider(provider);

src/Routers/UsersRouter.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ export class UsersRouter extends ClassesRouter {
302302
records.results[0].objectId
303303
)
304304
.then(() => {
305+
this._runAfterLogoutTrigger(req, records.results[0]);
305306
return Promise.resolve(success);
306307
});
307308
}
@@ -311,6 +312,17 @@ export class UsersRouter extends ClassesRouter {
311312
return Promise.resolve(success);
312313
}
313314

315+
_runAfterLogoutTrigger(req, session) {
316+
// After logout trigger
317+
maybeRunTrigger(
318+
TriggerTypes.afterLogout,
319+
req.auth,
320+
Parse.Session.fromJSON(Object.assign({ className: '_Session' }, session)),
321+
null,
322+
req.config
323+
);
324+
}
325+
314326
_throwOnBadEmailConfig(req) {
315327
try {
316328
Config.validateEmailConfiguration({

0 commit comments

Comments
 (0)