Skip to content

Commit b4e3911

Browse files
committed
Update checks and allow missing info property in openapi spec.
1 parent cbf939c commit b4e3911

4 files changed

Lines changed: 71 additions & 67 deletions

File tree

src/framework/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export interface OpenApiValidatorOpts {
8787
export namespace OpenAPIV3 {
8888
export interface Document {
8989
openapi: string;
90-
info: InfoObject;
90+
info?: InfoObject;
9191
servers?: ServerObject[];
9292
paths: PathsObject;
9393
components?: ComponentsObject;

src/middlewares/parsers/body.parse.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ export class BodySchemaParser {
3535
}
3636
}
3737

38-
for (const requestContentType of Object.keys(requestBody.content)
39-
.sort()
40-
.reverse()) {
38+
for (const requestContentType of Object.keys(requestBody.content).sort().reverse()) {
4139
if (requestContentType === '*/*') {
4240
content = requestBody.content[requestContentType];
4341
break;
4442
}
4543

46-
if (!new RegExp(/^[a-z]+\/\*$/).test(requestContentType)) {continue;} // not a wildcard of type application/*
44+
// not a wildcard of type application/*
45+
if (!new RegExp(/^[a-z]+\/\*$/).test(requestContentType)) {
46+
continue;
47+
}
4748

4849
const [type] = requestContentType.split('/', 1);
4950

tests/index.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,40 @@ describe('modelValidator.js', () => {
319319
// expectedExceptionObject: null
320320
// };
321321

322+
yield {
323+
name: 'Fails on invalid userId',
324+
request: {
325+
path: '/v1/users/Authress%7Cgoogle-oauth2%7C108076944510346272539/resources/Authress%3AAccountBilling/permissions/UPDATE',
326+
httpMethod: 'GET',
327+
headers: { 'Authorization': 'Bearer AUTH', 'Host': 'test13.api.authress.io', 'User-Agent': 'Amazon CloudFront' },
328+
queryStringParameters: {},
329+
pathParameters: {
330+
userId: 'Authress|google-oauth2|10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008076944510346272539',
331+
resourceUri: 'Authress:AccountBilling',
332+
permission: 'UPDATE'
333+
},
334+
route: '/v1/users/{userId}/resources/{resourceUri}/permissions/{permission}'
335+
},
336+
expectedExceptionObject: { title: 'InvalidRequest: request.path.userId must NOT have more than 64 characters.' }
337+
};
338+
339+
// yield {
340+
// name: 'Allows other language characters in userId',
341+
// request: {
342+
// path: '/v1/users/Authress%7Cgoogle-oauth2%7C%D0%A1%D0%B5%D1%80%D0%B3%D0%B5%D0%B9/resources/Authress%3AAccountBilling/permissions/UPDATE',
343+
// httpMethod: 'GET',
344+
// headers: { 'Authorization': 'Bearer AUTH', 'Host': 'test13.api.authress.io', 'User-Agent': 'Amazon CloudFront' },
345+
// queryStringParameters: {},
346+
// pathParameters: {
347+
// userId: 'Authress|google-oauth2|Сергей',
348+
// resourceUri: 'Authress:AccountBilling',
349+
// permission: 'UPDATE'
350+
// },
351+
// route: '/v1/users/{userId}/resources/{resourceUri}/permissions/{permission}'
352+
// },
353+
// expectedExceptionObject: null
354+
// };
355+
322356
yield {
323357
name: 'Failed an empty space is not allowed',
324358
request: {

tests/openapi.js

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,6 @@ const resourceManager = {
66

77
const spec = {
88
openapi: '3.0.0',
9-
info: {
10-
version: 'v1',
11-
title: 'Authress',
12-
description: `<p>
13-
<h2>Introduction</h2>
14-
<p>Welcome to the Authress Authorization API.
15-
<br>The Authress REST API provides the operations and resources necessary to create records, assign permissions, and verify any user in your platform.</p>
16-
<p><ul>
17-
<li>Manage multitenant platforms and create user tenants for SSO connections.</li>
18-
<li>Create records to assign roles and resources to grant access for users.</li>
19-
<li>Check user access control by calling the authorization API at the right time.</li>
20-
<li>Configure service clients to securely access services in your platform.</li>
21-
</ul></p>
22-
<p>For more in-depth scenarios check out the <a href="https://authress.io/knowledge-base" target="_blank">Authress knowledge base</a>.</p>
23-
</p>`,
24-
contact: {
25-
name: 'Authress Support',
26-
email: 'support@authress.io'
27-
}
28-
},
29-
tags: [
30-
{ name: 'User Permissions' },
31-
{ name: 'Groups' },
32-
{ name: 'Roles' },
33-
{ name: 'Access Records' },
34-
{ name: 'Service Clients' },
35-
{ name: 'Resource Permissions' },
36-
{ name: 'Accounts' },
37-
{ name: 'Login Management' }
38-
],
399
paths: {
4010
'/v1/users/{userId}/resources': {
4111
get: {
@@ -51,9 +21,7 @@ const spec = {
5121
description: 'The user to check permissions on',
5222
required: true,
5323
schema: {
54-
type: 'string',
55-
minLength: 1,
56-
maxLength: 64
24+
$ref: '#/components/schemas/User/properties/userId'
5725
}
5826
},
5927
{
@@ -234,9 +202,7 @@ const spec = {
234202
description: 'The user to check permissions on',
235203
required: true,
236204
schema: {
237-
type: 'string',
238-
minLength: 1,
239-
maxLength: 64
205+
$ref: '#/components/schemas/User/properties/userId'
240206
}
241207
},
242208
{
@@ -289,9 +255,7 @@ const spec = {
289255
description: 'The user to check permissions on',
290256
required: true,
291257
schema: {
292-
type: 'string',
293-
minLength: 1,
294-
maxLength: 64
258+
$ref: '#/components/schemas/User/properties/userId'
295259
}
296260
},
297261
{
@@ -349,9 +313,7 @@ const spec = {
349313
description: 'The user to get roles for.',
350314
required: true,
351315
schema: {
352-
type: 'string',
353-
minLength: 1,
354-
maxLength: 64
316+
$ref: '#/components/schemas/User/properties/userId'
355317
}
356318
},
357319
{
@@ -2162,9 +2124,7 @@ const spec = {
21622124
description: 'The connection user.',
21632125
required: true,
21642126
schema: {
2165-
type: 'string',
2166-
minLength: 1,
2167-
maxLength: 64
2127+
$ref: '#/components/schemas/User/properties/userId'
21682128
}
21692129
}
21702130
],
@@ -2619,6 +2579,16 @@ const spec = {
26192579
}
26202580
}
26212581
},
2582+
defaultConnectionProperties: {
2583+
type: 'object',
2584+
properties: {
2585+
scope: {
2586+
type: 'string',
2587+
default: 'profile email openid',
2588+
maxLength: 128
2589+
}
2590+
}
2591+
},
26222592
createdTime: {
26232593
readOnly: true,
26242594
type: 'string',
@@ -2837,8 +2807,9 @@ const spec = {
28372807
properties: {
28382808
userId: {
28392809
type: 'string',
2810+
pattern: '^[a-zA-Z0-9-._|/~:@]+$',
28402811
minLength: 1,
2841-
maxLength: 128
2812+
maxLength: 64
28422813
}
28432814
}
28442815
},
@@ -3084,6 +3055,7 @@ const spec = {
30843055
},
30853056
AccessRequestResponse: {
30863057
description: 'A dynamic body to support request PATCH operations',
3058+
type: 'object',
30873059
additionalProperties: false,
30883060
required: ['status'],
30893061
properties: {
@@ -3388,7 +3360,7 @@ const spec = {
33883360
example: ''
33893361
},
33903362
options: {
3391-
description: 'A map of client specific options',
3363+
description: 'A set of client specific options',
33923364
type: 'object',
33933365
additionalProperties: false,
33943366
properties: {
@@ -3398,6 +3370,13 @@ const spec = {
33983370
nullable: true,
33993371
example: false,
34003372
default: false
3373+
},
3374+
grantTokenGeneration: {
3375+
description: 'Grant the client access to generate oauth tokens on behalf of the Authress account. Security Warning: This means that this client can impersonate any user, and should only be used when connecting an existing custom Authorization Server to Authress, when that server does not support a standard OAuth connection.',
3376+
type: 'boolean',
3377+
nullable: true,
3378+
example: false,
3379+
default: false
34013380
}
34023381
// grantMetadataAccess: {
34033382
// description: 'Grant the client access to read and write user data on behalf of any user',
@@ -3520,9 +3499,7 @@ const spec = {
35203499
},
35213500
userId: {
35223501
readOnly: true,
3523-
type: 'string',
3524-
minLength: 1,
3525-
maxLength: 128
3502+
$ref: '#/components/schemas/User/properties/userId'
35263503
},
35273504
metadata: {
35283505
description: 'A JSON object limited to 10KB. The owner identified by the sub will always have access to read and update this data. Service clients may have access if the related property on the client is set. Access is restricted to authorized users.',
@@ -3576,9 +3553,7 @@ const spec = {
35763553
}
35773554
},
35783555
userId: {
3579-
type: 'string',
3580-
minLength: 1,
3581-
maxLength: 128
3556+
$ref: '#/components/schemas/User/properties/userId'
35823557
},
35833558
permissions: {
35843559
description: 'A list of the permissions',
@@ -3596,9 +3571,7 @@ const spec = {
35963571
required: ['userId', 'roles'],
35973572
properties: {
35983573
userId: {
3599-
type: 'string',
3600-
minLength: 1,
3601-
maxLength: 128
3574+
$ref: '#/components/schemas/User/properties/userId'
36023575
},
36033576
roles: {
36043577
description: 'A list of the roles',
@@ -3637,9 +3610,7 @@ const spec = {
36373610
}
36383611
},
36393612
userId: {
3640-
type: 'string',
3641-
minLength: 1,
3642-
maxLength: 128
3613+
$ref: '#/components/schemas/User/properties/userId'
36433614
},
36443615
resources: {
36453616
description: 'A list of the resources the user has some permission to.',
@@ -3692,9 +3663,7 @@ const spec = {
36923663
}
36933664
},
36943665
userId: {
3695-
type: 'string',
3696-
minLength: 1,
3697-
maxLength: 128
3666+
$ref: '#/components/schemas/User/properties/userId'
36983667
},
36993668
tokenId: {
37003669
description: 'The unique identifier for the token',

0 commit comments

Comments
 (0)