Skip to content

Commit 9762c1e

Browse files
Updating ACL tests to syncup changes with Dgraph v1.2 (#103)
- Removed try..catch block from tryReading() function - Added tests for when there is no ACL permission is passed - minor changes in delete tests' query to sort friends by name in ascending order Signed-off-by: Prashant Shahi <coolboi567@gmail.com>
1 parent c1ad859 commit 9762c1e

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

tests/integration/acl.spec.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ const DEV_GROUP = "dev";
2222
// tslint:disable-next-line mocha-no-side-effect-code
2323
const execute = promisify(exec);
2424

25-
// tslint:disable-next-line mocha-no-side-effect-code
26-
const QUERY_PERMISSION_DENIED = new Error("7 PERMISSION_DENIED:\
27-
unauthorized to query the predicate: unauthorized to do Read on predicate name");
2825
// tslint:disable-next-line mocha-no-side-effect-code
29-
const MUTATE_PERMISSION_DENIED = new Error("7 PERMISSION_DENIED:\
30-
unauthorized to mutate the predicate: unauthorized to do Write on predicate name");
26+
const MUTATE_PERMISSION_DENIED = new Error(`7 PERMISSION_DENIED:\
27+
unauthorized to mutate following predicates: ${PRED} \n`);
3128
// tslint:disable-next-line mocha-no-side-effect-code
32-
const ALTER_PERMISSION_DENIED = new Error("7 PERMISSION_DENIED:\
33-
unauthorized to alter the predicate: unauthorized to do Modify on predicate name");
29+
const ALTER_PERMISSION_DENIED = new Error(`7 PERMISSION_DENIED:\
30+
unauthorized to alter following predicates: ${PRED} \n`);
3431

3532
async function cmd(command: string) {
3633
try {
@@ -104,17 +101,18 @@ async function tryReading(): Promise<Boolean> {
104101
const txn = aclClient.newTxn();
105102
const query = `{
106103
me(func: has(${PRED})) {
107-
uid
108104
${PRED}
109105
}
110106
}`;
111-
try {
112-
const res: dgraph.Response = await txn.query(query);
113-
expect(res.getJson().me).not.toHaveLength(0);
114-
success = true;
115-
} catch (e) {
116-
expect(e).toEqual(QUERY_PERMISSION_DENIED);
107+
108+
const res: dgraph.Response = await txn.query(query);
109+
const data = res.getJson();
110+
if (data.me === undefined) {
111+
expect(data).toEqual({});
117112
success = false;
113+
} else {
114+
expect(data.me).not.toHaveLength(0);
115+
success = true;
118116
}
119117
return success;
120118
}
@@ -156,6 +154,13 @@ async function tryAltering(): Promise<Boolean> {
156154
}
157155

158156
describe("ACL tests", () => {
157+
it("has no access", async () => {
158+
await aclSetup();
159+
await expect(tryReading()).resolves.toBe(false);
160+
await expect(tryWriting()).resolves.toBe(false);
161+
await expect(tryAltering()).resolves.toBe(false);
162+
});
163+
159164
it("only has read access", async () => {
160165
await aclSetup();
161166
await changePermission(4);

tests/integration/delete.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe("delete", () => {
147147
schools {
148148
name
149149
}
150-
friends {
150+
friends (orderasc: name) {
151151
name
152152
age
153153
}

0 commit comments

Comments
 (0)