Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
feat: adding support for cookie auth (#817)
Browse files Browse the repository at this point in the history
* feat: adding support for cookie auth

* test: adding tests for cookie auth security handling

* docs: adding node-simple to the auth-types example def

* chore(deps): upgrading @readme/oas-tooling to 3.5.0
  • Loading branch information
erunion authored Jul 1, 2020
1 parent a40b605 commit 5a2ef14
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 9 deletions.
22 changes: 21 additions & 1 deletion example/swagger-files/auth-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@
}
]
}
},
"/anything/apiKey-cookie": {
"post": {
"summary": "ApiKey security type via cookie",
"responses": {
"200": {
"description": "OK"
}
},
"security": [
{
"apiKeyCookie": []
}
]
}
}
},
"components": {
Expand All @@ -89,10 +104,15 @@
"type": "apiKey",
"in": "query",
"name": "apiKey"
},
"apiKeyCookie": {
"type": "apiKey",
"in": "cookie",
"name": "apiKey"
}
}
},
"x-explorer-enabled": true,
"x-samples-enabled": true,
"x-samples-languages": ["curl", "node", "ruby", "javascript", "python"]
"x-samples-languages": ["curl", "node", "node-simple", "ruby", "javascript", "python"]
}
6 changes: 3 additions & 3 deletions packages/api-explorer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/api-explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@readme/markdown-magic": "^6.12.0",
"@readme/oas-extensions": "^6.10.2",
"@readme/oas-to-har": "^6.12.1",
"@readme/oas-tooling": "^3.4.7",
"@readme/oas-tooling": "^3.5.0",
"@readme/react-jsonschema-form": "^1.1.5",
"@readme/syntax-highlighter": "^6.10.2",
"@readme/variable": "^6.10.2",
Expand Down
32 changes: 32 additions & 0 deletions packages/oas-to-har/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,38 @@ describe('auth', () => {
]);
});

it('should work for cookie', () => {
expect(
oasToHar(
new Oas({
components: {
securitySchemes: {
'auth-cookie': {
type: 'apiKey',
name: 'authCookie',
in: 'cookie',
},
},
},
}),
{
path: '/security',
method: 'get',
security: [{ 'auth-cookie': [] }],
},
{},
{
'auth-cookie': 'value',
}
).log.entries[0].request.cookies
).toStrictEqual([
{
name: 'authCookie',
value: 'value',
},
]);
});

it('should work for multiple (||)', () => {
expect(
oasToHar(
Expand Down
6 changes: 3 additions & 3 deletions packages/oas-to-har/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/oas-to-har/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "src/index.js",
"dependencies": {
"@readme/oas-extensions": "^6.10.2",
"@readme/oas-tooling": "^3.4.7"
"@readme/oas-tooling": "^3.5.0"
},
"scripts": {
"inspect": "jsinspect",
Expand Down
5 changes: 5 additions & 0 deletions packages/oas-to-har/src/lib/configure-security.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ module.exports = function configureSecurity(oas, values, scheme) {
}

return harValue('headers', header);
} else if (security.in === 'cookie') {
return harValue('cookies', {
name: security.name,
value: values[scheme],
});
}
}

Expand Down

0 comments on commit 5a2ef14

Please sign in to comment.