Skip to content

Commit 5f34343

Browse files
committed
add executeQuery test cases which do not provide impersonation options, bypassing auth policies
1 parent 85a6b4b commit 5f34343

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

test/integration/data-connect.spec.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,69 @@ describe('getDataConnect()', () => {
698698
expect(resp.data.users[0]).to.deep.equal(fredUser);
699699
});
700700
});
701+
702+
describe('with no impersonation, bypassing auth policies', () => {
703+
it('should successfully execute a query with @auth(level: PUBLIC)', async () => {
704+
const resp = await getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
705+
'ListUsersPublic'
706+
).execute();
707+
expect(resp.data.users).to.not.be.empty;
708+
expect(resp.data.users.length).to.equal(initialState.users.length);
709+
resp.data.users.forEach((user) => {
710+
expect(initialState.users).to.deep.include(user);
711+
});
712+
});
713+
714+
it('should successfully execute a query with @auth(level: USER_ANON)', async () => {
715+
const resp = await getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
716+
'ListUsersUserAnon'
717+
).execute();
718+
expect(resp.data.users).to.not.be.empty;
719+
expect(resp.data.users.length).to.equal(initialState.users.length);
720+
resp.data.users.forEach((user) => {
721+
expect(initialState.users).to.deep.include(user);
722+
});
723+
});
724+
725+
it('should successfully execute a query with @auth(level: USER)', async () => {
726+
const resp = await getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
727+
'ListUsersUser'
728+
).execute();
729+
expect(resp.data.users).to.not.be.empty;
730+
expect(resp.data.users.length).to.equal(initialState.users.length);
731+
resp.data.users.forEach((user) => {
732+
expect(initialState.users).to.deep.include(user);
733+
});
734+
});
735+
736+
it('should successfully execute a query with @auth(level: USER_EMAIL_VERIFIED)', async () => {
737+
const resp = await getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
738+
'ListUsersUserEmailVerified'
739+
).execute();
740+
expect(resp.data.users).to.not.be.empty;
741+
expect(resp.data.users.length).to.equal(initialState.users.length);
742+
resp.data.users.forEach((user) => {
743+
expect(initialState.users).to.deep.include(user);
744+
});
745+
});
746+
747+
it('should successfully execute a query with @auth(level: NO_ACCESS)', async () => {
748+
const resp = await getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
749+
'ListUsersNoAccess'
750+
).execute();
751+
expect(resp.data.users).to.not.be.empty;
752+
expect(resp.data.users.length).to.equal(initialState.users.length);
753+
resp.data.users.forEach((user) => {
754+
expect(initialState.users).to.deep.include(user);
755+
});
756+
});
757+
758+
it("should fail to use the impersonated user's auth.uid", async () => {
759+
return getDataConnect(connectorConfig).queryRef<ListUsersResponse>(
760+
'ListUsersImpersonation'
761+
).execute().should.eventually.be.rejected.and.have.property('code', 'data-connect/permission-denied');
762+
});
763+
});
701764
});
702765

703766
describe('mutationRef()', () => {

0 commit comments

Comments
 (0)