This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
/
create_test_users.js
executable file
·56 lines (47 loc) · 1.71 KB
/
create_test_users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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/. */
/* A quick and dirty script to create test users for load generation.
* Usage: ./create_test_users.js [number of test users]
*
* NOTE: the database used can be altered by specifying the path to a
* configuration file in the `CONFIG_FILES` environment variable.
*
* Example:
* $ CONFIG_FILES=config/production.json scripts/create_test_users.js 5000
*/
const
db = require('../lib/db.js'),
config = require('../lib/configuration.js'),
logging = require('../lib/logging.js'),
logger = logging.logger,
bcrypt = require('../lib/bcrypt')
logging.enableConsoleLogging();
// how many?
var want = (process.argv.length > 2 ? parseInt(process.argv[2], 10) : 2000);
logger.info("creating " + want + " test users... this can take a while...");
db.open(config.get('database'), function (error) {
if (error) {
logger.error("can't open database: " + error);
// let async logging flush, then exit 1
return setTimeout(function() { process.exit(1); }, 0);
}
bcrypt.encrypt(
config.get('bcrypt_work_factor'), "THE PASSWORD", function(err, hash) {
if (err) {
logger.error("error creating test users - bcrypt encrypt pass: " + err);
process.exit(1);
}
var have = 0;
for (var i = 1; i <= want; i++) {
db.addTestUser(i + "@loadtest.domain", hash, function(err, email) {
if (++have == want) {
logger.warn("created " + want + " test users");
bcrypt.shutdown();
db.close();
}
});
}
});
});