Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("sends a CORS options request", function () {
var opts = { headers: { origin }, method: "OPTIONS" };
var result = internal.download(origin + "/unittest/headers/header-echo", "", opts);
expect(result.code).to.equal(200);
expect(result.headers['access-control-expose-headers']).to.equal('etag, content-encoding, content-length, location, server, x-arango-errors, x-arango-async-id');
expect(result.headers).not.to.have.property('access-control-allow-headers');
expect(result.headers['access-control-allow-credentials']).to.equal('true');
expect(result.headers['access-control-allow-origin']).to.equal(origin);
expect(result.headers['access-control-allow-methods']).to.equal('DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT');
});
it('defaults to authenticated user when present', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('root:').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: 'root'}));
});
it('defaults to authenticated user when present', function () {
const opts = { headers: {
authorization: (
'Basic ' + new Buffer('root:').toString('base64')
)
}};
const result = internal.download(url + mount, '', opts);
expect(result.code).to.equal(200);
expect(result.body).to.eql(JSON.stringify({user: 'root'}));
});
it("sets defaults for responses without headers", function () {
var opts = { headers: { origin }, method: "POST" };
var result = internal.download(origin + "/unittest/headers/header-empty", "", opts);
const irrelevantHeaders = ['http/1.1', 'connection', 'content-type'];
expect(result.headers['access-control-expose-headers']).to.equal(Object.keys(result.headers).filter(x => !x.startsWith('x-content-type-options') && !x.startsWith('access-control-') && !irrelevantHeaders.includes(x)).sort().join(', '));
expect(result.headers['access-control-allow-credentials']).to.equal('true');
});
});
testGetErrorNoReturn : function () {
var response = internal.download(buildUrlBroken("?foo=1&bar=baz&code=404"),
undefined, { timeout: 300 }, tempName );
assertEqual(404, response.code);
assertFalse(fs.exists(tempName));
},