Skip to content

Commit 9113c99

Browse files
committed
undo log error
1 parent c18519c commit 9113c99

File tree

1 file changed

+42
-47
lines changed

1 file changed

+42
-47
lines changed

spec/ParseUser.MFA.spec.js

+42-47
Original file line numberDiff line numberDiff line change
@@ -54,54 +54,49 @@ describe('MFA', () => {
5454
}
5555

5656
it('should enable MFA tokens', async () => {
57-
try {
58-
await reconfigureServer({
59-
multiFactorAuth: {
60-
enableMfa: true,
61-
encryptionKey: '89E4AFF1-DFE4-4603-9574-BFA16BB446FD',
62-
},
63-
appName: 'testApp',
64-
});
65-
const user = await Parse.User.signUp('username', 'password');
66-
const {
67-
data: { secret, qrcodeURL },
68-
} = await enableMfa(user); // this function would be user.enable2FA() one SDK is updated
69-
expect(qrcodeURL).toBeDefined();
70-
expect(qrcodeURL).toContain('otpauth://totp/testApp');
71-
expect(qrcodeURL).toContain('secret');
72-
expect(qrcodeURL).toContain('username');
73-
expect(qrcodeURL).toContain('period');
74-
expect(qrcodeURL).toContain('digits');
75-
expect(qrcodeURL).toContain('algorithm');
76-
const token = otplib.authenticator.generate(secret); // this token would be generated from authenticator
77-
await verifyMfa(user, token); // this function would be user.verifyMfa()
78-
await Parse.User.logOut();
79-
let verifytoken = '';
80-
const mfaLogin = async () => {
81-
try {
82-
const result = await loginWithMFA('username', 'password', verifytoken); // Parse.User.login('username','password',verifytoken);
83-
if (!verifytoken) {
84-
throw 'Should not have been able to login.';
85-
}
86-
const newUser = result.data;
87-
expect(newUser.objectId).toBe(user.id);
88-
expect(newUser.username).toBe('username');
89-
expect(newUser.createdAt).toBe(user.createdAt.toISOString());
90-
expect(newUser.mfaEnabled).toBe(true);
91-
} catch (err) {
92-
expect(err.text).toMatch('{"code":211,"error":"Please provide your MFA token."}');
93-
verifytoken = otplib.authenticator.generate(secret);
94-
if (err.text.includes('211')) {
95-
// this user is 2FA enroled, get code
96-
await mfaLogin();
97-
}
57+
await reconfigureServer({
58+
multiFactorAuth: {
59+
enableMfa: true,
60+
encryptionKey: '89E4AFF1-DFE4-4603-9574-BFA16BB446FD',
61+
},
62+
appName: 'testApp',
63+
});
64+
const user = await Parse.User.signUp('username', 'password');
65+
const {
66+
data: { secret, qrcodeURL },
67+
} = await enableMfa(user); // this function would be user.enable2FA() one SDK is updated
68+
expect(qrcodeURL).toBeDefined();
69+
expect(qrcodeURL).toContain('otpauth://totp/testApp');
70+
expect(qrcodeURL).toContain('secret');
71+
expect(qrcodeURL).toContain('username');
72+
expect(qrcodeURL).toContain('period');
73+
expect(qrcodeURL).toContain('digits');
74+
expect(qrcodeURL).toContain('algorithm');
75+
const token = otplib.authenticator.generate(secret); // this token would be generated from authenticator
76+
await verifyMfa(user, token); // this function would be user.verifyMfa()
77+
await Parse.User.logOut();
78+
let verifytoken = '';
79+
const mfaLogin = async () => {
80+
try {
81+
const result = await loginWithMFA('username', 'password', verifytoken); // Parse.User.login('username','password',verifytoken);
82+
if (!verifytoken) {
83+
throw 'Should not have been able to login.';
9884
}
99-
};
100-
await mfaLogin();
101-
} catch (e) {
102-
console.log(e);
103-
throw e;
104-
}
85+
const newUser = result.data;
86+
expect(newUser.objectId).toBe(user.id);
87+
expect(newUser.username).toBe('username');
88+
expect(newUser.createdAt).toBe(user.createdAt.toISOString());
89+
expect(newUser.mfaEnabled).toBe(true);
90+
} catch (err) {
91+
expect(err.text).toMatch('{"code":211,"error":"Please provide your MFA token."}');
92+
verifytoken = otplib.authenticator.generate(secret);
93+
if (err.text.includes('211')) {
94+
// this user is 2FA enroled, get code
95+
await mfaLogin();
96+
}
97+
}
98+
};
99+
await mfaLogin();
105100
});
106101

107102
it('can reject MFA', async () => {

0 commit comments

Comments
 (0)