This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #506 from dannycoates/test-refactor
Test refactor
- Loading branch information
Showing
34 changed files
with
1,912 additions
and
1,602 deletions.
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
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
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
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
File renamed without changes.
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,48 @@ | ||
/* 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/. */ | ||
|
||
require('ass') | ||
var test = require('tap').test | ||
var butil = require('../../crypto/butil') | ||
|
||
test( | ||
'buffersAreEqual returns false if lengths are different', | ||
function (t) { | ||
t.equal(butil.buffersAreEqual(Buffer(2), Buffer(4)), false) | ||
t.end() | ||
} | ||
) | ||
|
||
test( | ||
'buffersAreEqual returns true if buffers have same bytes', | ||
function (t) { | ||
var b1 = Buffer('abcd', 'hex') | ||
var b2 = Buffer('abcd', 'hex') | ||
t.equal(butil.buffersAreEqual(b1, b2), true) | ||
t.end() | ||
} | ||
) | ||
|
||
test( | ||
'xorBuffers throws an Error if lengths are different', | ||
function (t) { | ||
try { | ||
butil.xorBuffers(Buffer(2), Buffer(4)) | ||
} | ||
catch (e) { | ||
return t.end() | ||
} | ||
t.fail('did not throw') | ||
} | ||
) | ||
|
||
test( | ||
'xorBuffers works', | ||
function (t) { | ||
var b1 = Buffer('e5', 'hex') | ||
var b2 = Buffer('5e', 'hex') | ||
t.deepEqual(butil.xorBuffers(b1, b2), Buffer('bb', 'hex')) | ||
t.end() | ||
} | ||
) |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,46 @@ | ||
/* 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/. */ | ||
|
||
var test = require('../ptaptest') | ||
var TestServer = require('../test_server') | ||
var path = require('path') | ||
var Client = require('../../client') | ||
|
||
process.env.CONFIG_FILES = path.join(__dirname, '../config/api_error.json') | ||
var config = require('../../config').root() | ||
|
||
function fail() { throw new Error() } | ||
|
||
TestServer.start(config) | ||
.then(function main(server) { | ||
|
||
test( | ||
'token expiry', | ||
function (t) { | ||
// FYI config.tokenLifetimes.passwordChangeToken = -1 | ||
var email = Math.random() + "@example.com" | ||
var password = 'ok' | ||
return Client.create(config.publicUrl, email, password, { preVerified: true }) | ||
.then( | ||
function (c) { | ||
return c.changePassword('hello') | ||
} | ||
) | ||
.then( | ||
fail, | ||
function (err) { | ||
t.equal(err.errno, 110, 'invalid token') | ||
} | ||
) | ||
} | ||
) | ||
|
||
test( | ||
'teardown', | ||
function (t) { | ||
server.stop() | ||
t.end() | ||
} | ||
) | ||
}) |
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,64 @@ | ||
/* 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/. */ | ||
|
||
var P = require('p-promise') | ||
var request = require('request') | ||
|
||
module.exports = function (host, port) { | ||
|
||
host = host || '127.0.0.1' | ||
port = port || 9001 | ||
|
||
function waitForCode(email) { | ||
return waitForEmail(email) | ||
.then( | ||
function (emailData) { | ||
return emailData.headers['x-verify-code'] || emailData.headers['x-recovery-code'] | ||
} | ||
) | ||
} | ||
|
||
function loop(name, tries, cb) { | ||
var url = 'http://' + host + ':' + port + '/mail/' + name | ||
console.log('checking mail', url) | ||
request({ url: url, method: 'GET' }, | ||
function (err, res, body) { | ||
console.log('mail status', res && res.statusCode, 'tries', tries) | ||
var json = null | ||
try { | ||
json = JSON.parse(body)[0] | ||
} | ||
catch (e) { | ||
return cb(e) | ||
} | ||
|
||
if(!json) { | ||
if (tries === 0) { | ||
return cb(new Error('could not get mail for ' + url)) | ||
} | ||
return setTimeout(loop.bind(null, name, --tries, cb), 1000) | ||
} | ||
console.log('deleting mail', url) | ||
request({ url: url, method: 'DELETE' }, | ||
function (err, res, body) { | ||
cb(err, json) | ||
} | ||
) | ||
} | ||
) | ||
} | ||
|
||
function waitForEmail(email) { | ||
var d = P.defer() | ||
loop(email.split('@')[0], 20, function (err, json) { | ||
return err ? d.reject(err) : d.resolve(json) | ||
}) | ||
return d.promise | ||
} | ||
|
||
return { | ||
waitForEmail: waitForEmail, | ||
waitForCode: waitForCode | ||
} | ||
} |
Oops, something went wrong.