Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('supports HTTPS protocol with key and certificate files', async () => {
const serverOptions = givenHttpServerConfig();
const httpsServer: HttpServer = givenHttpsServer(serverOptions);
await httpsServer.start();
const response = await httpsGetAsync(httpsServer.url);
expect(response.statusCode).to.equal(200);
});
it('supports HTTPS protocol with a pfx file', async () => {
const httpsServer: HttpServer = givenHttpsServer({usePfx: true});
await httpsServer.start();
const response = await httpsGetAsync(httpsServer.url);
expect(response.statusCode).to.equal(200);
});
skipOnTravis(it, 'handles IPv6 loopback address in HTTPS', async () => {
const httpsServer: HttpServer = givenHttpsServer({
host: '::1',
});
await httpsServer.start();
expect(getAddressFamily(httpsServer)).to.equal('IPv6');
const response = await httpsGetAsync(httpsServer.url);
expect(response.statusCode).to.equal(200);
});
it('converts host from [::] to [::1] in url', async () => {
// Safari on MacOS does not support http://[::]:3000/
server = new HttpServer(dummyRequestHandler, {host: '::'});
await server.start();
expect(server.url).to.equal(`http://[::1]:${server.port}`);
});
host: '::1',
protocol: 'https',
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
},
});
server.handler(dummyRequestHandler);
await server.start();
const serverUrl = server.getSync(RestBindings.URL);
const res = await httpsGetAsync(serverUrl);
expect(res.statusCode).to.equal(200);
await server.stop();
});
// https://github.com/strongloop/loopback-next/issues/1623
skipOnTravis(it, 'handles IPv6 address for API Explorer UI', async () => {
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const server = await givenAServer({
rest: {
port: 0,
host: '::1',
protocol: 'https',
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
},
});
server.handler(dummyRequestHandler);
await server.start();
const serverUrl = server.getSync(RestBindings.URL);
// The `Location` header should be something like
const port = server.port;
const anotherServer = new HttpServer(dummyRequestHandler, {
port: port,
});
await expect(anotherServer.start()).to.be.rejectedWith(/EADDRINUSE/);
});
it('supports HTTP over IPv4', async () => {
server = new HttpServer(dummyRequestHandler, {host: '127.0.0.1'});
await server.start();
expect(getAddressFamily(server)).to.equal('IPv4');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});
skipOnTravis(it, 'supports HTTP over IPv6', async () => {
server = new HttpServer(dummyRequestHandler, {host: '::1'});
await server.start();
expect(getAddressFamily(server)).to.equal('IPv6');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});
it('supports HTTPS protocol with key and certificate files', async () => {
const serverOptions = givenHttpServerConfig();
const httpsServer: HttpServer = givenHttpsServer(serverOptions);
await httpsServer.start();
const response = await httpsGetAsync(httpsServer.url);
expect(response.statusCode).to.equal(200);
});
it('supports HTTPS protocol with a pfx file', async () => {
describe('HttpServer (integration)', () => {
let server: HttpServer | undefined;
afterEach(stopServer);
skipOnTravis(it, 'formats IPv6 url correctly', async () => {
server = new HttpServer(dummyRequestHandler, {
host: '::1',
} as HttpOptions);
await server.start();
expect(getAddressFamily(server)).to.equal('IPv6');
const response = await httpGetAsync(server.url);
expect(response.statusCode).to.equal(200);
});
it('starts server', async () => {
const serverOptions = givenHttpServerConfig();
server = new HttpServer(dummyRequestHandler, serverOptions);
await server.start();
await supertest(server.url)
.get('/')
.expect(200);
const serverOptions = givenHttpServerConfig({
port: 0,
protocol: 'https' as 'https',
pfx: fs.readFileSync(pfxPath),
passphrase: 'loopback4',
});
const server = await givenAServer({rest: serverOptions});
server.handler(dummyRequestHandler);
await server.start();
const serverUrl = server.getSync(RestBindings.URL);
const res = await httpsGetAsync(serverUrl);
expect(res.statusCode).to.equal(200);
await server.stop();
});
skipOnTravis(it, 'handles IPv6 loopback address in HTTPS', async () => {
const keyPath = path.join(FIXTURES, 'key.pem');
const certPath = path.join(FIXTURES, 'cert.pem');
const server = await givenAServer({
rest: {
port: 0,
host: '::1',
protocol: 'https',
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
},
});
server.handler(dummyRequestHandler);
await server.start();
const serverUrl = server.getSync(RestBindings.URL);
const res = await httpsGetAsync(serverUrl);
expect(res.statusCode).to.equal(200);