diff --git a/integration_test/database/accounts.js b/integration_test/database/accounts.js new file mode 100644 index 00000000..da35d4c2 --- /dev/null +++ b/integration_test/database/accounts.js @@ -0,0 +1,65 @@ +const assert = require('assert'); +const { testDB } = require('../testutil/db'); +const accounts = require('../../lib/database/accounts'); + +require('../../lib/database').init(testDB); + +describe('AccountsDatabase', () => { + describe('#verifyLogin', () => { + let ip = '169.254.111.111'; + let user; + let password; + + beforeEach(async () => { + return testDB.knex.table('users') + .where({ ip }) + .delete(); + }); + + beforeEach(done => { + user = `u${Math.random().toString(31).substring(2)}`; + password = 'int!gration_Test'; + + accounts.register( + user, + password, + '', + ip, + (error, res) => { + if (error) { + throw error; + } + + console.log(`Created test user ${user}`); + done(); + } + ) + }); + + it('verifies a correct login', done => { + accounts.verifyLogin( + user, + password, + (error, res) => { + if (error) { + throw error; + } + + assert.strictEqual(res.name, user); + done(); + } + ); + }); + + it('rejects an incorrect login', done => { + accounts.verifyLogin( + user, + 'not the right password', + (error, res) => { + assert.strictEqual(error, 'Invalid username/password combination'); + done(); + } + ); + }); + }); +}); diff --git a/integration_test/db/globalban.js b/integration_test/db/globalban.js index 37a091b5..ba7095b2 100644 --- a/integration_test/db/globalban.js +++ b/integration_test/db/globalban.js @@ -1,6 +1,7 @@ const assert = require('assert'); const GlobalBanDB = require('../../lib/db/globalban').GlobalBanDB; const testDB = require('../testutil/db').testDB; +const { o } = require('../testutil/o'); const globalBanDB = new GlobalBanDB(testDB); const testBan = { ip: '8.8.8.8', reason: 'test' }; @@ -35,7 +36,7 @@ describe('GlobalBanDB', () => { assert.deepStrictEqual([{ ip: '8.8.8.8', reason: 'test' - }], bans); + }], bans.map(o)); }); }); }); diff --git a/integration_test/db/password-reset.js b/integration_test/db/password-reset.js index 2bb00cc6..8589cf41 100644 --- a/integration_test/db/password-reset.js +++ b/integration_test/db/password-reset.js @@ -1,6 +1,7 @@ const assert = require('assert'); const PasswordResetDB = require('../../lib/db/password-reset').PasswordResetDB; const testDB = require('../testutil/db').testDB; +const { o } = require('../testutil/o'); const passwordResetDB = new PasswordResetDB(testDB); @@ -27,7 +28,7 @@ describe('PasswordResetDB', () => { .select(); }).then(rows => { assert.strictEqual(rows.length, 1); - assert.deepStrictEqual(rows[0], params); + assert.deepStrictEqual(o(rows[0]), params); }); }); @@ -45,7 +46,7 @@ describe('PasswordResetDB', () => { .select(); }).then(rows => { assert.strictEqual(rows.length, 1); - assert.deepStrictEqual(rows[0], params); + assert.deepStrictEqual(o(rows[0]), params); }); }); }); @@ -65,7 +66,7 @@ describe('PasswordResetDB', () => { it('gets a password reset by hash', () => { return passwordResetDB.get(reset.hash).then(result => { - assert.deepStrictEqual(result, reset); + assert.deepStrictEqual(o(result), reset); }); }); @@ -136,7 +137,7 @@ describe('PasswordResetDB', () => { .select(); }).then(rows => { assert.strictEqual(rows.length, 1); - assert.deepStrictEqual(rows[0], reset2); + assert.deepStrictEqual(o(rows[0]), reset2); }); }); }); diff --git a/integration_test/testutil/o.js b/integration_test/testutil/o.js new file mode 100644 index 00000000..b8863929 --- /dev/null +++ b/integration_test/testutil/o.js @@ -0,0 +1,4 @@ +exports.o = function o(obj) { + // Workaround for knex returning RowDataPacket and failing assertions + return Object.assign({}, obj); +}