Skip to content

Commit 84f6d2e

Browse files
committed
Add tests for getMethodAuthorization
1 parent 4b35afd commit 84f6d2e

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

lib/deploy/events/apiGateway/methods.test.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,78 @@ describe('#methods()', () => {
242242
.to.equal('\'*\'');
243243
});
244244
});
245+
246+
describe('#getMethodAuthorization()', () => {
247+
it('should return resource properties with AuthorizationType: NONE if no authorizer provided', () => {
248+
const event = {
249+
path: 'foo/bar1',
250+
method: 'post'
251+
};
252+
253+
expect(serverlessStepFunctions.getMethodAuthorization(event)
254+
.Properties.AuthorizationType).to.equal('NONE');
255+
});
256+
257+
it('should return resource properties with AuthorizationType: AWS_IAM', () => {
258+
259+
const event = {
260+
authorizer: {
261+
type: 'AWS_IAM',
262+
authorizerId: 'foo12345',
263+
},
264+
};
265+
266+
expect(serverlessStepFunctions.getMethodAuthorization(event)
267+
.Properties.AuthorizationType).to.equal('AWS_IAM');
268+
});
269+
270+
it('should return resource properties with AuthorizationType: CUSTOM and authotizerId', () => {
271+
272+
const event = {
273+
authorizer: {
274+
type: 'CUSTOM',
275+
authorizerId: 'foo12345',
276+
},
277+
};
278+
279+
expect(serverlessStepFunctions.getMethodAuthorization(event)
280+
.Properties.AuthorizationType).to.equal('CUSTOM');
281+
expect(serverlessStepFunctions.getMethodAuthorization(event)
282+
.Properties.AuthorizerId).to.equal('foo12345');
283+
284+
});
285+
286+
it('should return resource properties with AuthorizationType: CUSTOM and resource reference', () => {
287+
const event = {
288+
authorizer: {
289+
name: 'authorizer',
290+
arn: { 'Fn::GetAtt': ['SomeLambdaFunction', 'Arn'] },
291+
resultTtlInSeconds: 300,
292+
identitySource: 'method.request.header.Authorization',
293+
},
294+
};
295+
296+
const autorization = serverlessStepFunctions.getMethodAuthorization(event)
297+
expect(autorization.Properties.AuthorizationType)
298+
.to.equal('CUSTOM');
299+
300+
expect(autorization.Properties.AuthorizerId)
301+
.to.deep.equal({ Ref: 'AuthorizerApiGatewayAuthorizer' });
302+
});
303+
304+
it('should return resource properties with AuthorizationType: COGNITO_USER_POOLS and resource reference', () => {
305+
const event = {
306+
authorizer: {
307+
name: 'authorizer',
308+
arn: 'arn:aws:cognito-idp:us-east-1:xxx:userpool/us-east-1_ZZZ',
309+
},
310+
};
311+
312+
const autorization = serverlessStepFunctions.getMethodAuthorization(event)
313+
expect(autorization.Properties.AuthorizationType)
314+
.to.equal('COGNITO_USER_POOLS');
315+
expect(autorization.Properties.AuthorizerId)
316+
.to.deep.equal({ Ref: 'AuthorizerApiGatewayAuthorizer' });
317+
});
318+
});
245319
});

0 commit comments

Comments
 (0)