Skip to content

Commit

Permalink
Add a unit test to reproduce #90
Browse files Browse the repository at this point in the history
  • Loading branch information
comino committed Oct 25, 2019
1 parent 1427577 commit a8dacc4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/security.spec.ts
Expand Up @@ -152,6 +152,22 @@ describe(packageJson.name, () => {
.expect(200);
});

it('should return 404 if apikey header exists and handler returns true but path doesnt exist', async () => {
eovConf.securityHandlers.ApiKeyAuth = <any>function(req, scopes, schema) {
expect(schema.type).to.equal('apiKey');
expect(schema.in).to.equal('header');
expect(schema.name).to.equal('X-API-Key');
expect(scopes)
.to.be.an('array')
.with.length(0);
return true;
};
return request(app)
.get(`${basePath}/api_key_but_invalid_path`)
.set('X-API-Key', 'test')
.expect(404);
});

it('should return 401 if auth header is missing for basic auth', async () => {
(<any>eovConf.securityHandlers).BasicAuth = async (req, scopes, schema) => {
return true;
Expand Down
22 changes: 22 additions & 0 deletions test/security.top.level.spec.ts
Expand Up @@ -51,6 +51,28 @@ describe(packageJson.name, () => {
);
}));


it('should return 200 if apikey exist', async () =>
request(app)
.get(`${basePath}/api_key`)
.set('X-API-Key', 'test')
.expect(200)
);

it('should return 404 if apikey exist, but path doesnt exist', async () =>
request(app)
.get(`${basePath}/api_key_undefined_path`)
.set('X-API-Key', 'test')
.expect(404)
.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(
'not found',
);
}));

it('should return 200 if apikey or anonymous', async () =>
request(app)
.get(`${basePath}/api_key_or_anonymous`)
Expand Down

0 comments on commit a8dacc4

Please sign in to comment.