From 6e34585dfd7f99cb747f037cc0d0b60eb99cecba Mon Sep 17 00:00:00 2001 From: Thomas Rittson Date: Wed, 15 Dec 2021 11:10:15 +1000 Subject: [PATCH] Add test for captcha --- spec/common/services/auth.service.spec.ts | 26 ++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/spec/common/services/auth.service.spec.ts b/spec/common/services/auth.service.spec.ts index df8211e1..848bedb5 100644 --- a/spec/common/services/auth.service.spec.ts +++ b/spec/common/services/auth.service.spec.ts @@ -136,7 +136,7 @@ describe('Cipher Service', () => { return tokenResponse; } - it('logIn method: simple call: no 2FA, captcha or password reset', async () => { + it('logIn: simple call: no 2FA, captcha or password reset', async () => { logInSetup(); commonSetup(); const tokenResponse = newTokenResponse(); @@ -180,4 +180,28 @@ describe('Cipher Service', () => { // Return result: expect(result).toEqual(expected); }); + + + it('logIn: bails out if captchaSiteKey is true', async () => { + const siteKey = 'CAPTCHA_SITE_KEY'; + + logInSetup(); + commonSetup(); + const tokenResponse = newTokenResponse(); + (tokenResponse as any).siteKey = siteKey; + + tokenService.getTwoFactorToken(email).resolves(null); + apiService.postIdentityToken(Arg.any()).resolves(tokenResponse); + + const expected = new AuthResult(); + expected.captchaSiteKey = siteKey; + + // Act + const result = await authService.logIn(email, masterPassword); + + // Assertions + stateService.didNotReceive().addAccount(Arg.any()); + messagingService.didNotReceive().send(Arg.any()); + expect(result).toEqual(expected); + }); });