websocket event authorizer now supports name and arn fields together#8335
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8335 +/- ##
=======================================
Coverage 88.01% 88.02%
=======================================
Files 249 249
Lines 9306 9308 +2
=======================================
+ Hits 8191 8193 +2
Misses 1115 1115
Continue to review full report at Codecov.
|
…(schema also changed)
medikoo
left a comment
There was a problem hiding this comment.
@zaldanaraul thank you! That looks very good. I have just remark concerning tests. We now stay away from old way of writing tests (as they're very problematic for eventual refactors), see my comment
| }); | ||
|
|
||
| it('should add authorizer config when authorizer is specified as an object with both arn and name', () => { | ||
| awsCompileWebsocketsEvents.serverless.service.functions = { |
There was a problem hiding this comment.
Let's configure this test with runServerless util. See: https://github.com/serverless/serverless/tree/master/test#unit-tests
There was a problem hiding this comment.
hi @medikoo I just did this. Please take a look to see if its appropriate
medikoo
left a comment
There was a problem hiding this comment.
Thank you @zaldanaraul ! That looks great. I've spotted just one issue in configured test
| const nameField = 'authName'; | ||
| const arnName = 'auth'; | ||
|
|
||
| runServerless({ |
There was a problem hiding this comment.
Let's use async/await (note also that here promise as being not returned is orphaned)
There was a problem hiding this comment.
@medikoo just changed to use async/await. This explains some issues I was having earlier. Thanks for pointing out!
There was a problem hiding this comment.
@zaldanaraul as I look they return the promise (note no brackets wrapping arrow function body).
There's no async/await as they were written before we could use it before breaking things. While it be nice to have everything migrated to async/await, it's not easily doable, do we do it on demand
There was a problem hiding this comment.
you're right. Just noticed the missing brackets. My bad!
Codecov Report
@@ Coverage Diff @@
## master #8335 +/- ##
==========================================
+ Coverage 88.01% 88.04% +0.02%
==========================================
Files 249 249
Lines 9306 9287 -19
==========================================
- Hits 8191 8177 -14
+ Misses 1115 1110 -5
Continue to review full report at Codecov.
|
| @@ -72,7 +72,7 @@ class AwsCompileWebsockets { | |||
| arn: { $ref: '#/definitions/awsArnString' }, | |||
There was a problem hiding this comment.
To fully fix #8328 we need to change here awsArnString to awsArn
| route: '$connect', | ||
| authorizer: { | ||
| name: nameField, | ||
| arn: `arn:aws:${arnName}`, |
There was a problem hiding this comment.
Let's use object form of ARN for this test
| websocketObj.authorizer.name = getAuthorizerNameFromArn( | ||
| event.websocket.authorizer.arn | ||
| ); | ||
| if (event.websocket.authorizer.name) { |
There was a problem hiding this comment.
To not be breaking, we actually need to consturct this resolution as:
if (_.isObject(event.websocket.authorizer.arn)) {
if (!event.websocket.authorizer.name) throw new ServerlessError(....)
websocketObj.authorizer.name = event.websocket.authorizer.name;
} else {
websocketObj.authorizer.name = getAuthorizerNameFromArn(...)
}|
Hi @medikoo , Just implemented suggested changes. Also had to change a line in Old: New: Please let me know if it needs further changes! |
medikoo
left a comment
There was a problem hiding this comment.
@zaldanaraul that looks great! I have just one last very minor remark and we're good to go
| if (_.isObject(event.websocket.authorizer.arn)) { | ||
| if (!event.websocket.authorizer.name) { | ||
| throw new ServerlessError( | ||
| 'Websocket Authorizer: Non-string arn needs to be accompanied with "name"' |
medikoo
left a comment
There was a problem hiding this comment.
Thank you @zaldanaraul !
Closes: #8328