Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions db-server/test/backend/db_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,30 @@ module.exports = function (config, DB) {
})
})

it('should update session verificationMethod', () => {
const verifyOptions = {
verificationMethod: 'totp-2fa'
}
return db.verifyTokens(sessionToken.tokenVerificationId, account)
.then(() => {
return db.sessionToken(tokenId)
}, assert.fail)
.then((token) => {
assert.equal(token.mustVerify, false, 'mustVerify is false')
assert.equal(token.tokenVerificationId, null, 'tokenVerificationId is null')
assert.equal(token.verificationMethod, null, 'verificationMethod is null')
return db.verifyTokensWithMethod(tokenId, verifyOptions)
})
.then(() => {
return db.sessionToken(tokenId)
}, assert.fail)
.then((token) => {
assert.equal(token.mustVerify, false, 'mustVerify is false')
assert.equal(token.tokenVerificationId, null, 'tokenVerificationId is null')
assert.equal(token.verificationMethod, 2, 'verificationMethod is set')
})
})

it('should fail to verify unknown verification method', () => {
const verifyOptions = {
verificationMethod: 'super-invalid-method'
Expand Down
2 changes: 1 addition & 1 deletion lib/db/mem.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ module.exports = function (log, error) {
item.authAt = sessionTokens[id].authAt || sessionTokens[id].createdAt
item.verificationMethod = sessionTokens[id].verificationMethod || null
item.verifiedAt = sessionTokens[id].verifiedAt || null
item.mustVerify = sessionTokens[id].mustVerify || null
item.mustVerify = !! sessionTokens[id].mustVerify

var accountId = sessionTokens[id].uid.toString('hex')
var account = accounts[accountId]
Expand Down
2 changes: 1 addition & 1 deletion lib/db/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ module.exports = function (log, error) {
})
}

const VERIFY_SESSION_WITH_METHOD = 'CALL verifyTokensWithMethod_1(?, ?, ?)'
const VERIFY_SESSION_WITH_METHOD = 'CALL verifyTokensWithMethod_2(?, ?, ?)'
MySql.prototype.verifyTokensWithMethod = function (tokenId, data) {
return P.resolve()
.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion lib/db/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

// The expected patch level of the database. Update if you add a new
// patch in the ./schema/ directory.
module.exports.level = 75
module.exports.level = 76
36 changes: 36 additions & 0 deletions lib/db/schema/patch-075-076.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
SET NAMES utf8mb4 COLLATE utf8mb4_bin;

CREATE PROCEDURE `verifyTokensWithMethod_2` (
IN `tokenIdArg` BINARY(32),
IN `verificationMethodArg` INT,
IN `verifiedAtArg` BIGINT(1)
)
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
RESIGNAL;
END;

START TRANSACTION;
-- Update session verification methods
UPDATE `sessionTokens` SET verificationMethod = verificationMethodArg, verifiedAt = verifiedAtArg
WHERE tokenId = tokenIdArg;

SET @updateCount = (SELECT ROW_COUNT());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count returned should be the the number of session's updated, previously it was number of tokens verified.


-- Get the tokenVerificationId and uid for session
SET @tokenVerificationId = NULL;
SET @uid = NULL;
SELECT tokenVerificationId, uid INTO @tokenVerificationId, @uid FROM `unverifiedTokens`
WHERE tokenId = tokenIdArg;

-- Verify tokens with tokenVerificationId
CALL verifyToken_3(@tokenVerificationId, @uid);
COMMIT;

SELECT @updateCount;
END;

UPDATE dbMetadata SET value = '76' WHERE name = 'schema-patch-level';

6 changes: 6 additions & 0 deletions lib/db/schema/patch-076-075.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- SET NAMES utf8mb4 COLLATE utf8mb4_bin;

-- DROP PROCEDURE verifyTokensWithMethod_2;

-- UPDATE dbMetadata SET value = '75' WHERE name = 'schema-patch-level';