Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
 into ldap-auth-support
  • Loading branch information
brodo committed Nov 20, 2019
2 parents 6c97b00 + 5ed0885 commit 3017ef2
Show file tree
Hide file tree
Showing 7 changed files with 273 additions and 15 deletions.
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 38 additions & 2 deletions spec/CloudCode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2219,10 +2219,14 @@ describe('afterFind hooks', () => {
it('should validate triggers correctly', () => {
expect(() => {
Parse.Cloud.beforeSave('_Session', () => {});
}).toThrow('Triggers are not supported for _Session class.');
}).toThrow(
'Only the afterLogout trigger is allowed for the _Session class.'
);
expect(() => {
Parse.Cloud.afterSave('_Session', () => {});
}).toThrow('Triggers are not supported for _Session class.');
}).toThrow(
'Only the afterLogout trigger is allowed for the _Session class.'
);
expect(() => {
Parse.Cloud.beforeSave('_PushStatus', () => {});
}).toThrow('Only afterSave is allowed on _PushStatus');
Expand All @@ -2247,6 +2251,22 @@ describe('afterFind hooks', () => {
expect(() => {
Parse.Cloud.beforeLogin('SomeClass', () => {});
}).toThrow('Only the _User class is allowed for the beforeLogin trigger');
expect(() => {
Parse.Cloud.afterLogout(() => {});
}).not.toThrow();
expect(() => {
Parse.Cloud.afterLogout('_Session', () => {});
}).not.toThrow();
expect(() => {
Parse.Cloud.afterLogout('_User', () => {});
}).toThrow(
'Only the _Session class is allowed for the afterLogout trigger.'
);
expect(() => {
Parse.Cloud.afterLogout('SomeClass', () => {});
}).toThrow(
'Only the _Session class is allowed for the afterLogout trigger.'
);
});

it('should skip afterFind hooks for aggregate', done => {
Expand Down Expand Up @@ -2436,6 +2456,22 @@ describe('beforeLogin hook', () => {
done();
});

it('should trigger afterLogout hook on logout', async done => {
let userId;
Parse.Cloud.afterLogout(req => {
expect(req.object.className).toEqual('_Session');
expect(req.object.id).toBeDefined();
const user = req.object.get('user');
expect(user).toBeDefined();
userId = user.id;
});

const user = await Parse.User.signUp('user', 'pass');
await Parse.User.logOut();
expect(user.id).toBe(userId);
done();
});

it('should have expected data in request', async done => {
Parse.Cloud.beforeLogin(req => {
expect(req.object).toBeDefined();
Expand Down
18 changes: 9 additions & 9 deletions spec/LdapAuth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ it('Should fail with missing options', done => {
});

it('Should succeed with right credentials', done => {
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
const options = {
suffix: 'o=example',
url: 'ldap://localhost:1010',
url: 'ldap://localhost:12345',
dn: 'uid={{id}}, o=example',
};
ldap
Expand All @@ -26,10 +26,10 @@ it('Should succeed with right credentials', done => {
});

it('Should fail with wrong credentials', done => {
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
const options = {
suffix: 'o=example',
url: 'ldap://localhost:1010',
url: 'ldap://localhost:12345',
dn: 'uid={{id}}, o=example',
};
ldap
Expand All @@ -44,10 +44,10 @@ it('Should fail with wrong credentials', done => {
});

it('Should succeed if user is in given group', done => {
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
const options = {
suffix: 'o=example',
url: 'ldap://localhost:1010',
url: 'ldap://localhost:12345',
dn: 'uid={{id}}, o=example',
groupCn: 'powerusers',
groupFilter:
Expand All @@ -63,12 +63,12 @@ it('Should succeed if user is in given group', done => {
});

it('Should fail if user is not in given group', done => {
mockLdapServer(1010, 'uid=testuser, o=example').then(server => {
mockLdapServer(12345, 'uid=testuser, o=example').then(server => {
const options = {
suffix: 'o=example',
url: 'ldap://localhost:1010',
url: 'ldap://localhost:12345',
dn: 'uid={{id}}, o=example',
groupDn: 'ou=somegroup, o=example',
groupCn: 'ou=somegroup, o=example',
groupFilter:
'(&(uniqueMember=uid={{id}}, o=example)(objectClass=groupOfUniqueNames))',
};
Expand Down
18 changes: 18 additions & 0 deletions spec/ParseUser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1523,6 +1523,24 @@ describe('Parse.User testing', () => {
done();
});

it('logout with provider should call afterLogout trigger', async done => {
const provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);

let userId;
Parse.Cloud.afterLogout(req => {
expect(req.object.className).toEqual('_Session');
expect(req.object.id).toBeDefined();
const user = req.object.get('user');
expect(user).toBeDefined();
userId = user.id;
});
const user = await Parse.User._logInWith('facebook');
await Parse.User.logOut();
expect(user.id).toBe(userId);
done();
});

it('link with provider', async done => {
const provider = getMockFacebookProvider();
Parse.User._registerAuthenticationProvider(provider);
Expand Down
12 changes: 12 additions & 0 deletions src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ export class UsersRouter extends ClassesRouter {
records.results[0].objectId
)
.then(() => {
this._runAfterLogoutTrigger(req, records.results[0]);
return Promise.resolve(success);
});
}
Expand All @@ -311,6 +312,17 @@ export class UsersRouter extends ClassesRouter {
return Promise.resolve(success);
}

_runAfterLogoutTrigger(req, session) {
// After logout trigger
maybeRunTrigger(
TriggerTypes.afterLogout,
req.auth,
Parse.Session.fromJSON(Object.assign({ className: '_Session' }, session)),
null,
req.config
);
}

_throwOnBadEmailConfig(req) {
try {
Config.validateEmailConfiguration({
Expand Down
Loading

0 comments on commit 3017ef2

Please sign in to comment.