mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Updae tests
This commit is contained in:
parent
88ed6c9d47
commit
113ec4cceb
@ -120,13 +120,13 @@ describe('AwsDeployFunction', () => {
|
||||
});
|
||||
|
||||
describe('#normalizeArnRole', () => {
|
||||
let getAccountIdStub;
|
||||
let getAccountInfoStub;
|
||||
let getRoleStub;
|
||||
|
||||
beforeEach(() => {
|
||||
getAccountIdStub = sinon
|
||||
.stub(awsDeployFunction.provider, 'getAccountId')
|
||||
.resolves('123456789012');
|
||||
getAccountInfoStub = sinon
|
||||
.stub(awsDeployFunction.provider, 'getAccountInfo')
|
||||
.resolves({ accountId: '123456789012', partition: 'aws' });
|
||||
getRoleStub = sinon
|
||||
.stub(awsDeployFunction.provider, 'request')
|
||||
.resolves({ Arn: 'arn:aws:iam::123456789012:role/role_2' });
|
||||
@ -144,7 +144,7 @@ describe('AwsDeployFunction', () => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
awsDeployFunction.provider.getAccountId.restore();
|
||||
awsDeployFunction.provider.getAccountInfo.restore();
|
||||
awsDeployFunction.provider.request.restore();
|
||||
serverless.service.resources = undefined;
|
||||
});
|
||||
@ -153,7 +153,7 @@ describe('AwsDeployFunction', () => {
|
||||
const arn = 'arn:aws:iam::123456789012:role/role';
|
||||
|
||||
return awsDeployFunction.normalizeArnRole(arn).then((result) => {
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(false);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(false);
|
||||
expect(result).to.be.equal(arn);
|
||||
});
|
||||
});
|
||||
@ -162,7 +162,7 @@ describe('AwsDeployFunction', () => {
|
||||
const roleName = 'MyCustomRole';
|
||||
|
||||
return awsDeployFunction.normalizeArnRole(roleName).then((result) => {
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(true);
|
||||
expect(result).to.be.equal('arn:aws:iam::123456789012:role/role_123');
|
||||
});
|
||||
});
|
||||
@ -177,7 +177,7 @@ describe('AwsDeployFunction', () => {
|
||||
|
||||
return awsDeployFunction.normalizeArnRole(roleObj).then((result) => {
|
||||
expect(getRoleStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(false);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(false);
|
||||
expect(result).to.be.equal('arn:aws:iam::123456789012:role/role_2');
|
||||
});
|
||||
});
|
||||
@ -336,7 +336,7 @@ describe('AwsDeployFunction', () => {
|
||||
awsDeployFunction.options = options;
|
||||
|
||||
return expect(awsDeployFunction.updateFunctionConfiguration()).to.be.fulfilled
|
||||
.then(() => expect(updateFunctionConfigurationStub).to.not.be.called);
|
||||
.then(() => expect(updateFunctionConfigurationStub).to.not.be.called);
|
||||
});
|
||||
|
||||
it('should fail when using invalid characters in environment variable', () => {
|
||||
|
||||
@ -39,15 +39,18 @@ describe('#compileAuthorizers()', () => {
|
||||
|
||||
expect(resource.Type).to.equal('AWS::ApiGateway::Authorizer');
|
||||
expect(resource.Properties.AuthorizerResultTtlInSeconds).to.equal(300);
|
||||
expect(resource.Properties.AuthorizerUri).to.deep.equal({ 'Fn::Join': ['',
|
||||
[
|
||||
'arn:aws:apigateway:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/',
|
||||
{ 'Fn::GetAtt': ['SomeLambdaFunction', 'Arn'] },
|
||||
'/invocations',
|
||||
expect(resource.Properties.AuthorizerUri).to.deep.equal({
|
||||
'Fn::Join': ['',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':apigateway:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/',
|
||||
{ 'Fn::GetAtt': ['SomeLambdaFunction', 'Arn'] },
|
||||
'/invocations',
|
||||
],
|
||||
],
|
||||
],
|
||||
});
|
||||
expect(resource.Properties.IdentitySource).to.equal('method.request.header.Authorization');
|
||||
expect(resource.Properties.IdentityValidationExpression).to.equal(undefined);
|
||||
@ -77,15 +80,18 @@ describe('#compileAuthorizers()', () => {
|
||||
.compiledCloudFormationTemplate.Resources.AuthorizerApiGatewayAuthorizer;
|
||||
|
||||
expect(resource.Type).to.equal('AWS::ApiGateway::Authorizer');
|
||||
expect(resource.Properties.AuthorizerUri).to.deep.equal({ 'Fn::Join': ['',
|
||||
[
|
||||
'arn:aws:apigateway:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/',
|
||||
'foo',
|
||||
'/invocations',
|
||||
expect(resource.Properties.AuthorizerUri).to.deep.equal({
|
||||
'Fn::Join': ['',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':apigateway:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/',
|
||||
'foo',
|
||||
'/invocations',
|
||||
],
|
||||
],
|
||||
],
|
||||
});
|
||||
expect(resource.Properties.AuthorizerResultTtlInSeconds).to.equal(500);
|
||||
expect(resource.Properties.IdentitySource).to.equal('method.request.header.Custom');
|
||||
|
||||
@ -63,7 +63,9 @@ describe('#compileDeployment()', () => {
|
||||
[
|
||||
'https://',
|
||||
{ Ref: awsCompileApigEvents.apiGatewayRestApiLogicalId },
|
||||
'.execute-api.us-east-1.amazonaws.com/dev',
|
||||
'.execute-api.us-east-1.',
|
||||
{ Ref: "AWS::URLSuffix" },
|
||||
'/dev',
|
||||
],
|
||||
],
|
||||
},
|
||||
|
||||
@ -456,7 +456,7 @@ describe('#compileMethods()', () => {
|
||||
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json']
|
||||
).to.not.match(/undefined/);
|
||||
).to.not.match(/undefined/);
|
||||
});
|
||||
});
|
||||
|
||||
@ -479,8 +479,8 @@ describe('#compileMethods()', () => {
|
||||
|
||||
return awsCompileApigEvents.compileMethods().then(() => {
|
||||
const jsonRequestTemplatesString = awsCompileApigEvents.serverless.service.provider
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
const cognitoPoolClaimsRegex = /"cognitoPoolClaims"\s*:\s*(\{[^}]*\})/;
|
||||
const cognitoPoolClaimsString = jsonRequestTemplatesString.match(cognitoPoolClaimsRegex)[1];
|
||||
const cognitoPoolClaims = JSON.parse(cognitoPoolClaimsString);
|
||||
@ -507,8 +507,8 @@ describe('#compileMethods()', () => {
|
||||
|
||||
return awsCompileApigEvents.compileMethods().then(() => {
|
||||
const jsonRequestTemplatesString = awsCompileApigEvents.serverless.service.provider
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
const cognitoPoolClaimsRegex = /"cognitoPoolClaims"\s*:\s*(\{[^}]*\})/;
|
||||
const cognitoPoolClaimsString = jsonRequestTemplatesString.match(cognitoPoolClaimsRegex)[1];
|
||||
const cognitoPoolClaims = JSON.parse(cognitoPoolClaimsString);
|
||||
@ -536,8 +536,8 @@ describe('#compileMethods()', () => {
|
||||
|
||||
return awsCompileApigEvents.compileMethods().then(() => {
|
||||
const jsonRequestTemplatesString = awsCompileApigEvents.serverless.service.provider
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
.compiledCloudFormationTemplate.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json'];
|
||||
const cognitoPoolClaimsRegex = /"cognitoPoolClaims"\s*:\s*(\{[^}]*\})/;
|
||||
const cognitoPoolClaimsString = jsonRequestTemplatesString.match(cognitoPoolClaimsRegex)[1];
|
||||
const cognitoPoolClaims = JSON.parse(cognitoPoolClaimsString);
|
||||
@ -568,7 +568,7 @@ describe('#compileMethods()', () => {
|
||||
awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources.ApiGatewayMethodUsersCreatePost.Properties
|
||||
.Integration.RequestTemplates['application/json']
|
||||
).to.not.match(/extraCognitoPoolClaims/);
|
||||
).to.not.match(/extraCognitoPoolClaims/);
|
||||
});
|
||||
});
|
||||
|
||||
@ -665,7 +665,9 @@ describe('#compileMethods()', () => {
|
||||
).to.deep.equal({
|
||||
'Fn::Join': [
|
||||
'', [
|
||||
'arn:aws:apigateway:', { Ref: 'AWS::Region' },
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' }
|
||||
, ':apigateway:', { Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/', { 'Fn::GetAtt': ['FirstLambdaFunction', 'Arn'] },
|
||||
'/invocations',
|
||||
],
|
||||
@ -677,7 +679,9 @@ describe('#compileMethods()', () => {
|
||||
).to.deep.equal({
|
||||
'Fn::Join': [
|
||||
'', [
|
||||
'arn:aws:apigateway:', { Ref: 'AWS::Region' },
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':apigateway:', { Ref: 'AWS::Region' },
|
||||
':lambda:path/2015-03-31/functions/', { 'Fn::GetAtt': ['SecondLambdaFunction', 'Arn'] },
|
||||
'/invocations',
|
||||
],
|
||||
|
||||
@ -48,17 +48,21 @@ describe('#awsCompilePermissions()', () => {
|
||||
.Resources.FirstLambdaPermissionApiGateway
|
||||
.Properties.FunctionName['Fn::GetAtt'][0]).to.equal('FirstLambdaFunction');
|
||||
|
||||
const deepObj = { 'Fn::Join': ['',
|
||||
[
|
||||
'arn:aws:execute-api:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':',
|
||||
{ Ref: 'AWS::AccountId' },
|
||||
':',
|
||||
{ Ref: 'ApiGatewayRestApi' },
|
||||
'/*/*',
|
||||
],
|
||||
] };
|
||||
const deepObj = {
|
||||
'Fn::Join': ['',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':execute-api:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':',
|
||||
{ Ref: 'AWS::AccountId' },
|
||||
':',
|
||||
{ Ref: 'ApiGatewayRestApi' },
|
||||
'/*/*',
|
||||
],
|
||||
]
|
||||
};
|
||||
|
||||
expect(awsCompileApigEvents.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources.FirstLambdaPermissionApiGateway
|
||||
|
||||
@ -95,7 +95,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
],
|
||||
Resource: [
|
||||
{
|
||||
'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ `log-group:/aws/lambda/${qualifiedFunction}:*`,
|
||||
},
|
||||
],
|
||||
@ -107,7 +107,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
],
|
||||
Resource: [
|
||||
{
|
||||
'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ `log-group:/aws/lambda/${qualifiedFunction}:*:*`,
|
||||
},
|
||||
],
|
||||
@ -179,7 +179,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
}];
|
||||
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw(
|
||||
'missing the following properties: Effect');
|
||||
'missing the following properties: Effect');
|
||||
});
|
||||
|
||||
it('should throw error if a custom IAM policy statement does not have an Action field', () => {
|
||||
@ -189,7 +189,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
}];
|
||||
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw(
|
||||
'missing the following properties: Action');
|
||||
'missing the following properties: Action');
|
||||
});
|
||||
|
||||
it('should throw error if a custom IAM policy statement does not have a Resource field', () => {
|
||||
@ -199,7 +199,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
}];
|
||||
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw(
|
||||
'missing the following properties: Resource');
|
||||
'missing the following properties: Resource');
|
||||
});
|
||||
|
||||
it('should throw an error describing all problematics custom IAM policy statements', () => {
|
||||
@ -234,44 +234,44 @@ describe('#mergeIamTemplates()', () => {
|
||||
LogGroupName: awsPackage.provider.naming.getLogGroupName(functionName),
|
||||
},
|
||||
}
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('should add RetentionInDays to a CloudWatch LogGroup resource if logRetentionInDays is given'
|
||||
, () => {
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 5;
|
||||
const normalizedName = awsPackage.provider.naming.getLogGroupLogicalId(functionName);
|
||||
return awsPackage.mergeIamTemplates().then(() => {
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[normalizedName]
|
||||
).to.deep.equal(
|
||||
{
|
||||
Type: 'AWS::Logs::LogGroup',
|
||||
Properties: {
|
||||
LogGroupName: awsPackage.provider.naming.getLogGroupName(functionName),
|
||||
RetentionInDays: 5,
|
||||
},
|
||||
}
|
||||
);
|
||||
, () => {
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 5;
|
||||
const normalizedName = awsPackage.provider.naming.getLogGroupLogicalId(functionName);
|
||||
return awsPackage.mergeIamTemplates().then(() => {
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[normalizedName]
|
||||
).to.deep.equal(
|
||||
{
|
||||
Type: 'AWS::Logs::LogGroup',
|
||||
Properties: {
|
||||
LogGroupName: awsPackage.provider.naming.getLogGroupName(functionName),
|
||||
RetentionInDays: 5,
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error if RetentionInDays is 0 or not an integer'
|
||||
, () => {
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 0;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 'string';
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = [];
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = {};
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = undefined;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = null;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
});
|
||||
, () => {
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 0;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = 'string';
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = [];
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = {};
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = undefined;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
awsPackage.serverless.service.provider.logRetentionInDays = null;
|
||||
expect(() => awsPackage.mergeIamTemplates()).to.throw('should be an integer');
|
||||
});
|
||||
|
||||
it('should add a CloudWatch LogGroup resource if all functions use custom roles', () => {
|
||||
awsPackage.serverless.service.functions[functionName].role = 'something';
|
||||
@ -300,7 +300,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
LogGroupName: awsPackage.provider.naming.getLogGroupName(f.func0.name),
|
||||
},
|
||||
}
|
||||
);
|
||||
);
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[normalizedNames[1]]
|
||||
).to.deep.equal(
|
||||
@ -310,7 +310,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
LogGroupName: awsPackage.provider.naming.getLogGroupName(f.func1.name),
|
||||
},
|
||||
}
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -326,7 +326,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
.Resource
|
||||
).to.deep.equal([
|
||||
{
|
||||
'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ `log-group:/aws/lambda/${qualifiedFunction}:*`,
|
||||
},
|
||||
]);
|
||||
@ -339,7 +339,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
.Resource
|
||||
).to.deep.equal([
|
||||
{
|
||||
'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ `log-group:/aws/lambda/${qualifiedFunction}:*:*`,
|
||||
},
|
||||
]);
|
||||
@ -367,12 +367,16 @@ describe('#mergeIamTemplates()', () => {
|
||||
.Resource
|
||||
).to.deep.equal(
|
||||
[
|
||||
{ 'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func0:*' },
|
||||
{ 'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func1:*' },
|
||||
{
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func0:*'
|
||||
},
|
||||
{
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func1:*'
|
||||
},
|
||||
]
|
||||
);
|
||||
);
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()]
|
||||
.Properties
|
||||
@ -382,12 +386,16 @@ describe('#mergeIamTemplates()', () => {
|
||||
.Resource
|
||||
).to.deep.equal(
|
||||
[
|
||||
{ 'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func0:*:*' },
|
||||
{ 'Fn::Sub': 'arn:aws:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func1:*:*' },
|
||||
{
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func0:*:*'
|
||||
},
|
||||
{
|
||||
'Fn::Sub': 'arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:'
|
||||
+ 'log-group:/aws/lambda/func1:*:*'
|
||||
},
|
||||
]
|
||||
);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -409,7 +417,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
.then(() => expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()]
|
||||
).to.exist
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
it('should not add the default role if role is defined on a provider level', () => {
|
||||
@ -449,7 +457,7 @@ describe('#mergeIamTemplates()', () => {
|
||||
.then(() => expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()]
|
||||
).to.not.exist
|
||||
);
|
||||
);
|
||||
});
|
||||
|
||||
describe('ManagedPolicyArns property', () => {
|
||||
@ -463,8 +471,8 @@ describe('#mergeIamTemplates()', () => {
|
||||
|
||||
return awsPackage.mergeIamTemplates()
|
||||
.then(() => expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()].Properties.ManagedPolicyArns
|
||||
).to.not.exist
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()].Properties.ManagedPolicyArns
|
||||
).to.not.exist
|
||||
);
|
||||
});
|
||||
|
||||
@ -478,9 +486,15 @@ describe('#mergeIamTemplates()', () => {
|
||||
.then(() => {
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()].Properties.ManagedPolicyArns
|
||||
).to.deep.equal([
|
||||
'arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole',
|
||||
]);
|
||||
).to.deep.equal({
|
||||
'Fn::Join': ['',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole',
|
||||
]
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -504,9 +518,15 @@ describe('#mergeIamTemplates()', () => {
|
||||
.then(() => {
|
||||
expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()].Properties.ManagedPolicyArns
|
||||
).to.deep.equal([
|
||||
'arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole',
|
||||
]);
|
||||
).to.deep.equal({
|
||||
'Fn::Join': ['',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole',
|
||||
]
|
||||
]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -525,8 +545,8 @@ describe('#mergeIamTemplates()', () => {
|
||||
|
||||
return awsPackage.mergeIamTemplates()
|
||||
.then(() => expect(awsPackage.serverless.service.provider.compiledCloudFormationTemplate
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()]
|
||||
).to.not.exist
|
||||
.Resources[awsPackage.provider.naming.getRoleLogicalId()]
|
||||
).to.not.exist
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -393,9 +393,9 @@ describe('AwsProvider', () => {
|
||||
{},
|
||||
{ useCache: true }
|
||||
)
|
||||
.then(data => {
|
||||
expect(data.called).to.equal(true);
|
||||
});
|
||||
.then(data => {
|
||||
expect(data.called).to.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should resolve to the same response with mutiple parallel requests', () => {
|
||||
@ -442,19 +442,19 @@ describe('AwsProvider', () => {
|
||||
}
|
||||
|
||||
return BbPromise.all(requests)
|
||||
.then(results => {
|
||||
expect(_.size(results, numTests));
|
||||
_.forEach(results, result => {
|
||||
expect(result).to.deep.equal(expectedResult);
|
||||
.then(results => {
|
||||
expect(_.size(results, numTests));
|
||||
_.forEach(results, result => {
|
||||
expect(result).to.deep.equal(expectedResult);
|
||||
});
|
||||
return BbPromise.join(
|
||||
expect(sendStub).to.have.been.calledOnce,
|
||||
expect(requestSpy).to.have.callCount(numTests)
|
||||
);
|
||||
})
|
||||
.finally(() => {
|
||||
requestSpy.restore();
|
||||
});
|
||||
return BbPromise.join(
|
||||
expect(sendStub).to.have.been.calledOnce,
|
||||
expect(requestSpy).to.have.callCount(numTests)
|
||||
);
|
||||
})
|
||||
.finally(() => {
|
||||
requestSpy.restore();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -835,9 +835,10 @@ describe('AwsProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getAccountId()', () => {
|
||||
it('should return the AWS account id', () => {
|
||||
describe('#getAccountInfo()', () => {
|
||||
it('should return the AWS account id and partition', () => {
|
||||
const accountId = '12345678';
|
||||
const partition = 'aws';
|
||||
|
||||
const stsGetCallerIdentityStub = sinon
|
||||
.stub(awsProvider, 'request')
|
||||
@ -848,10 +849,11 @@ describe('AwsProvider', () => {
|
||||
Arn: 'arn:aws:sts::123456789012:assumed-role/ROLE-NAME/VWXYZ',
|
||||
});
|
||||
|
||||
return awsProvider.getAccountId()
|
||||
return awsProvider.getAccountInfo()
|
||||
.then((result) => {
|
||||
expect(stsGetCallerIdentityStub.calledOnce).to.equal(true);
|
||||
expect(result).to.equal(accountId);
|
||||
expect(result.accountId).to.equal(accountId);
|
||||
expect(result.partition).to.equal(partition);
|
||||
awsProvider.request.restore();
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
cognitoIdpArnExpr: /arn:[a-zA-Z\-]*:cognito-idp/,
|
||||
cognitoIdpArnExpr: /^arn:[a-zA-Z\-]*:cognito-idp/,
|
||||
lambdaArnExpr: /arn:[a-zA-Z\-]*:lambda/
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ describe('Platform', () => {
|
||||
|
||||
describe('#publishService()', () => {
|
||||
let getAuthTokenStub;
|
||||
let getAccountIdStub;
|
||||
let getAccountInfoStub;
|
||||
let endpointsRequestStub;
|
||||
let publishServiceRequestStub;
|
||||
|
||||
@ -114,7 +114,7 @@ describe('Platform', () => {
|
||||
// eslint-disable-next-line max-len
|
||||
'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE0OTc4ODMwMzMsImV4cCI6MTUyOTQxOTAzMywiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIm5pY2tuYW1lIjoiam9obmRvZSJ9.GD6sqQR3qLirnrvLKKrmOc7vgsHpqZ3TPwyG8ZI69ig'
|
||||
);
|
||||
getAccountIdStub = sinon.stub(platform.provider, 'getAccountId').resolves('acountId123');
|
||||
getAccountInfoStub = sinon.stub(platform.provider, 'getAccountInfo').resolves({ accountId: 'acountId123', partition: 'aws' });
|
||||
endpointsRequestStub = sinon.stub(platform.provider, 'request').resolves({
|
||||
Stacks: [
|
||||
{
|
||||
@ -128,7 +128,7 @@ describe('Platform', () => {
|
||||
|
||||
afterEach(() => {
|
||||
platform.getAuthToken.restore();
|
||||
platform.provider.getAccountId.restore();
|
||||
platform.provider.getAccountInfo.restore();
|
||||
platform.provider.request.restore();
|
||||
platform.publishServiceRequest.restore();
|
||||
console.log.restore();
|
||||
@ -143,7 +143,7 @@ describe('Platform', () => {
|
||||
|
||||
return platform.publishService().then(() => {
|
||||
expect(getAuthTokenStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(true);
|
||||
expect(endpointsRequestStub.calledOnce).to.be.equal(true);
|
||||
expect(publishServiceRequestStub.calledOnce).to.be.equal(true);
|
||||
const expected = { name: 'new-service-2', stage: undefined, functions: [] };
|
||||
@ -180,7 +180,7 @@ describe('Platform', () => {
|
||||
|
||||
return platform.publishService().then(() => {
|
||||
expect(getAuthTokenStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(true);
|
||||
expect(endpointsRequestStub.calledOnce).to.be.equal(true);
|
||||
expect(publishServiceRequestStub.calledOnce).to.be.equal(true);
|
||||
const expected = {
|
||||
@ -226,7 +226,7 @@ describe('Platform', () => {
|
||||
|
||||
return platform.publishService().then(() => {
|
||||
expect(getAuthTokenStub.calledOnce).to.be.equal(true);
|
||||
expect(getAccountIdStub.calledOnce).to.be.equal(false);
|
||||
expect(getAccountInfoStub.calledOnce).to.be.equal(false);
|
||||
expect(endpointsRequestStub.calledOnce).to.be.equal(false);
|
||||
expect(publishServiceRequestStub.calledOnce).to.be.equal(false);
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user