Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions test/cors.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,66 @@ describe('CORS', () => {
});
});

it('sets default CORS access-control-expose-headers with default cors configuration', (done) => {

const handler = function (request, reply) {

return reply('ok');
};

const server = new Hapi.Server();
server.connection({ routes: { cors: true } });
server.route({ method: 'GET', path: '/', handler: handler });

server.inject({ url: '/', headers: { origin: 'http://example.com/' } }, (res) => {

expect(res.result).to.exist();
expect(res.result).to.equal('ok');
expect(res.headers['access-control-expose-headers']).to.equal('WWW-Authenticate,Server-Authorization');
done();
});
});

it('sets default CORS access-control-expose-headers with custom cors configuration', (done) => {

const handler = function (request, reply) {

return reply('ok');
};

const server = new Hapi.Server();
server.connection({ routes: { cors: { origin: ['http://example.com'] } } });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Origin config missing trailing /

server.route({ method: 'GET', path: '/', handler: handler });

server.inject({ url: '/', headers: { origin: 'http://example.com/' } }, (res) => {

expect(res.result).to.exist();
expect(res.result).to.equal('ok');
expect(res.headers['access-control-expose-headers']).to.equal('WWW-Authenticate,Server-Authorization');
done();
});
});

it('sets CORS access-control-expose-headers with specified headers', (done) => {

const handler = function (request, reply) {

return reply('ok');
};

const server = new Hapi.Server();
server.connection({ routes: { cors: { origin: ['http://example.com'], exposedHeaders: ['Foo', 'Bar'] } } });
server.route({ method: 'GET', path: '/', handler: handler });

server.inject({ url: '/', headers: { origin: 'http://example.com/' } }, (res) => {

expect(res.result).to.exist();
expect(res.result).to.equal('ok');
expect(res.headers['access-control-expose-headers']).to.equal('Foo,Bar');
done();
});
});

it('returns no CORS headers when route CORS disabled', (done) => {

const handler = function (request, reply) {
Expand Down Expand Up @@ -589,6 +649,7 @@ describe('CORS', () => {

expect(res.statusCode).to.equal(200);
expect(res.headers['access-control-allow-headers']).to.equal('Accept,Authorization,Content-Type,If-None-Match,Origin');
expect(res.headers['access-control-expose-headers']).to.equal('WWW-Authenticate,Server-Authorization');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug

done();
});
});
Expand Down