Skip to content

Commit

Permalink
fix: add double colon to tests and fix relational snap
Browse files Browse the repository at this point in the history
  • Loading branch information
danielleadams committed Apr 26, 2022
1 parent ca1912e commit 4c5dd5f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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____\\" )
Expand Down Expand Up @@ -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 }))
Expand Down Expand Up @@ -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____\\"))))
Expand Down Expand Up @@ -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____\\"))))
Expand Down Expand Up @@ -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____\\"))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
],
Expand All @@ -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 });
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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, {
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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' } },
],
Expand Down Expand Up @@ -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' } },
],
Expand Down Expand Up @@ -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' } },
],
Expand All @@ -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' } },
],
Expand Down Expand Up @@ -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` } }),
]),
}),
);
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' } },
],
Expand Down

0 comments on commit 4c5dd5f

Please sign in to comment.