Skip to content
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

feat: 3.1.0 roles in security schema for all types #513

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/middlewares/openapi.security.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ class AuthValidator {
if (type === 'basic' && !authHeader.includes('basic')) {
throw Error(`Authorization header with scheme 'Basic' required`);
}

this.dissallowScopes();
}
}

Expand All @@ -300,17 +298,6 @@ class AuthValidator {
throw Error(`cookie '${scheme.name}' required`);
}
}

this.dissallowScopes();
}
}

private dissallowScopes(): void {
if (this.scopes.length > 0) {
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#security-requirement-object
throw new InternalServerError({
message: "scopes array must be empty for security type 'http'",
});
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions test/security.handlers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,18 +351,6 @@ describe('security.handlers', () => {
});
});

it('should return 500 if scopes are no allowed', async () =>
request(app)
.get(`${basePath}/api_key_with_scopes`)
.set('X-Api-Key', 'XXX')
.expect(500)
.then((r) => {
const body = r.body;
expect(body.message).to.equal(
"scopes array must be empty for security type 'http'",
);
}));

it('should return 200 if api_key or anonymous and no api key is supplied', async () => {
const validateSecurity = <ValidateSecurityOpts>eovConf.validateSecurity;
validateSecurity.handlers.ApiKeyAuth = <any>((req, scopes, schema) => true);
Expand Down