From 4c5dd5f6c5ede4822be73bcdac55d0018a2abbd5 Mon Sep 17 00:00:00 2001 From: Danielle Adams Date: Tue, 26 Apr 2022 11:59:20 -0400 Subject: [PATCH] fix: add double colon to tests and fix relational snap --- ...phql-many-to-many-transformer.test.ts.snap | 24 ++++++++++++++--- .../src/__tests__/velocity/model-auth.test.ts | 26 +++++++++---------- .../velocity/relational-auth.test.ts | 2 +- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/packages/amplify-graphql-relational-transformer/src/__tests__/__snapshots__/amplify-graphql-many-to-many-transformer.test.ts.snap b/packages/amplify-graphql-relational-transformer/src/__tests__/__snapshots__/amplify-graphql-many-to-many-transformer.test.ts.snap index 9f89cb492f1..3d6fbdf4042 100644 --- a/packages/amplify-graphql-relational-transformer/src/__tests__/__snapshots__/amplify-graphql-many-to-many-transformer.test.ts.snap +++ b/packages/amplify-graphql-relational-transformer/src/__tests__/__snapshots__/amplify-graphql-many-to-many-transformer.test.ts.snap @@ -2616,6 +2616,11 @@ $util.qr($ctx.stash.put(\\"hasAuth\\", true)) #if( $util.authType() == \\"User Pool Authorization\\" ) #if( !$isAuthorized ) #set( $authFilter = [] ) + #set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) + #set( $currentClaim1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) + #set( $ownerClaim0 = \\"$ownerClaim0::$currentClaim1\\" ) + #if( $role0 != \\"___xamznone____\\" ) + $util.qr($authFilter.add({\\"owner\\": { \\"eq\\": $ownerClaim0 }})) #end #set( $role0_0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) #if( $role0_0 != \\"___xamznone____\\" ) @@ -2680,6 +2685,19 @@ $util.qr($ctx.stash.put(\\"hasAuth\\", true)) #if( $util.authType() == \\"User Pool Authorization\\" ) #if( !$isAuthorized ) #set( $authFilter = [] ) + #set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) + #set( $currentClaim1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) + #set( $ownerClaim0 = \\"$ownerClaim0::$currentClaim1\\" ) + #if( $role0 != \\"___xamznone____\\" ) + $util.qr($authFilter.add({\\"owner\\": { \\"eq\\": $ownerClaim0 }})) + #end + #set( $role0_0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) + #if( $role0_0 != \\"___xamznone____\\" ) + $util.qr($authFilter.add({\\"owner\\": { \\"eq\\": $role0_0 }})) + #end + #set( $role0_1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) + #if( $role0_1 != \\"___xamznone____\\" ) + $util.qr($authFilter.add({\\"owner\\": { \\"eq\\": $role0_1 }})) #end #if( !$authFilter.isEmpty() ) $util.qr($ctx.stash.put(\\"authFilter\\", { \\"or\\": $authFilter })) @@ -2721,7 +2739,7 @@ $util.qr($ctx.stash.put(\\"hasAuth\\", true)) #set( $ownerEntity0 = $util.defaultIfNull($ctx.args.input.owner, null) ) #set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) #set( $currentClaim1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) - #set( $ownerClaim0 = \\"$ownerClaim0:$currentClaim1\\" ) + #set( $ownerClaim0 = \\"$ownerClaim0::$currentClaim1\\" ) #set( $ownerClaimsList0 = [] ) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\"))) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")))) @@ -2810,7 +2828,7 @@ $util.qr($ctx.stash.put(\\"hasAuth\\", true)) #set( $ownerEntity0 = $util.defaultIfNull($ctx.result.owner, null) ) #set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) #set( $currentClaim1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) - #set( $ownerClaim0 = \\"$ownerClaim0:$currentClaim1\\" ) + #set( $ownerClaim0 = \\"$ownerClaim0::$currentClaim1\\" ) #set( $ownerClaimsList0 = [] ) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\"))) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")))) @@ -2949,7 +2967,7 @@ $util.qr($ctx.stash.put(\\"hasAuth\\", true)) #set( $ownerEntity0 = $util.defaultIfNull($ctx.result.owner, null) ) #set( $ownerClaim0 = $util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\") ) #set( $currentClaim1 = $util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")) ) - #set( $ownerClaim0 = \\"$ownerClaim0:$currentClaim1\\" ) + #set( $ownerClaim0 = \\"$ownerClaim0::$currentClaim1\\" ) #set( $ownerClaimsList0 = [] ) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"sub\\"), \\"___xamznone____\\"))) $util.qr($ownerClaimsList0.add($util.defaultIfNull($ctx.identity.claims.get(\\"username\\"), $util.defaultIfNull($ctx.identity.claims.get(\\"cognito:username\\"), \\"___xamznone____\\")))) diff --git a/packages/amplify-util-mock/src/__tests__/velocity/model-auth.test.ts b/packages/amplify-util-mock/src/__tests__/velocity/model-auth.test.ts index 7349842bc86..22a6676c2a4 100644 --- a/packages/amplify-util-mock/src/__tests__/velocity/model-auth.test.ts +++ b/packages/amplify-util-mock/src/__tests__/velocity/model-auth.test.ts @@ -59,7 +59,7 @@ describe('@model owner mutation checks', () => { expect(queryResponse.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${ownerRequest.jwt.sub}:user1` } }, + { owner: { eq: `${ownerRequest.jwt.sub}::user1` } }, { owner: { eq: `${ownerRequest.jwt.sub}` } }, { owner: { eq: 'user1' } }, ], @@ -73,7 +73,7 @@ describe('@model owner mutation checks', () => { expect(createVTLRequest.args).toBeDefined(); expect(createVTLRequest.hadException).toEqual(false); // since we have an owner rule we expect the owner field to be defined in the argument input - expect(createVTLRequest.args.input.owner).toEqual(`${ownerRequest.jwt.sub}:user1`); + expect(createVTLRequest.args.input.owner).toEqual(`${ownerRequest.jwt.sub}::user1`); const updateRequestTemplate = out.resolvers['Mutation.updatePost.auth.1.req.vtl']; const updateVTLRequest = vtlTemplate.render(updateRequestTemplate, { context: ownerContext, requestParameters: ownerRequest }); @@ -136,7 +136,7 @@ describe('@model owner mutation checks', () => { expect(createVTLRequest.args).toBeDefined(); expect(createVTLRequest.hadException).toEqual(false); // since we have an owner rule we expect the owner field to be defined in the argument input - expect(createVTLRequest.args.input.editor).toEqual(`${ownerRequest.jwt.sub}:user1`); + expect(createVTLRequest.args.input.editor).toEqual(`${ownerRequest.jwt.sub}::user1`); }); test('explicit owner with default field', () => { @@ -162,7 +162,7 @@ describe('@model owner mutation checks', () => { expect(createVTLRequest.args).toBeDefined(); expect(createVTLRequest.hadException).toEqual(false); // since we have an owner rule we expect the owner field to be defined in the argument input - expect(createVTLRequest.args.input.owner).toEqual(`${ownerRequest.jwt.sub}:user1`); + expect(createVTLRequest.args.input.owner).toEqual(`${ownerRequest.jwt.sub}::user1`); }); test('explicit owner with custom field', () => { @@ -188,7 +188,7 @@ describe('@model owner mutation checks', () => { expect(createVTLRequest.args).toBeDefined(); expect(createVTLRequest.hadException).toEqual(false); // since we have an owner rule we expect the owner field to be defined in the argument input - expect(createVTLRequest.args.input.editor).toEqual(`${ownerRequest.jwt.sub}:user1`); + expect(createVTLRequest.args.input.editor).toEqual(`${ownerRequest.jwt.sub}::user1`); const differentOwnerContext: AppSyncVTLContext = { arguments: { input: { id: '001', title: 'sample', editor: 'user2' } } }; const createVTLRequestWithErrors = vtlTemplate.render(createRequestTemplate, { @@ -231,7 +231,7 @@ describe('@model owner mutation checks', () => { expect(createVTLRequest.args).toBeDefined(); expect(createVTLRequest.hadException).toEqual(false); // since we have an owner rule we expect the owner field to be defined in the argument input - expect(createVTLRequest.args.input.editors).toEqual([`${ownerRequest.jwt.sub}:user1`]); + expect(createVTLRequest.args.input.editors).toEqual([`${ownerRequest.jwt.sub}::user1`]); // should fail if the list of users does not contain the currently signed user const failedCreateVTLRequest = vtlTemplate.render(createRequestTemplate, { @@ -344,7 +344,7 @@ describe('@model operations', () => { expect(readRequestAsOwner.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${ownerRequest.jwt.sub}:user1` } }, + { owner: { eq: `${ownerRequest.jwt.sub}::user1` } }, { owner: { eq: `${ownerRequest.jwt.sub}` } }, { owner: { eq: 'user1' } }, ], @@ -413,7 +413,7 @@ describe('@model operations', () => { expect(readPostsAsOwner.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${ownerRequest.jwt.sub}:user1` } }, + { owner: { eq: `${ownerRequest.jwt.sub}::user1` } }, { owner: { eq: `${ownerRequest.jwt.sub}` } }, { owner: { eq: 'user1' } }, ], @@ -479,7 +479,7 @@ describe('@model operations', () => { expect(readRequestAsOwner.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${ownerRequest.jwt.sub}:user1` } }, + { owner: { eq: `${ownerRequest.jwt.sub}::user1` } }, { owner: { eq: `${ownerRequest.jwt.sub}` } }, { owner: { eq: 'user1' } }, ], @@ -491,7 +491,7 @@ describe('@model operations', () => { expect(readRequestAsNonOwner.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${adminGroupRequest.jwt.sub}:user2` } }, + { owner: { eq: `${adminGroupRequest.jwt.sub}::user2` } }, { owner: { eq: `${adminGroupRequest.jwt.sub}` } }, { owner: { eq: 'user2' } }, ], @@ -807,8 +807,8 @@ describe('@model @primaryIndex @index auth', () => { expect(listAuthVTLRequest.stash.authFilter).toEqual( expect.objectContaining({ or: expect.arrayContaining([ - expect.objectContaining({ child: { eq: `${ownerRequest.jwt.sub}:user1` } }), - expect.objectContaining({ parent: { eq: `${ownerRequest.jwt.sub}:user1` } }), + expect.objectContaining({ child: { eq: `${ownerRequest.jwt.sub}::user1` } }), + expect.objectContaining({ parent: { eq: `${ownerRequest.jwt.sub}::user1` } }), ]), }), ); @@ -850,7 +850,7 @@ describe('@model @primaryIndex @index auth', () => { }, "expressionValues": Object { ":child": Object { - "S": "${ownerRequest.jwt.sub}:user1", + "S": "${ownerRequest.jwt.sub}::user1", }, ":parent": Object { "S": "$ctx.args.parent", diff --git a/packages/amplify-util-mock/src/__tests__/velocity/relational-auth.test.ts b/packages/amplify-util-mock/src/__tests__/velocity/relational-auth.test.ts index 0a7aea5011b..6f0e2f0557c 100644 --- a/packages/amplify-util-mock/src/__tests__/velocity/relational-auth.test.ts +++ b/packages/amplify-util-mock/src/__tests__/velocity/relational-auth.test.ts @@ -100,7 +100,7 @@ describe('relational tests', () => { expect(ownerFieldResponse.stash.authFilter).toEqual( expect.objectContaining({ or: [ - { owner: { eq: `${ownerRequest.jwt.sub}:user1` } }, + { owner: { eq: `${ownerRequest.jwt.sub}::user1` } }, { owner: { eq: `${ownerRequest.jwt.sub}` } }, { owner: { eq: 'user1' } }, ],