Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 9c433ba

Browse files
authored
fix(verify): update verifyWithMethod to update a session verification status (#329), r=@philbooth
1 parent 1361ba4 commit 9c433ba

File tree

6 files changed

+69
-3
lines changed

6 files changed

+69
-3
lines changed

db-server/test/backend/db_tests.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,30 @@ module.exports = function (config, DB) {
19561956
})
19571957
})
19581958

1959+
it('should update session verificationMethod', () => {
1960+
const verifyOptions = {
1961+
verificationMethod: 'totp-2fa'
1962+
}
1963+
return db.verifyTokens(sessionToken.tokenVerificationId, account)
1964+
.then(() => {
1965+
return db.sessionToken(tokenId)
1966+
}, assert.fail)
1967+
.then((token) => {
1968+
assert.equal(token.mustVerify, false, 'mustVerify is false')
1969+
assert.equal(token.tokenVerificationId, null, 'tokenVerificationId is null')
1970+
assert.equal(token.verificationMethod, null, 'verificationMethod is null')
1971+
return db.verifyTokensWithMethod(tokenId, verifyOptions)
1972+
})
1973+
.then(() => {
1974+
return db.sessionToken(tokenId)
1975+
}, assert.fail)
1976+
.then((token) => {
1977+
assert.equal(token.mustVerify, false, 'mustVerify is false')
1978+
assert.equal(token.tokenVerificationId, null, 'tokenVerificationId is null')
1979+
assert.equal(token.verificationMethod, 2, 'verificationMethod is set')
1980+
})
1981+
})
1982+
19591983
it('should fail to verify unknown verification method', () => {
19601984
const verifyOptions = {
19611985
verificationMethod: 'super-invalid-method'

lib/db/mem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ module.exports = function (log, error) {
558558
item.authAt = sessionTokens[id].authAt || sessionTokens[id].createdAt
559559
item.verificationMethod = sessionTokens[id].verificationMethod || null
560560
item.verifiedAt = sessionTokens[id].verifiedAt || null
561-
item.mustVerify = sessionTokens[id].mustVerify || null
561+
item.mustVerify = !! sessionTokens[id].mustVerify
562562

563563
var accountId = sessionTokens[id].uid.toString('hex')
564564
var account = accounts[accountId]

lib/db/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ module.exports = function (log, error) {
13881388
})
13891389
}
13901390

1391-
const VERIFY_SESSION_WITH_METHOD = 'CALL verifyTokensWithMethod_1(?, ?, ?)'
1391+
const VERIFY_SESSION_WITH_METHOD = 'CALL verifyTokensWithMethod_2(?, ?, ?)'
13921392
MySql.prototype.verifyTokensWithMethod = function (tokenId, data) {
13931393
return P.resolve()
13941394
.then(() => {

lib/db/patch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
// The expected patch level of the database. Update if you add a new
66
// patch in the ./schema/ directory.
7-
module.exports.level = 75
7+
module.exports.level = 76

lib/db/schema/patch-075-076.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
SET NAMES utf8mb4 COLLATE utf8mb4_bin;
2+
3+
CREATE PROCEDURE `verifyTokensWithMethod_2` (
4+
IN `tokenIdArg` BINARY(32),
5+
IN `verificationMethodArg` INT,
6+
IN `verifiedAtArg` BIGINT(1)
7+
)
8+
BEGIN
9+
DECLARE EXIT HANDLER FOR SQLEXCEPTION
10+
BEGIN
11+
ROLLBACK;
12+
RESIGNAL;
13+
END;
14+
15+
START TRANSACTION;
16+
-- Update session verification methods
17+
UPDATE `sessionTokens` SET verificationMethod = verificationMethodArg, verifiedAt = verifiedAtArg
18+
WHERE tokenId = tokenIdArg;
19+
20+
SET @updateCount = (SELECT ROW_COUNT());
21+
22+
-- Get the tokenVerificationId and uid for session
23+
SET @tokenVerificationId = NULL;
24+
SET @uid = NULL;
25+
SELECT tokenVerificationId, uid INTO @tokenVerificationId, @uid FROM `unverifiedTokens`
26+
WHERE tokenId = tokenIdArg;
27+
28+
-- Verify tokens with tokenVerificationId
29+
CALL verifyToken_3(@tokenVerificationId, @uid);
30+
COMMIT;
31+
32+
SELECT @updateCount;
33+
END;
34+
35+
UPDATE dbMetadata SET value = '76' WHERE name = 'schema-patch-level';
36+

lib/db/schema/patch-076-075.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- SET NAMES utf8mb4 COLLATE utf8mb4_bin;
2+
3+
-- DROP PROCEDURE verifyTokensWithMethod_2;
4+
5+
-- UPDATE dbMetadata SET value = '75' WHERE name = 'schema-patch-level';
6+

0 commit comments

Comments
 (0)