2014-10-01 08:53:22 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
2017-09-19 16:00:37 +03:00
|
|
|
'use strict'
|
|
|
|
|
2017-04-04 20:31:37 +03:00
|
|
|
const ROOT_DIR = '../..'
|
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
const assert = require('insist')
|
2016-10-18 22:58:46 +03:00
|
|
|
const log = {
|
|
|
|
trace: () => {},
|
|
|
|
activityEvent: () => {},
|
|
|
|
flowEvent: () => {},
|
2016-11-08 23:04:46 +03:00
|
|
|
error() {}
|
2014-10-01 08:53:22 +04:00
|
|
|
}
|
2017-04-04 20:31:37 +03:00
|
|
|
const mocks = require('../mocks')
|
|
|
|
const error = require(`${ROOT_DIR}/lib/error.js`)
|
2018-07-10 18:31:43 +03:00
|
|
|
const P = require(`${ROOT_DIR}/lib/promise.js`)
|
2014-10-01 08:53:22 +04:00
|
|
|
var nock = require('nock')
|
|
|
|
|
2017-04-04 20:31:37 +03:00
|
|
|
const Customs = require(`${ROOT_DIR}/lib/customs.js`)(log, error)
|
2014-10-01 08:53:22 +04:00
|
|
|
|
|
|
|
var CUSTOMS_URL_REAL = 'http://localhost:7000'
|
|
|
|
var CUSTOMS_URL_MISSING = 'http://localhost:7001'
|
|
|
|
|
|
|
|
var customsNoUrl
|
|
|
|
var customsWithUrl
|
|
|
|
var customsInvalidUrl
|
|
|
|
|
|
|
|
var customsServer = nock(CUSTOMS_URL_REAL)
|
|
|
|
.defaultReplyHeaders({
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
describe('Customs', () => {
|
|
|
|
it(
|
|
|
|
"can create a customs object with url as 'none'",
|
|
|
|
() => {
|
|
|
|
customsNoUrl = new Customs('none')
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
assert.ok(customsNoUrl, 'got a customs object with a none url')
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
var request = newRequest()
|
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var email = newEmail()
|
|
|
|
var action = newAction()
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
return customsNoUrl.check(request, email, action)
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
return customsNoUrl.flag(ip, { email: email, uid: '12345' })
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /failedLoginAttempt succeeds')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
return customsNoUrl.reset(email)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /passwordReset succeeds')
|
|
|
|
})
|
2017-05-29 11:54:27 +03:00
|
|
|
.then(() => {
|
|
|
|
return customsNoUrl.checkIpOnly(request, action)
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /checkIpOnly succeeds')
|
|
|
|
})
|
2016-11-08 23:04:46 +03:00
|
|
|
}
|
|
|
|
)
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
it(
|
|
|
|
'can create a customs object with a url',
|
|
|
|
() => {
|
|
|
|
customsWithUrl = new Customs(CUSTOMS_URL_REAL)
|
|
|
|
|
|
|
|
assert.ok(customsWithUrl, 'got a customs object with a valid url')
|
|
|
|
|
|
|
|
var request = newRequest()
|
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var email = newEmail()
|
|
|
|
var action = newAction()
|
|
|
|
|
|
|
|
// Mock a check that does not get blocked.
|
|
|
|
customsServer.post('/check', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
2016-06-30 08:31:11 +03:00
|
|
|
email: email,
|
2016-11-08 23:04:46 +03:00
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
|
|
|
payload: request.payload,
|
|
|
|
}, 'first call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {
|
|
|
|
block: false,
|
|
|
|
retryAfter: 0
|
|
|
|
})
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds')
|
2016-06-30 08:31:11 +03:00
|
|
|
})
|
2016-11-08 23:04:46 +03:00
|
|
|
.then(function() {
|
|
|
|
// Mock a report of a failed login attempt
|
|
|
|
customsServer.post('/failedLoginAttempt', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
errno: error.ERRNO.UNEXPECTED_ERROR
|
|
|
|
}, 'first call to /failedLoginAttempt had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {})
|
|
|
|
return customsWithUrl.flag(ip, { email: email, uid: '12345' })
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /failedLoginAttempt succeeds')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// Mock a report of a password reset.
|
|
|
|
customsServer.post('/passwordReset', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
email: email,
|
|
|
|
}, 'first call to /passwordReset had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {})
|
|
|
|
return customsWithUrl.reset(email)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /passwordReset succeeds')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// Mock a check that does get blocked, with a retryAfter.
|
|
|
|
customsServer.post('/check', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
|
|
|
payload: request.payload,
|
|
|
|
}, 'second call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {
|
|
|
|
block: true,
|
|
|
|
retryAfter: 10001
|
|
|
|
})
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert(false, 'This should have failed the check since it should be blocked')
|
|
|
|
}, function(err) {
|
|
|
|
assert.equal(err.errno, error.ERRNO.THROTTLED, 'Error number is correct')
|
|
|
|
assert.equal(err.message, 'Client has sent too many requests', 'Error message is correct')
|
|
|
|
assert.ok(err.isBoom, 'The error causes a boom')
|
|
|
|
assert.equal(err.output.statusCode, 429, 'Status Code is correct')
|
|
|
|
assert.equal(err.output.payload.retryAfter, 10001, 'retryAfter is correct')
|
|
|
|
assert.equal(err.output.headers['retry-after'], 10001, 'retryAfter header is correct')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// Mock a report of a failed login attempt that does trigger lockout.
|
|
|
|
customsServer.post('/failedLoginAttempt', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
errno: error.ERRNO.INCORRECT_PASSWORD
|
|
|
|
}, 'second call to /failedLoginAttempt had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, { })
|
|
|
|
return customsWithUrl.flag(ip, {
|
2016-09-14 07:51:51 +03:00
|
|
|
email: email,
|
2016-11-08 23:04:46 +03:00
|
|
|
errno: error.ERRNO.INCORRECT_PASSWORD
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /failedLoginAttempt succeeds')
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// Mock a check that does get blocked, with no retryAfter.
|
|
|
|
request.headers['user-agent'] = 'test passing through headers'
|
|
|
|
request.payload['foo'] = 'bar'
|
|
|
|
customsServer.post('/check', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
|
|
|
payload: request.payload,
|
|
|
|
}, 'third call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {
|
|
|
|
block: true
|
|
|
|
})
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert(false, 'This should have failed the check since it should be blocked')
|
|
|
|
}, function(err) {
|
|
|
|
assert.equal(err.errno, error.ERRNO.REQUEST_BLOCKED, 'Error number is correct')
|
|
|
|
assert.equal(err.message, 'The request was blocked for security reasons', 'Error message is correct')
|
|
|
|
assert.ok(err.isBoom, 'The error causes a boom')
|
|
|
|
assert.equal(err.output.statusCode, 400, 'Status Code is correct')
|
2017-02-08 18:39:56 +03:00
|
|
|
assert(! err.output.payload.retryAfter, 'retryAfter field is not present')
|
|
|
|
assert(! err.output.headers['retry-after'], 'retryAfter header is not present')
|
2016-11-08 23:04:46 +03:00
|
|
|
})
|
2017-05-29 11:54:27 +03:00
|
|
|
.then(() => {
|
|
|
|
customsServer.post('/checkIpOnly', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
action: action
|
|
|
|
}, 'first call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}).reply(200, {
|
|
|
|
block: false,
|
|
|
|
retryAfter: 0
|
|
|
|
})
|
|
|
|
return customsWithUrl.checkIpOnly(request, action)
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds')
|
|
|
|
})
|
2016-11-08 23:04:46 +03:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
it(
|
2018-07-10 18:31:43 +03:00
|
|
|
'failed closed when creating a customs object with non-existant customs service',
|
2016-11-08 23:04:46 +03:00
|
|
|
() => {
|
|
|
|
customsInvalidUrl = new Customs(CUSTOMS_URL_MISSING)
|
|
|
|
|
|
|
|
assert.ok(customsInvalidUrl, 'got a customs object with a non-existant service url')
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
var request = newRequest()
|
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var email = newEmail()
|
|
|
|
var action = newAction()
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2018-07-10 18:31:43 +03:00
|
|
|
return P.all([
|
|
|
|
customsInvalidUrl.check(request, email, action)
|
|
|
|
.then(assert.fail, err => {
|
|
|
|
assert.equal(err.errno, error.ERRNO.BACKEND_SERVICE_FAILURE, 'an error is returned from /check')
|
|
|
|
}),
|
|
|
|
|
|
|
|
customsInvalidUrl.flag(ip, { email: email, uid: '12345' })
|
|
|
|
.then(assert.fail, err => {
|
|
|
|
assert.equal(err.errno, error.ERRNO.BACKEND_SERVICE_FAILURE, 'an error is returned from /flag')
|
|
|
|
}),
|
|
|
|
|
|
|
|
customsInvalidUrl.reset(email)
|
|
|
|
.then(assert.fail, err => {
|
|
|
|
assert.equal(err.errno, error.ERRNO.BACKEND_SERVICE_FAILURE, 'an error is returned from /passwordReset')
|
2016-11-08 23:04:46 +03:00
|
|
|
})
|
2018-07-10 18:31:43 +03:00
|
|
|
])
|
2016-11-08 23:04:46 +03:00
|
|
|
}
|
|
|
|
)
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
it(
|
|
|
|
'can rate limit checkAccountStatus /check',
|
|
|
|
() => {
|
|
|
|
customsWithUrl = new Customs(CUSTOMS_URL_REAL)
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
assert.ok(customsWithUrl, 'can rate limit checkAccountStatus /check')
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
var request = newRequest()
|
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var email = newEmail()
|
|
|
|
var action = 'accountStatusCheck'
|
2014-10-01 08:53:22 +04:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
function checkRequestBody (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
|
|
|
payload: request.payload,
|
|
|
|
}, 'call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
customsServer
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":true,"retryAfter":10001}')
|
|
|
|
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 1')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 2')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 3')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 4')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// request is blocked
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
assert(false, 'This should have failed the check since it should be blocked')
|
|
|
|
}, function(error) {
|
|
|
|
assert.equal(error.errno, 114, 'Error number is correct')
|
|
|
|
assert.equal(error.message, 'Client has sent too many requests', 'Error message is correct')
|
|
|
|
assert.ok(error.isBoom, 'The error causes a boom')
|
|
|
|
assert.equal(error.output.statusCode, 429, 'Status Code is correct')
|
|
|
|
assert.equal(error.output.payload.retryAfter, 10001, 'retryAfter is correct')
|
|
|
|
assert.equal(error.output.payload.retryAfterLocalized, 'in 3 hours', 'retryAfterLocalized is correct')
|
|
|
|
assert.equal(error.output.headers['retry-after'], 10001, 'retryAfter header is correct')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
it(
|
|
|
|
'can rate limit devicesNotify /checkAuthenticated',
|
|
|
|
() => {
|
|
|
|
customsWithUrl = new Customs(CUSTOMS_URL_REAL)
|
|
|
|
|
|
|
|
assert.ok(customsWithUrl, 'can rate limit /checkAuthenticated')
|
|
|
|
|
|
|
|
var request = newRequest()
|
|
|
|
var action = 'devicesNotify'
|
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var uid = 'foo'
|
|
|
|
|
|
|
|
function checkRequestBody (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
action: action,
|
|
|
|
ip: ip,
|
|
|
|
uid: uid,
|
|
|
|
}, 'call to /checkAuthenticated had expected request params')
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
customsServer
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/checkAuthenticated', checkRequestBody).reply(200, '{"block":true,"retryAfter":10001}')
|
|
|
|
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /checkAuthenticated succeeds - 1')
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /checkAuthenticated succeeds - 2')
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /checkAuthenticated succeeds - 3')
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
})
|
|
|
|
.then(function(result) {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /checkAuthenticated succeeds - 4')
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
// request is blocked
|
|
|
|
return customsWithUrl.checkAuthenticated(action, ip, uid)
|
|
|
|
})
|
|
|
|
.then(function() {
|
|
|
|
assert(false, 'This should have failed the check since it should be blocked')
|
|
|
|
}, function(error) {
|
|
|
|
assert.equal(error.errno, 114, 'Error number is correct')
|
|
|
|
assert.equal(error.message, 'Client has sent too many requests', 'Error message is correct')
|
|
|
|
assert.ok(error.isBoom, 'The error causes a boom')
|
|
|
|
assert.equal(error.output.statusCode, 429, 'Status Code is correct')
|
|
|
|
assert.equal(error.output.payload.retryAfter, 10001, 'retryAfter is correct')
|
|
|
|
assert.equal(error.output.headers['retry-after'], 10001, 'retryAfter header is correct')
|
|
|
|
})
|
2016-06-30 08:31:11 +03:00
|
|
|
}
|
2016-11-08 23:04:46 +03:00
|
|
|
)
|
2016-06-30 08:31:11 +03:00
|
|
|
|
2018-04-11 19:19:03 +03:00
|
|
|
it('can rate limit verifyTotpCode /check', () => {
|
|
|
|
const request = newRequest()
|
|
|
|
const action = 'verifyTotpCode'
|
|
|
|
const email = 'test@email.com'
|
|
|
|
const ip = request.app.clientAddress
|
|
|
|
|
|
|
|
customsWithUrl = new Customs(CUSTOMS_URL_REAL)
|
|
|
|
assert.ok(customsWithUrl, 'can rate limit ')
|
|
|
|
|
|
|
|
function checkRequestBody(body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
|
|
|
payload: request.payload,
|
|
|
|
}, 'call to /check had expected request params')
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
customsServer
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":false,"retryAfter":0}')
|
|
|
|
.post('/check', checkRequestBody).reply(200, '{"block":true,"retryAfter":30}')
|
|
|
|
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
.then((result) => {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 1')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then((result) => {
|
|
|
|
assert.equal(result, undefined, 'Nothing is returned when /check succeeds - 2')
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
})
|
|
|
|
.then(assert.fail, (error) => {
|
|
|
|
assert.equal(error.errno, 114, 'Error number is correct')
|
|
|
|
assert.equal(error.message, 'Client has sent too many requests', 'Error message is correct')
|
|
|
|
assert.ok(error.isBoom, 'The error causes a boom')
|
|
|
|
assert.equal(error.output.statusCode, 429, 'Status Code is correct')
|
|
|
|
assert.equal(error.output.payload.retryAfter, 30, 'retryAfter is correct')
|
|
|
|
assert.equal(error.output.headers['retry-after'], 30, 'retryAfter header is correct')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
it(
|
|
|
|
'can scrub customs request object',
|
|
|
|
() => {
|
|
|
|
customsWithUrl = new Customs(CUSTOMS_URL_REAL)
|
|
|
|
|
|
|
|
assert.ok(customsWithUrl, 'got a customs object with a valid url')
|
|
|
|
|
|
|
|
var request = newRequest()
|
|
|
|
request.payload.authPW = 'asdfasdfadsf'
|
2016-11-28 10:06:24 +03:00
|
|
|
request.payload.oldAuthPW = '012301230123'
|
|
|
|
request.payload.notThePW = 'plaintext'
|
2016-11-08 23:04:46 +03:00
|
|
|
var ip = request.app.clientAddress
|
|
|
|
var email = newEmail()
|
|
|
|
var action = newAction()
|
|
|
|
|
|
|
|
customsServer.post('/check', function (body) {
|
|
|
|
assert.deepEqual(body, {
|
|
|
|
ip: ip,
|
|
|
|
email: email,
|
|
|
|
action: action,
|
|
|
|
headers: request.headers,
|
|
|
|
query: request.query,
|
2016-11-28 10:06:24 +03:00
|
|
|
payload: {
|
|
|
|
notThePW: 'plaintext'
|
|
|
|
}
|
|
|
|
}, 'should not have password fields in payload')
|
2016-11-08 23:04:46 +03:00
|
|
|
return true
|
|
|
|
}).reply(200, {
|
|
|
|
block: false,
|
|
|
|
retryAfter: 0
|
|
|
|
})
|
|
|
|
|
|
|
|
return customsWithUrl.check(request, email, action)
|
|
|
|
.then(function (result) {
|
|
|
|
assert.equal(result, undefined, 'nothing is returned when /check succeeds - 1')
|
|
|
|
})
|
2016-08-05 20:33:55 +03:00
|
|
|
}
|
2016-11-08 23:04:46 +03:00
|
|
|
)
|
2016-08-05 20:33:55 +03:00
|
|
|
|
2016-11-08 23:04:46 +03:00
|
|
|
})
|
2016-07-20 19:18:01 +03:00
|
|
|
|
2014-10-01 08:53:22 +04:00
|
|
|
function newEmail() {
|
|
|
|
return Math.random().toString().substr(2) + '@example.com'
|
|
|
|
}
|
|
|
|
|
|
|
|
function newIp() {
|
|
|
|
return [
|
|
|
|
'' + Math.floor(Math.random() * 256),
|
|
|
|
'' + Math.floor(Math.random() * 256),
|
|
|
|
'' + Math.floor(Math.random() * 256),
|
|
|
|
'' + Math.floor(Math.random() * 256),
|
|
|
|
].join('.')
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:31:11 +03:00
|
|
|
function newRequest() {
|
2016-10-18 22:58:46 +03:00
|
|
|
return mocks.mockRequest({
|
|
|
|
clientAddress: newIp(),
|
2016-06-30 08:31:11 +03:00
|
|
|
headers: {},
|
|
|
|
query: {},
|
|
|
|
payload: {}
|
2016-10-18 22:58:46 +03:00
|
|
|
})
|
2016-06-30 08:31:11 +03:00
|
|
|
}
|
|
|
|
|
2014-10-01 08:53:22 +04:00
|
|
|
|
|
|
|
function newAction() {
|
2016-07-15 16:18:20 +03:00
|
|
|
var EMAIL_ACTIONS = [
|
|
|
|
'accountCreate',
|
|
|
|
'recoveryEmailResendCode',
|
|
|
|
'passwordForgotSendCode',
|
|
|
|
'passwordForgotResendCode'
|
|
|
|
]
|
|
|
|
|
2014-10-01 08:53:22 +04:00
|
|
|
return EMAIL_ACTIONS[Math.floor(Math.random() * EMAIL_ACTIONS.length)]
|
|
|
|
}
|