@@ -22,15 +22,12 @@ const DEV_GROUP = "dev";
22
22
// tslint:disable-next-line mocha-no-side-effect-code
23
23
const execute = promisify ( exec ) ;
24
24
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" ) ;
28
25
// 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` ) ;
31
28
// 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` ) ;
34
31
35
32
async function cmd ( command : string ) {
36
33
try {
@@ -104,17 +101,18 @@ async function tryReading(): Promise<Boolean> {
104
101
const txn = aclClient . newTxn ( ) ;
105
102
const query = `{
106
103
me(func: has(${ PRED } )) {
107
- uid
108
104
${ PRED }
109
105
}
110
106
}` ;
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 ( { } ) ;
117
112
success = false ;
113
+ } else {
114
+ expect ( data . me ) . not . toHaveLength ( 0 ) ;
115
+ success = true ;
118
116
}
119
117
return success ;
120
118
}
@@ -156,6 +154,13 @@ async function tryAltering(): Promise<Boolean> {
156
154
}
157
155
158
156
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
+
159
164
it ( "only has read access" , async ( ) => {
160
165
await aclSetup ( ) ;
161
166
await changePermission ( 4 ) ;
0 commit comments