-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Fix awsProvider.js : "Cannot use 'in' operator to search for '0' #5688
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -763,6 +763,141 @@ describe('Service', () => { | ||
expect(consoleLogStub.callCount).to.equal(2); | expect(consoleLogStub.callCount).to.equal(2); | ||
}); | }); | ||
}); | }); | ||
|
|||
describe('stage name validation', () => { | |||
function simulateRun(serverless) { | |||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: |
|||
return serverless.init().then(() => | |||
serverless.variables.populateService(serverless.pluginManager.cliOptions) | |||
.then(() => { | |||
serverless.service.mergeArrays(); | |||
serverless.service.setFunctionNames(serverless.processedInput.options); | |||
})); | |||
} | |||
|
|||
it(`should not throw an error if http event is absent and | |||
stage contains only alphanumeric, underscore and hyphen`, () => { | |||
const SUtils = new Utils(); | |||
const serverlessYml = { | |||
service: 'new-service', | |||
provider: { | |||
name: 'aws', | |||
stage: 'xyz-101_abc-123', | |||
}, | |||
functions: { | |||
first: { | |||
events: [], | |||
}, | |||
}, | |||
}; | |||
SUtils.writeFileSync(path.join(tmpDirPath, 'serverless.yml'), | |||
YAML.dump(serverlessYml)); | |||
|
|||
const serverless = new Serverless({ servicePath: tmpDirPath }); | |||
return expect(simulateRun(serverless)).to.eventually.be.fulfilled.then(() => { | |||
expect(() => serverless.service.validate()).to.not.throw(serverless.classes.Error); | |||
}); | |||
}); | |||
|
|||
it(`should not throw an error after variable population if http event is present and | |||
the populated stage contains only alphanumeric, underscore and hyphen`, () => { | |||
const SUtils = new Utils(); | |||
const serverlessYml = { | |||
service: 'new-service', | |||
provider: { | |||
name: 'aws', | |||
stage: '${opt:stage, "default-stage"}', | |||
}, | |||
functions: { | |||
first: { | |||
events: [ | |||
{ | |||
http: { | |||
path: 'foo', | |||
method: 'GET', | |||
}, | |||
}, | |||
], | |||
}, | |||
}, | |||
}; | |||
SUtils.writeFileSync(path.join(tmpDirPath, 'serverless.yml'), | |||
YAML.dump(serverlessYml)); | |||
|
|||
const serverless = new Serverless({ servicePath: tmpDirPath }); | |||
return expect(simulateRun(serverless)).to.eventually.be.fulfilled.then(() => { | |||
expect(() => serverless.service.validate()).to.not.throw(serverless.classes.Error); | |||
}); | |||
}); | |||
|
|||
it('should throw an error if http event is present and stage contains invalid chars', () => { | |||
const SUtils = new Utils(); | |||
const serverlessYml = { | |||
service: 'new-service', | |||
provider: { | |||
name: 'aws', | |||
stage: 'my@stage', | |||
}, | |||
functions: { | |||
first: { | |||
events: [ | |||
{ | |||
http: { | |||
path: 'foo', | |||
method: 'GET', | |||
}, | |||
}, | |||
], | |||
}, | |||
}, | |||
}; | |||
SUtils.writeFileSync(path.join(tmpDirPath, 'serverless.yml'), | |||
YAML.dump(serverlessYml)); | |||
|
|||
const serverless = new Serverless({ servicePath: tmpDirPath }); | |||
return expect(simulateRun(serverless)).to.eventually.be.fulfilled.then(() => { | |||
expect(() => serverless.service.validate()).to.throw(serverless.classes.Error, [ | |||
'Invalid stage name my@stage: it should contains only [-_a-zA-Z0-9]', | |||
'for AWS provider if http event are present', | |||
'according to API Gateway limitation.', | |||
].join(' ')); | |||
}); | |||
}); | |||
|
|||
it(`should throw an error after variable population | |||
if http event is present and stage contains hyphen`, () => { | |||
const SUtils = new Utils(); | |||
const serverlessYml = { | |||
service: 'new-service', | |||
provider: { | |||
name: 'aws', | |||
stage: '${opt:stage, "default:stage"}', | |||
}, | |||
functions: { | |||
first: { | |||
events: [ | |||
{ | |||
http: { | |||
path: 'foo', | |||
method: 'GET', | |||
}, | |||
}, | |||
], | |||
}, | |||
}, | |||
}; | |||
SUtils.writeFileSync(path.join(tmpDirPath, 'serverless.yml'), | |||
YAML.dump(serverlessYml)); | |||
|
|||
const serverless = new Serverless({ servicePath: tmpDirPath }); | |||
return expect(simulateRun(serverless)).to.eventually.be.fulfilled.then(() => { | |||
expect(() => serverless.service.validate()).to.throw(serverless.classes.Error, [ | |||
'Invalid stage name default:stage: it should contains only [-_a-zA-Z0-9]', | |||
'for AWS provider if http event are present', | |||
'according to API Gateway limitation.', | |||
].join(' ')); | |||
}); | |||
}); | |||
}); | |||
}); | }); | ||
|
|
||
describe('#mergeArrays', () => { | describe('#mergeArrays', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use
BbPromise.each
function instead offorEach
? We're currently enforcing the policy that all new code should be as async as possible since sync calls are on of the roots of the sloweness of the Framework.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be async technically.
But I think it is premature optimization and not necessary for this case.
Both
Service#getAllFunctions
andService#getAllEventsInFunction
used in validation are just iterating over functions (and its events).I assume number of those are several dozens in most cases, and thousands in very extreme situation.
I believe Node.js is fast enough for such number of elements.
And, other validations in
Service#validate
are also iterating over functions synchronousely.I can make them all asynchronously, but it requires changes a lot in existing tests.
I think it is better to optimize in another PR when users complains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exoego
OK 👍 Thank you for considering it 😄