forked from aws-amplify/amplify-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix null check for implied owner check (aws-amplify#8586)
- Loading branch information
Showing
3 changed files
with
161 additions
and
12 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
...ages/amplify-graphql-auth-transformer/src/__tests__/__snapshots__/owner-auth.test.ts.snap
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ownerfield where the field is a list 1`] = ` | ||
"## [Start] Authorization Steps. ** | ||
$util.qr($ctx.stash.put(\\"hasAuth\\", true)) | ||
#set( $inputFields = $util.parseJson($util.toJson($ctx.args.input.keySet())) ) | ||
#set( $isAuthorized = false ) | ||
#set( $allowedFields = [] ) | ||
#if( $util.authType() == \\"User Pool Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#set( $ownerEntity0 = $util.defaultIfNull($ctx.args.input.editors, null) ) | ||
#set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) | ||
#set( $ownerAllowedFields0 = [] ) | ||
#foreach( $allowedOwner in $ownerEntity0 ) | ||
#if( $allowedOwner == $ownerClaim0 ) | ||
#if( !$ownerAllowedFields0.isEmpty() ) | ||
$util.qr($allowedFields.addAll($ownerAllowedFields0)) | ||
#else | ||
#set( $isAuthorized = true ) | ||
#break | ||
#end | ||
#end | ||
#end | ||
#if( $util.isNull($ownerEntity0) && !$ctx.args.input.containsKey(\\"editors\\") ) | ||
$util.qr($ctx.args.input.put(\\"editors\\", [$ownerClaim0])) | ||
#if( !$ownerAllowedFields0.isEmpty() ) | ||
$util.qr($allowedFields.addAll($ownerAllowedFields0)) | ||
#else | ||
#set( $isAuthorized = true ) | ||
#end | ||
#end | ||
#end | ||
#end | ||
#if( !$isAuthorized && $allowedFields.isEmpty() ) | ||
$util.unauthorized() | ||
#end | ||
#if( !$isAuthorized ) | ||
#set( $deniedFields = $util.list.copyAndRemoveAll($inputFields, $allowedFields) ) | ||
#if( $deniedFields.size() > 0 ) | ||
$util.error(\\"Unauthorized on \${deniedFields}\\", \\"Unauthorized\\") | ||
#end | ||
#end | ||
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}}) | ||
## [End] Authorization Steps. **" | ||
`; | ||
|
||
exports[`ownerfield where the field is a list 2`] = ` | ||
"## [Start] Get Request template. ** | ||
#set( $GetRequest = { | ||
\\"version\\": \\"2018-05-29\\", | ||
\\"operation\\": \\"GetItem\\" | ||
} ) | ||
#if( $ctx.stash.metadata.modelObjectKey ) | ||
#set( $key = $ctx.stash.metadata.modelObjectKey ) | ||
#else | ||
#set( $key = { | ||
\\"id\\": $util.dynamodb.toDynamoDB($ctx.args.input.id) | ||
} ) | ||
#end | ||
$util.qr($GetRequest.put(\\"key\\", $key)) | ||
$util.toJson($GetRequest) | ||
## [End] Get Request template. **" | ||
`; | ||
|
||
exports[`ownerfield where the field is a list 3`] = ` | ||
"## [Start] Get Request template. ** | ||
#set( $GetRequest = { | ||
\\"version\\": \\"2018-05-29\\", | ||
\\"operation\\": \\"GetItem\\" | ||
} ) | ||
#if( $ctx.stash.metadata.modelObjectKey ) | ||
#set( $key = $ctx.stash.metadata.modelObjectKey ) | ||
#else | ||
#set( $key = { | ||
\\"id\\": $util.dynamodb.toDynamoDB($ctx.args.input.id) | ||
} ) | ||
#end | ||
$util.qr($GetRequest.put(\\"key\\", $key)) | ||
$util.toJson($GetRequest) | ||
## [End] Get Request template. **" | ||
`; | ||
|
||
exports[`ownerfield where the field is a list 4`] = ` | ||
"## [Start] Authorization Steps. ** | ||
$util.qr($ctx.stash.put(\\"hasAuth\\", true)) | ||
#set( $isAuthorized = false ) | ||
#set( $primaryFieldMap = {} ) | ||
#if( $util.authType() == \\"User Pool Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#set( $authFilter = [{ | ||
\\"editors\\": { | ||
\\"contains\\": $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) | ||
} | ||
}] ) | ||
$util.qr($ctx.stash.put(\\"authFilter\\", { \\"or\\": $authFilter })) | ||
#end | ||
#end | ||
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) && $primaryFieldMap.isEmpty() ) | ||
$util.unauthorized() | ||
#end | ||
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}}) | ||
## [End] Authorization Steps. **" | ||
`; | ||
|
||
exports[`ownerfield where the field is a list 5`] = ` | ||
"## [Start] Authorization Steps. ** | ||
$util.qr($ctx.stash.put(\\"hasAuth\\", true)) | ||
#set( $isAuthorized = false ) | ||
#set( $primaryFieldMap = {} ) | ||
#if( $util.authType() == \\"User Pool Authorization\\" ) | ||
#if( !$isAuthorized ) | ||
#set( $authFilter = [{ | ||
\\"editors\\": { | ||
\\"contains\\": $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) | ||
} | ||
}] ) | ||
$util.qr($ctx.stash.put(\\"authFilter\\", { \\"or\\": $authFilter })) | ||
#end | ||
#end | ||
#if( !$isAuthorized && $util.isNull($ctx.stash.authFilter) && $primaryFieldMap.isEmpty() ) | ||
$util.unauthorized() | ||
#end | ||
$util.toJson({\\"version\\":\\"2018-05-29\\",\\"payload\\":{}}) | ||
## [End] Authorization Steps. **" | ||
`; |
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