-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Carmine DiMascio
committed
Oct 7, 2019
1 parent
7ff34c0
commit 5a6b330
Showing
8 changed files
with
148 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { OpenApiContext } from '../framework/openapi.context'; | ||
// import { validationError } from './util'; | ||
|
||
export function security(openApiContext: OpenApiContext) { | ||
return (req, res, next) => { | ||
if (!req.openapi) { | ||
// this path was not found in open api and | ||
// this path is not defined under an openapi base path | ||
// skip it | ||
return next(); | ||
} | ||
|
||
const security = req.openapi.schema.security; | ||
if (!security) { | ||
return next(); | ||
} | ||
|
||
console.log('found security ', security, req.openapi); | ||
// run security handlers | ||
next(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
openapi: '3.0.2' | ||
info: | ||
version: 1.0.0 | ||
title: requestBodies $ref | ||
description: requestBodies $ref Test | ||
|
||
servers: | ||
- url: /v1/ | ||
|
||
paths: | ||
/api_key: | ||
get: | ||
security: | ||
- ApiKeyAuth: [] | ||
responses: | ||
'200': | ||
description: OK | ||
'400': | ||
description: Bad Request | ||
#'401': | ||
# description: unauthorized | ||
|
||
components: | ||
securitySchemes: | ||
BasicAuth: | ||
type: http | ||
scheme: basic | ||
BearerAuth: | ||
type: http | ||
scheme: bearer | ||
ApiKeyAuth: | ||
type: apiKey | ||
in: header | ||
name: X-API-Key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as path from 'path'; | ||
import * as express from 'express'; | ||
import { expect } from 'chai'; | ||
import * as request from 'supertest'; | ||
import { createApp } from './common/app'; | ||
|
||
const packageJson = require('../package.json'); | ||
|
||
describe(packageJson.name, () => { | ||
let app = null; | ||
let basePath = null; | ||
|
||
before(async () => { | ||
// Set up the express app | ||
const apiSpec = path.join('test', 'resources', 'security.yaml'); | ||
app = await createApp( | ||
{ | ||
apiSpec, | ||
securityHandlers: { | ||
ApiKeyAuth: function(req, scopes, schema) { | ||
console.log('-------in sec handler'); | ||
}, | ||
}, | ||
}, | ||
3005, | ||
); | ||
basePath = app.basePath; | ||
console.log(basePath); | ||
|
||
app.use( | ||
`${basePath}`, | ||
express | ||
.Router() | ||
.get(`/api_key`, (req, res) => res.json({ logged_in: true })), | ||
); | ||
}); | ||
|
||
after(() => { | ||
app.server.close(); | ||
}); | ||
|
||
it.only('should return 401 if apikey not valid', async () => | ||
request(app) | ||
.get(`${basePath}/api_key`) | ||
.send({}) | ||
.expect(401) | ||
.then(r => { | ||
console.log(r.body); | ||
expect(r.body.errors).to.be.an('array'); | ||
expect(r.body.errors).to.have.length(1); | ||
|
||
// TODO add test | ||
})); | ||
}); |