-
Notifications
You must be signed in to change notification settings - Fork 12
Do not flatten securities #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e9ac5f5
84f21bd
f62ae24
ae676c9
c1545e7
7cc9841
5e80177
40232d7
9099020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,90 @@ const securityDefinitionsFixture: Dictionary<Security> = { | |
| }; | ||
|
|
||
| describe('accessors', () => { | ||
| const securityFixture = [ | ||
| const securityFixture: Array<Dictionary<string[], string>> = [ | ||
| { | ||
| api_key: [], | ||
| petstore_auth: ['write:pets', 'read:pets'], | ||
| }, | ||
| ]; | ||
|
|
||
| describe('relation between schemes', () => { | ||
| describe('when all of the given schemes are expected to be validated against', () => { | ||
| const securityFixtureWithAndRelation = securityFixture; | ||
|
|
||
| it('returns an array containing multiple elements', () => { | ||
| expect( | ||
| getSecurities( | ||
| { | ||
| securityDefinitions: securityDefinitionsFixture, | ||
| security: [], | ||
| }, | ||
| securityFixtureWithAndRelation, | ||
| ), | ||
| ).toEqual([ | ||
| [ | ||
| { | ||
| in: 'header', | ||
| name: 'api_key', | ||
| type: 'apiKey', | ||
| }, | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { | ||
| 'read:pets': 'read your pets', | ||
| 'write:pets': 'modify pets in your account', | ||
| }, | ||
| type: 'oauth2', | ||
| }, | ||
| ], | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('when one of the given schemes is expected to be validated against', () => { | ||
| it('returns arrays containing one element each', () => { | ||
| const securityFixtureWithOrRelation: Array<Dictionary<string[], string>> = [ | ||
| { | ||
| petstore_auth: ['write:pets', 'read:pets'], | ||
| }, | ||
| { | ||
| api_key: [], | ||
| }, | ||
XVincentX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ]; | ||
|
|
||
| expect( | ||
| getSecurities( | ||
| { | ||
| securityDefinitions: securityDefinitionsFixture, | ||
| security: [], | ||
| }, | ||
| securityFixtureWithOrRelation, | ||
| ), | ||
| ).toEqual([ | ||
| [ | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { | ||
| 'read:pets': 'read your pets', | ||
| 'write:pets': 'modify pets in your account', | ||
| }, | ||
| type: 'oauth2', | ||
| }, | ||
| ], | ||
| [ | ||
| { | ||
| in: 'header', | ||
| name: 'api_key', | ||
| type: 'apiKey', | ||
| }, | ||
| ], | ||
| ]); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getSecurities', () => { | ||
| test('given no security definitions should return empty array', () => { | ||
| expect( | ||
|
|
@@ -87,7 +164,7 @@ describe('accessors', () => { | |
| }, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good but needs some more tests: something that can prove we support both AND & OR cases.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chris-miaskowski @lag-of-death is there anything left to address here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lottamus, no, the test was added: |
||
| ], | ||
| ), | ||
| ).toEqual([{ in: 'header', name: 'api_key', type: 'apiKey' }]); | ||
| ).toEqual([[{ in: 'header', name: 'api_key', type: 'apiKey' }]]); | ||
| }); | ||
|
|
||
| test('given security with custom scopes should override global definition', () => { | ||
|
|
@@ -104,12 +181,14 @@ describe('accessors', () => { | |
| ], | ||
| ), | ||
| ).toEqual([ | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { 'read:pets': 'read your pets', 'write:pets': 'modify pets in your account' }, | ||
| type: 'oauth2', | ||
| }, | ||
| [ | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { 'read:pets': 'read your pets', 'write:pets': 'modify pets in your account' }, | ||
| type: 'oauth2', | ||
| }, | ||
| ], | ||
| ]); | ||
| }); | ||
|
|
||
|
|
@@ -123,13 +202,15 @@ describe('accessors', () => { | |
| securityFixture, | ||
| ), | ||
| ).toEqual([ | ||
| { in: 'header', name: 'api_key', type: 'apiKey' }, | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { 'write:pets': 'modify pets in your account', 'read:pets': 'read your pets' }, | ||
| type: 'oauth2', | ||
| }, | ||
| [ | ||
| { in: 'header', name: 'api_key', type: 'apiKey' }, | ||
| { | ||
| authorizationUrl: 'http://swagger.io/api/oauth/dialog', | ||
| flow: 'implicit', | ||
| scopes: { 'write:pets': 'modify pets in your account', 'read:pets': 'read your pets' }, | ||
| type: 'oauth2', | ||
| }, | ||
| ], | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason you can think of that we might need the security array's key here? Currently there is nothing tying this oauth2 object back to the security array. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lottamus, I think that given https://github.com/stoplightio/http-spec/pull/15/files#diff-f5ac86d0dd4d4fa1390aca28ac1fbc59L107-L112 it's OK to just not add this
securityKey? If it was not a problem before, it shouldn't be a problem now. We can address it later if it turns out to be an issue