Skip to content

Commit

Permalink
add promise reject with error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmine DiMascio committed Oct 12, 2019
1 parent 34c0dd3 commit f3ef5c4
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions test/security.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe(packageJson.name, () => {
const eovConf = {
apiSpec: path.join('test', 'resources', 'security.yaml'),
securityHandlers: {
ApiKeyAuth: function(req, scopes, schema) {
ApiKeyAuth: (req, scopes, schema) => {
throw Error('custom api key handler failed');
},
},
Expand Down Expand Up @@ -93,6 +93,29 @@ describe(packageJson.name, () => {
});
});

it('should return 401 if apikey handler returns Promise reject with custom message', async () => {
(<any>eovConf.securityHandlers).ApiKeyAuth = (
req,
scopes,
schema,
) => {
expect(scopes)
.to.be.an('array')
.with.length(0);
return Promise.reject(new Error('rejected promise'));
};
return request(app)
.get(`${basePath}/api_key`)
.set('X-API-Key', 'test')
.expect(401)
.then(r => {
const body = r.body;
expect(body.errors).to.be.an('array');
expect(body.errors).to.have.length(1);
expect(body.errors[0].message).to.equals('rejected promise');
});
});

it('should return 401 if apikey header is missing', async () => {
eovConf.securityHandlers.ApiKeyAuth = <any>function(req, scopes, schema) {
return true;
Expand Down Expand Up @@ -125,7 +148,7 @@ describe(packageJson.name, () => {
});

it('should return 401 if auth header is missing for basic auth', async () => {
(<any>eovConf.securityHandlers).BasicAuth = function(req, scopes, schema) {
(<any>eovConf.securityHandlers).BasicAuth = async (req, scopes, schema) => {
return true;
};
return request(app)
Expand Down

0 comments on commit f3ef5c4

Please sign in to comment.