added validation of environment variable names

This commit is contained in:
Bryan Pedlar 2016-11-19 21:40:10 -05:00
parent 1f1c63dc7a
commit ca41f63c48
2 changed files with 22 additions and 0 deletions

View File

@ -86,6 +86,12 @@ class AwsCompileFunctions {
this.serverless.service.provider.environment,
functionObject.environment
)
for(var key in newFunction.Properties.Environment.Variables){
// I pulled this from the bash man pages
if(!key.match(/^[A-Za-z_][a-zA-Z0-9_]*$/)){
throw new Error("Invalid characters in environment variable");
}
}
if ('role' in functionObject) {

View File

@ -420,6 +420,22 @@ describe('AwsCompileFunctions', () => {
};
});
it('should throw if invalid environment variable name', () => {
awsCompileFunctions.serverless.service.functions = {
func: {
handler: 'func.function.handler',
name: 'new-service-dev-func',
environment: {
'1test1': 'test1',
test2: 'test2',
},
},
};
expect(() => awsCompileFunctions.compileFunctions()).to.throw(Error);
});
it('should consider function based config when creating a function resource', () => {
awsCompileFunctions.serverless.service.functions = {
func: {