From ebcf9136765c91fd79c96bd78008a69e58c49a7d Mon Sep 17 00:00:00 2001 From: Victor Piousbox Date: Sun, 20 Mar 2016 19:00:23 +0000 Subject: [PATCH] strengthen the test of password-reset just a little --- .../DELETE-user_auth_social_network.test.js | 40 +++++++++++++++++++ .../auth/POST-user_reset_password.test.js | 3 ++ 2 files changed, 43 insertions(+) create mode 100644 test/api/v3/integration/user/auth/DELETE-user_auth_social_network.test.js diff --git a/test/api/v3/integration/user/auth/DELETE-user_auth_social_network.test.js b/test/api/v3/integration/user/auth/DELETE-user_auth_social_network.test.js new file mode 100644 index 0000000000..e589256346 --- /dev/null +++ b/test/api/v3/integration/user/auth/DELETE-user_auth_social_network.test.js @@ -0,0 +1,40 @@ +import { + generateUser, + translate as t, +} from '../../../../../helpers/api-integration/v3'; + +describe('DELETE social registration', () => { + let user; + let endpoint = '/user/auth/social/facebook'; + beforeEach(async () => { + user = await generateUser(); + await user.update({ 'auth.facebook.id': 'some-fb-id' }); + expect(user.auth.local.username).to.not.be.empty; + expect(user.auth.facebook).to.not.be.empty; + }); + context('of NOT-FACEBOOK', () => { + it('is not supported', async () => { + expect(user.del('/user/auth/social/SOME-OTHER-NETWORK')).to.eventually.be.rejected.and.eql({ + code: 400, + error: 'NotAuthorized', + message: t('onlyFbSupported'), + }); + }); + }); + context('of facebook', () => { + it('fails if local registration does not exist for this user', async () => { + await user.update({ 'auth.local': { ok: true } }); + expect(user.del(endpoint)).to.eventually.be.rejected.and.eql({ + code: 400, + error: 'NotAuthorized', + message: t('cantDetachFb'), + }); + }); + it('succeeds', async () => { + let response = await user.del(endpoint); + expect(response).to.eql({}); + await user.sync(); + expect(user.auth.facebook).to.be.empty; + }); + }); +}); diff --git a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js index 34612106d6..6116f67a35 100644 --- a/test/api/v3/integration/user/auth/POST-user_reset_password.test.js +++ b/test/api/v3/integration/user/auth/POST-user_reset_password.test.js @@ -12,10 +12,13 @@ describe('POST /user/reset-password', async () => { }); it('resets password', async () => { + let previousPassword = user.auth.local.hashed_password; let response = await user.post(endpoint, { email: user.auth.local.email, }); expect(response).to.eql({ message: t('passwordReset') }); + await user.sync(); + expect(user.auth.local.hashed_password).to.not.eql(previousPassword); }); it('same message on error as on success', async () => {