-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3870 from swagger-api/bug/auth-operation-btn-error
Bug/auth operation btn error
- Loading branch information
Showing
6 changed files
with
168 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ node_modules | |
.idea | ||
.deps_check | ||
.DS_Store | ||
.nyc_output | ||
npm-debug.log* | ||
.eslintcache | ||
package-lock.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
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,133 @@ | ||
/* eslint-env mocha */ | ||
import expect from "expect" | ||
import { fromJS } from "immutable" | ||
import { definitionsToAuthorize, definitionsForRequirements } from "corePlugins/auth/selectors" | ||
|
||
describe("auth plugin - selectors", () => { | ||
describe("definitionsToAuthorize", () => { | ||
it("should return securityDefinitions as a List", () => { | ||
const securityDefinitions = { | ||
"petstore_auth": { | ||
"type": "oauth2", | ||
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog", | ||
"flow": "implicit", | ||
"scopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
}, | ||
"api_key": { | ||
"type": "apiKey", | ||
"name": "api_key", | ||
"in": "header" | ||
} | ||
} | ||
|
||
const system = { | ||
specSelectors: { | ||
securityDefinitions() { | ||
return fromJS(securityDefinitions) | ||
} | ||
} | ||
} | ||
|
||
const res = definitionsToAuthorize({})(system) | ||
|
||
expect(res.toJS()).toEqual([ | ||
{ | ||
"petstore_auth": securityDefinitions["petstore_auth"] | ||
}, | ||
{ | ||
"api_key": securityDefinitions["api_key"] | ||
}, | ||
]) | ||
}) | ||
|
||
it("should fail gracefully with bad data", () => { | ||
const securityDefinitions = null | ||
|
||
const system = { | ||
specSelectors: { | ||
securityDefinitions() { | ||
return fromJS(securityDefinitions) | ||
} | ||
} | ||
} | ||
|
||
const res = definitionsToAuthorize({})(system) | ||
|
||
expect(res.toJS()).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe("definitionsForRequirements", () => { | ||
it("should return applicable securityDefinitions as a List", () => { | ||
const securityDefinitions = { | ||
"petstore_auth": { | ||
"type": "oauth2", | ||
"authorizationUrl": "http://petstore.swagger.io/oauth/dialog", | ||
"flow": "implicit", | ||
"scopes": { | ||
"write:pets": "modify pets in your account", | ||
"read:pets": "read your pets" | ||
} | ||
}, | ||
"api_key": { | ||
"type": "apiKey", | ||
"name": "api_key", | ||
"in": "header" | ||
} | ||
} | ||
|
||
const system = { | ||
authSelectors: { | ||
definitionsToAuthorize() { | ||
return fromJS([ | ||
{ | ||
"petstore_auth": securityDefinitions["petstore_auth"] | ||
}, | ||
{ | ||
"api_key": securityDefinitions["api_key"] | ||
}, | ||
]) | ||
} | ||
} | ||
} | ||
|
||
const securities = fromJS([ | ||
{ | ||
"petstore_auth": [ | ||
"write:pets", | ||
"read:pets" | ||
] | ||
} | ||
]) | ||
|
||
const res = definitionsForRequirements({}, securities)(system) | ||
|
||
expect(res.toJS()).toEqual([ | ||
{ | ||
"petstore_auth": securityDefinitions["petstore_auth"] | ||
} | ||
]) | ||
}) | ||
|
||
it("should fail gracefully with bad data", () => { | ||
const securityDefinitions = null | ||
|
||
const system = { | ||
authSelectors: { | ||
definitionsToAuthorize() { | ||
return null | ||
} | ||
} | ||
} | ||
|
||
const securities = null | ||
|
||
const res = definitionsForRequirements({}, securities)(system) | ||
|
||
expect(res.toJS()).toEqual([]) | ||
}) | ||
}) | ||
}) |