This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(test): add a test script to add account rows
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env node | ||
|
||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
// For testing purposes only, generate traffic and table size for fxa.accounts. | ||
|
||
const assert = require('insist') | ||
const dbServer = require('../db-server') | ||
const log = require('../test/lib/log') | ||
const DB = require('../lib/db/mysql')(log, dbServer.errors) | ||
const config = require('../config') | ||
const crypto = require('crypto') | ||
|
||
function randomBuffer16() { | ||
return crypto.randomBytes(16) | ||
} | ||
|
||
function randomBuffer32() { | ||
return crypto.randomBytes(32) | ||
} | ||
|
||
function now() { | ||
return Date.now() | ||
} | ||
|
||
let count = 0 | ||
let db | ||
|
||
function create() { | ||
var uid = crypto.randomBytes(16) | ||
var account = { | ||
uid: uid, | ||
email: ('' + Math.random()).substr(2) + '@bar.com', | ||
emailCode: randomBuffer16(), | ||
emailVerified: false, | ||
verifierVersion: 1, | ||
verifyHash: randomBuffer32(), | ||
authSalt: randomBuffer32(), | ||
kA: randomBuffer32(), | ||
wrapWrapKb: randomBuffer32(), | ||
verifierSetAt: now(), | ||
createdAt: now(), | ||
locale : 'en_US', | ||
} | ||
account.normalizedEmail = account.email.toLowerCase() | ||
|
||
return db.createAccount(uid, account) | ||
.then( | ||
function(result) { | ||
assert.deepEqual(result, {}, 'Returned an empty object on account creation') | ||
return db.emailRecord(account.email) | ||
} | ||
) | ||
.then( | ||
function(result) { | ||
assert.equal(result.createdAt, account.createdAt, 'createdAt set') | ||
assert.equal(result.email, account.email, 'email set') | ||
assert.equal(result.emailVerified, 0, 'emailVerified set') | ||
assert.equal(result.normalizedEmail, account.normalizedEmail, 'normalizedEmail set') | ||
assert.equal(result.verifierSetAt, account.verifierSetAt, 'verifierSetAt set') | ||
assert.equal(result.verifierVersion, account.verifierVersion, 'verifierVersion set') | ||
}) | ||
} | ||
|
||
function init() { | ||
return DB.connect(config).then(db_ => { | ||
db = db_ | ||
return db.ping() | ||
}) | ||
} | ||
|
||
function createAccount() { | ||
return create() | ||
.then(() => { | ||
console.log('done', ++count) //eslint-disable-line no-console | ||
if (count >= 50000) { | ||
process.exit(0) | ||
} | ||
}) | ||
.catch((err) => console.error(err)) //eslint-disable-line no-console | ||
} | ||
|
||
init() | ||
.then(() => { | ||
setInterval(createAccount, 5) | ||
}) |