forked from readmeio/api-explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests to pass 90% test coverage
- Loading branch information
Showing
10 changed files
with
205 additions
and
6 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
88 changes: 88 additions & 0 deletions
88
packages/api-explorer-ui/__tests__/fixtures/auth-types/oas.json
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,88 @@ | ||
{ | ||
"openapi": "3.0.0-rc2", | ||
"info": { | ||
"version": "1.0.0", | ||
"title": "Multiple Securities" | ||
}, | ||
"paths": { | ||
"/things": { | ||
"post": { | ||
"security": [ | ||
{ | ||
"oauth": ["write:things"] | ||
}, | ||
{ | ||
"apiKey": [] | ||
} | ||
] | ||
} | ||
}, | ||
"/api-key": { | ||
"post": { | ||
"security": [ | ||
{ | ||
"apiKey": [] | ||
} | ||
] | ||
} | ||
}, | ||
"/basic": { | ||
"post": { | ||
"security": [ | ||
{ | ||
"basic": [] | ||
} | ||
] | ||
} | ||
}, | ||
"/no-auth": { | ||
"post": {} | ||
}, | ||
"/multiple-oauths": { | ||
"post": { | ||
"security": [ | ||
{ | ||
"oauth": ["write:things", "read:things"] | ||
}, | ||
{ | ||
"oauthDiff": ["write:things", "read:things"] | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"components": { | ||
"securitySchemes": { | ||
"oauth": { | ||
"type": "oauth2", | ||
"flows": { | ||
"implicit": { | ||
"authorizationUrl": "http://example.com/oauth/dialog", | ||
"scopes": { | ||
"write:things": "Add things to your account" | ||
} | ||
} | ||
} | ||
}, | ||
"oauthDiff": { | ||
"type": "oauth2", | ||
"flows": { | ||
"implicit": { | ||
"authorizationUrl": "http://example.com/oauth/dialog", | ||
"scopes": { | ||
"write:things": "Add things to your account" | ||
} | ||
} | ||
} | ||
}, | ||
"apiKey": { | ||
"type": "apiKey", | ||
"name": "apiKey", | ||
"in": "header" | ||
}, | ||
"basic": { | ||
"type": "basic" | ||
} | ||
} | ||
} | ||
} |
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
38 changes: 38 additions & 0 deletions
38
packages/api-explorer-ui/__tests__/lib/authRequired.test.jsx
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,38 @@ | ||
const AuthRequired = require('../../src/lib/authRequired'); | ||
const Oas = require('../../src/lib/Oas.js'); | ||
const petstore = require('../fixtures/petstore/oas'); | ||
const auth = require('../fixtures/auth-types/oas'); | ||
|
||
const oas = new Oas(petstore); | ||
const oas2 = new Oas(auth); | ||
|
||
describe('AuthRequired', () => { | ||
xit('should return false if auth data is not passed in for api key condition', () => { | ||
const operation = oas.operation('/pet/{petId}', 'patch'); | ||
|
||
expect(AuthRequired(operation)).toBe(null); | ||
}); | ||
it('should return false if auth data is not passed in for api key condition', () => { | ||
const operation = oas.operation('/pet/{petId}', 'get'); | ||
|
||
expect(AuthRequired(operation, { api_key: '' })).toBe(false); | ||
}); | ||
|
||
it('should return false if auth data is not passed in for oaut condition', () => { | ||
const operation = oas.operation('/pet/{petId}', 'delete'); | ||
|
||
expect(AuthRequired(operation, { petstore_auth: '' })).toBe(false); | ||
}); | ||
|
||
it('should return false if auth data is not passed in for basic condition', () => { | ||
const operation = oas2.operation('/basic', 'post'); | ||
|
||
expect(AuthRequired(operation, { basic: { username: '', password: '' } })).toBe(false); | ||
}); | ||
|
||
it('should return true if endpoint does not need auth or passed in auth is correct', () => { | ||
const operation = oas.operation('/store/order/{orderId}', 'get'); | ||
|
||
expect(AuthRequired(operation)).toBe(true); | ||
}); | ||
}); |
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
5 changes: 2 additions & 3 deletions
5
packages/api-explorer-ui/src/lib/endpoint.js → ...s/api-explorer-ui/src/lib/authRequired.js
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