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

Commit 9bdb47b

Browse files
vbudhramvladikoff
authored andcommitted
fix(unblock): update consume unblock code (#330) r=@vladikoff
1 parent f6ab498 commit 9bdb47b

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

db-server/test/backend/db_tests.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,23 @@ module.exports = function (config, DB) {
13841384
})
13851385
})
13861386
})
1387+
1388+
it('should delete all code when successfully consumed code', () => {
1389+
return db.consumeUnblockCode(uid1, 'NOTREAL')
1390+
.then(assert.fail, (err) => {
1391+
assert.equal(err.code, 404, 'err.code')
1392+
assert.equal(err.errno, 116, 'err.errno')
1393+
return db.consumeUnblockCode(uid1, code1)
1394+
})
1395+
.then((code) => {
1396+
assert(code.createdAt <= Date.now(), 'returns unblock code timestamp')
1397+
return db.consumeUnblockCode(uid1, code2)
1398+
}, assert.fail)
1399+
.then(assert.fail, (err) => {
1400+
assert.equal(err.code, 404, 'err.code')
1401+
assert.equal(err.errno, 116, 'err.errno')
1402+
})
1403+
})
13871404
})
13881405

13891406
it(

lib/db/mysql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ module.exports = function (log, error) {
848848
)
849849
}
850850

851-
var CONSUME_UNBLOCK_CODE = 'CALL consumeUnblockCode_2(?, ?)'
851+
var CONSUME_UNBLOCK_CODE = 'CALL consumeUnblockCode_3(?, ?)'
852852

853853
MySql.prototype.consumeUnblockCode = function (uid, code) {
854854
// hash the code since it's like a password

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 = 77
7+
module.exports.level = 78

lib/db/schema/patch-077-078.sql

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
SET NAMES utf8mb4 COLLATE utf8mb4_bin;
2+
3+
CREATE PROCEDURE `consumeUnblockCode_3` (
4+
inUid BINARY(16),
5+
inCodeHash BINARY(32)
6+
)
7+
BEGIN
8+
DECLARE timestamp BIGINT;
9+
10+
SET @timestamp = (
11+
SELECT createdAt FROM unblockCodes
12+
WHERE
13+
uid = inUid
14+
AND
15+
unblockCodeHash = inCodeHash
16+
);
17+
18+
IF @timestamp > 0 THEN
19+
DELETE FROM unblockCodes
20+
WHERE
21+
uid = inUid;
22+
END IF;
23+
24+
SELECT @timestamp AS createdAt;
25+
END;
26+
27+
UPDATE dbMetadata SET value = '78' WHERE name = 'schema-patch-level';
28+

lib/db/schema/patch-078-077.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 `consumeUnblockCode_3`;
4+
5+
-- UPDATE dbMetadata SET value = '77' WHERE name = 'schema-patch-level';
6+

0 commit comments

Comments
 (0)