Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions lib/apiGateway/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const authorizationScopes = Joi.array()
const authorizationType = Joi.alternatives().when('authorizerId', {
is: authorizerId.required(),
then: Joi.string()
.valid('CUSTOM')
.valid('CUSTOM', 'COGNITO_USER_POOLS')
.required(),
otherwise: Joi.alternatives().when('authorizationScopes', {
is: authorizationScopes.required(),
Expand Down Expand Up @@ -103,12 +103,7 @@ const proxy = Joi.object({
authorizationScopes,
roleArn,
acceptParameters
})
.oxor('authorizerId', 'authorizationScopes') // can have one of them, but not required
.error(
customErrorBuilder('object.oxor', 'cannot set both "authorizerId" and "authorizationScopes"')
)
.required()
}).required()

const stringOrRef = Joi.alternatives().try([
Joi.string(),
Expand Down
6 changes: 4 additions & 2 deletions lib/apiGateway/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ describe('#validateServiceProxies()', () => {
)
})

it('should throw if "authorizationType" is not set to "CUSTOM" when the "authorizerId" property is set', () => {
it('should throw if "authorizationType" is not set to "CUSTOM" or "COGNITO_USER_POOLS" when the "authorizerId" property is set', () => {
serverlessApigatewayServiceProxy.serverless.service.custom = {
apiGatewayServiceProxies: [
{
Expand All @@ -470,7 +470,7 @@ describe('#validateServiceProxies()', () => {

expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.throw(
serverless.classes.Error,
'child "kinesis" fails because [child "authorizationType" fails because ["authorizationType" must be one of [CUSTOM]]]'
'child "kinesis" fails because [child "authorizationType" fails because ["authorizationType" must be one of [CUSTOM, COGNITO_USER_POOLS]]]'
)
})

Expand Down Expand Up @@ -564,6 +564,7 @@ describe('#validateServiceProxies()', () => {
path: '/kinesis',
streamName: 'streamName',
authorizationType: 'COGNITO_USER_POOLS',
authorizerId: { Ref: 'SomeAuthorizerId' },
authorizationScopes: ['editor', 'owner'],
method: 'post'
}
Expand All @@ -575,6 +576,7 @@ describe('#validateServiceProxies()', () => {

expect(json.events[0].http.auth).to.deep.equal({
authorizationType: 'COGNITO_USER_POOLS',
authorizerId: { Ref: 'SomeAuthorizerId' },
authorizationScopes: ['editor', 'owner']
})
})
Expand Down