Skip to content

Commit 088d882

Browse files
committed
add executeMutation test cases which do not provide impersonation options, bypassing auth policies
1 parent 5f34343 commit 088d882

File tree

1 file changed

+57
-3
lines changed

1 file changed

+57
-3
lines changed

test/integration/data-connect.spec.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ describe('getDataConnect()', () => {
755755
});
756756
});
757757

758-
it("should fail to use the impersonated user's auth.uid", async () => {
758+
it("should fail to execute a query using the impersonated user's auth.uid", async () => {
759759
return getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
760-
'ListUsersImpersonation'
761-
).execute().should.eventually.be.rejected.and.have.property('code', 'data-connect/permission-denied');
760+
'ListUsersImpersonationAnon'
761+
).execute().should.eventually.be.rejected.and.have.property('code', 'data-connect/query-error');
762762
});
763763
});
764764
});
@@ -1005,6 +1005,60 @@ describe('getDataConnect()', () => {
10051005
expect(queryResp.data.email.from.id).to.equal(fredUser.id);
10061006
});
10071007
});
1008+
1009+
describe('with no impersonation, bypassing auth policies', () => {
1010+
it('should successfully execute a mutation with @auth(level: PUBLIC)', async () => {
1011+
const resp = await getDataConnect(connectorConfig)
1012+
.mutationRef<InsertEmailResponse, InsertEmailVariables>(
1013+
'InsertEmailPublic',
1014+
{ id: `email_id_${Math.random() * 1000}` }
1015+
).execute();
1016+
expect(resp.data.email_insert.id).to.not.be.undefined;
1017+
});
1018+
1019+
it('should successfully execute a mutation with @auth(level: USER_ANON)', async () => {
1020+
const resp = await getDataConnect(connectorConfig)
1021+
.mutationRef<InsertEmailResponse, InsertEmailVariables>(
1022+
'InsertEmailUserAnon',
1023+
{ id: `email_id_${Math.random() * 1000}` }
1024+
).execute();
1025+
expect(resp.data.email_insert.id).to.not.be.undefined;
1026+
});
1027+
1028+
it('should successfully execute a mutation with @auth(level: USER)', async () => {
1029+
const resp = await getDataConnect(connectorConfig)
1030+
.mutationRef<InsertEmailResponse, InsertEmailVariables>(
1031+
'InsertEmailUser',
1032+
{ id: `email_id_${Math.random() * 1000}` }
1033+
).execute();
1034+
expect(resp.data.email_insert.id).to.not.be.undefined;
1035+
});
1036+
1037+
it('should successfully execute a mutation with @auth(level: USER_EMAIL_VERIFIED)', async () => {
1038+
const resp = await getDataConnect(connectorConfig)
1039+
.mutationRef<InsertEmailResponse, InsertEmailVariables>(
1040+
'InsertEmailUserEmailVerified',
1041+
{ id: `email_id_${Math.random() * 1000}` }
1042+
).execute();
1043+
expect(resp.data.email_insert.id).to.not.be.undefined;
1044+
});
1045+
1046+
it('should successfully execute a mutation with @auth(level: NO_ACCESS)', async () => {
1047+
const resp = await getDataConnect(connectorConfig)
1048+
.mutationRef<InsertEmailResponse, InsertEmailVariables>(
1049+
'InsertEmailNoAccess',
1050+
{ id: `email_id_${Math.random() * 1000}` }
1051+
).execute();
1052+
expect(resp.data.email_insert.id).to.not.be.undefined;
1053+
});
1054+
1055+
it("should fail to execute a mutation using the impersonated user's auth.uid", async () => {
1056+
return getDataConnect(connectorConfig).mutationRef<InsertEmailResponse, InsertEmailVariables>(
1057+
'InsertEmailImpersonation',
1058+
{ id: `email_id_${Math.random() * 1000}` },
1059+
).execute().should.eventually.be.rejected.and.have.property('code', 'data-connect/query-error');
1060+
});
1061+
});
10081062
});
10091063
});
10101064
});

0 commit comments

Comments
 (0)