test('server.onError EADDRINUSE', (done) => { const serverWithSameSocketPath = awsServerlessExpress.createServer(mockApp) serverWithSameSocketPath._socketPathSuffix = server._socketPathSuffix const succeed = response => { expect(response.statusCode).toBe(200) done() serverWithSameSocketPath.close() } awsServerlessExpress.proxy(serverWithSameSocketPath, makeEvent({}), { succeed }) })
Then('check link', async () => { // From "features\lawPage.feature" {"line":73,"column":7} const link = await I.grabAttributeFrom({ css: '#gbw > div > div > div.gb_qe.gb_R.gb_Pg.gb_Fg > div:nth-child(2) > a' }, 'href'); const response = await I.sendGetRequest(link); assert(response.statusCode === 200); I.see('Google'); });
function setResStatus(defaultCode) { setReqStatus(LOCALHOST); resData.statusCode = _res.statusCode || defaultCode || 502; resData.statusMessage = _res.statusMessage; if (!data.requestTime) { data.requestTime = requestTime || data.dnsTime || Date.now(); } data.responseTime = Date.now(); resData.headers = _res.headers; }
util.request({ url: 'http://statuscode1.testx.whistlejs.com/index.html?resBody=', method: 'POST', body: 'xxxxxxxxxxxx' }, function(res) { res.statusCode.should.equal(999); });
test('should support builder-style injection with non-ready app', async (t) => { t.plan(3) const fastify = Fastify() const payload = { hello: 'world' } fastify.get('/', (req, reply) => { reply.send(payload) }) const res = await fastify.inject().get('/').end() t.deepEqual(payload, JSON.parse(res.payload)) t.strictEqual(res.statusCode, 200) t.strictEqual(res.headers['content-length'], '17') })
util.drain(req, function() { if (util.getStatusCode(_res.statusCode)) { res.src(_res); res.writeHead(_res.statusCode, _res.headers); } else { util.sendStatusCodeError(res, _res); } });
lab.test('it returns early when abuse is detected', (done) => { stub.AuthAttempt.abuseDetected = function (ip, username, callback) { callback(null, true); }; server.inject(request, (response) => { Code.expect(response.statusCode).to.equal(400); Code.expect(response.result.message).to.match(/maximum number of auth attempts reached/i); done(); }); });
test('shorthand - request delete', t => { t.plan(4) sget({ method: 'DELETE', url: 'http://localhost:' + fastify.server.address().port }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 'world' }) }) })
lab.test('it returns an error when find by credentials fails', (done) => { stub.AuthAttempt.abuseDetected = function (ip, username, callback) { callback(null, false); }; stub.User.findByCredentials = function (username, password, callback) { callback(Error('find by credentials failed')); }; server.inject(request, (response) => { Code.expect(response.statusCode).to.equal(500); done(); }); });
test("Hidden files are hidden", () => { // expect.assertions(1); return get("/_hidden/config.txt") .then(data => { //expect(data && data.indexOf("secret") === -1).toBe(true); }) .catch(e => { expect(e.statusCode).toBe(404); }); });
test('.status() is an alias for .code()', t => { t.plan(2) const fastify = require('../..')() fastify.get('/', function (req, reply) { reply.status(418).send() }) fastify.inject('/', (err, res) => { t.error(err) t.is(res.statusCode, 418) }) })
test('redirect to `/` - 7', t => { t.plan(4) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/redirect-code-before-call-overwrite' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-type'], 'text/plain') t.deepEqual(body.toString(), 'hello world!') }) })
util.request({ method: 'post', headers: { 'x-test': 'test', cookie: 'cookieName=123; test=abc; name=tps2.json', other: 'otherhaha' }, url: 'https://2.tps.whistlejs.com/?test=abc' }, function(res, data) { data.statusCode.should.equal('200'); });
test('shorthand - request get params schema', t => { t.plan(4) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/params/world/123' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { foo: 'world', test: 123 }) }) })
test('shorthand - request get missing schema', t => { t.plan(4) sget({ method: 'GET', url: 'http://localhost:' + fastify.server.address().port + '/missing' }, (err, response, body) => { t.error(err) t.strictEqual(response.statusCode, 200) t.strictEqual(response.headers['content-length'], '' + body.length) t.deepEqual(JSON.parse(body), { hello: 'world' }) }) })