Skip to content

Commit 77a0226

Browse files
authored
feat: properly handle cookie auth (#216)
* feat: properly handle cookie auth * test: removing a now-filled test todo 🙂
1 parent 06f17b6 commit 77a0226

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

packages/tooling/__tests__/operation.test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,20 @@ describe('#prepareSecurity()', () => {
197197
});
198198
});
199199

200+
it('apiKey/cookie: should return with a type of Cookie', () => {
201+
const oas = createSecurityOas({
202+
securityScheme: {
203+
type: 'apiKey',
204+
in: 'cookie',
205+
},
206+
});
207+
const operation = oas.operation(path, method);
208+
209+
expect(operation.prepareSecurity()).toStrictEqual({
210+
Cookie: [oas.components.securitySchemes.securityScheme],
211+
});
212+
});
213+
200214
it('should work for petstore', () => {
201215
const operation = new Oas(petstore).operation('/pet', 'post');
202216

@@ -224,9 +238,6 @@ describe('#prepareSecurity()', () => {
224238

225239
it.todo('should set a `key` property');
226240

227-
// TODO We dont currently support cookies?
228-
it.todo('apiKey/cookie: should return with a type of Cookie');
229-
230241
it.todo('should throw if attempting to use a non-existent scheme');
231242

232243
it('should return empty object if no security', () => {
@@ -311,7 +322,7 @@ describe('#getHeaders()', () => {
311322
const operation = new Operation(oas, logOperation.url.path, logOperation.url.method, logOperation.operation);
312323

313324
expect(operation.getHeaders()).toMatchObject({
314-
request: ['Cookie', 'Authorization', 'Accept'],
325+
request: ['Authorization', 'Cookie', 'Accept'],
315326
response: ['Content-Type'],
316327
});
317328
});

packages/tooling/src/operation.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class Operation {
5959
type = 'OAuth2';
6060
} else if (security.type === 'apiKey') {
6161
if (security.in === 'query') type = 'Query';
62-
else if (security.in === 'header' || security.in === 'cookie') type = 'Header';
62+
else if (security.in === 'header') type = 'Header';
63+
else if (security.in === 'cookie') type = 'Cookie';
6364
} else {
6465
return false;
6566
}
@@ -90,7 +91,6 @@ class Operation {
9091
const security = this.prepareSecurity();
9192
if (security.Header) {
9293
this.headers.request = security.Header.map(h => {
93-
if (h.in === 'cookie') return 'Cookie';
9494
return h.name;
9595
});
9696
}
@@ -99,6 +99,10 @@ class Operation {
9999
this.headers.request.push('Authorization');
100100
}
101101

102+
if (security.Cookie) {
103+
this.headers.request.push('Cookie');
104+
}
105+
102106
if (this.parameters) {
103107
this.headers.request = this.headers.request.concat(
104108
this.parameters

0 commit comments

Comments
 (0)