Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"use strict";
const HttpStatusCodes = require("http-status-codes");
module.exports = {
// Status codes where we want to redirect the user
redirect: {
[HttpStatusCodes.MOVED_PERMANENTLY]: true,
[HttpStatusCodes.MOVED_TEMPORARILY]: true,
[HttpStatusCodes.PERMANENT_REDIRECT]: true,
[HttpStatusCodes.TEMPORARY_REDIRECT]: true
}
};
it('should set the end time on the request and log the interaction when: log level is debug, a redirect, and a status code', function(done) {
req.didRedirect = true;
req.url = '/admin/hello';
req.controllerResult = { redirect: '/somewhere/else', code: HttpStatusCodes.MOVED_TEMPORARILY };
sandbox.stub(this.pb.log, 'isDebug').returns(true);
sandbox.stub(this.pb.log, 'debug')
.withArgs(sinon.match.string, sinon.match.number, req.url, ' REDIRECT=/somewhere/else', ' CODE='+HttpStatusCodes.MOVED_TEMPORARILY);
var self = this;
this.pb.Middleware.responseTime(req, res, function(err) {
should(err).eql(undefined);
self.pb.log.isDebug.calledOnce.should.eql(true);
self.pb.log.debug.calledOnce.should.eql(true);
done();
});
});
});
it('should set the end time on the request and log the interaction when: log level is debug, a redirect, and a status code', function(done) {
req.didRedirect = true;
req.url = '/admin/hello';
req.controllerResult = { redirect: '/somewhere/else', code: HttpStatusCodes.MOVED_TEMPORARILY };
sandbox.stub(this.pb.log, 'isDebug').returns(true);
sandbox.stub(this.pb.log, 'debug')
.withArgs(sinon.match.string, sinon.match.number, req.url, ' REDIRECT=/somewhere/else', ' CODE='+HttpStatusCodes.MOVED_TEMPORARILY);
var self = this;
this.pb.Middleware.responseTime(req, res, function(err) {
should(err).eql(undefined);
self.pb.log.isDebug.calledOnce.should.eql(true);
self.pb.log.debug.calledOnce.should.eql(true);
done();
});
});
});
assert.ok(await this.login(), `should be logged in to ${this.config.botAccount.username} with username ${this.config.baseUrl}`);
await this.rateLimiter.limit();
let response: request.Response;
try {
response = await this.request.post({
uri: `/${entity}/${mbid}/edit`,
form: formData,
followRedirect: false
});
} catch (err) {
assert.ok(err.response.complete);
response = err.response;
}
assert.strictEqual(response.statusCode, HttpStatus.MOVED_TEMPORARILY);
}
RequestHandler.prototype.doRedirect = function(location, statusCode) {
this.resp.statusCode = statusCode || HttpStatusCodes.MOVED_TEMPORARILY;
this.resp.setHeader("Location", location);
this.resp.end();
};
export function movedTemporarily(arg1: T | string | Wrapper, arg2?: string): T {
return answer(HTTP.MOVED_TEMPORARILY, arg1, arg2);
}