Skip to content

Commit cfa040d

Browse files
author
Mark
committed
User Tests fixed, ArangoDriver.getUsers() now works always on _system
1 parent 6391c6d commit cfa040d

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

src/main/java/com/arangodb/ArangoDriver.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
*/
102102
public class ArangoDriver extends BaseArangoDriver {
103103

104+
private static final String DATABASE_SYSTEM = "_system";
105+
private static final String COLLECTION_USERS = "_users";
104106
private static final String GRAPH_NAME = "graphName";
105107
private static final String VERTEX_EXAMPLE = "vertexExample";
106108
private final ArangoConfigure configure;
@@ -2950,7 +2952,8 @@ public DefaultEntity grantDatabaseAccess(String username, String database) throw
29502952
* @throws ArangoException
29512953
*/
29522954
public List<DocumentEntity<UserEntity>> getUsersDocument() throws ArangoException {
2953-
final DocumentCursor<UserEntity> documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class);
2955+
final DocumentCursor<UserEntity> documentCursor = simpleDriver.executeSimpleAllDocuments(DATABASE_SYSTEM,
2956+
COLLECTION_USERS, 0, 0, UserEntity.class);
29542957
return documentCursor.asList();
29552958
}
29562959

@@ -2961,7 +2964,8 @@ public List<DocumentEntity<UserEntity>> getUsersDocument() throws ArangoExceptio
29612964
* @throws ArangoException
29622965
*/
29632966
public List<UserEntity> getUsers() throws ArangoException {
2964-
final DocumentCursor<UserEntity> documentCursor = executeSimpleAllDocuments("_users", 0, 0, UserEntity.class);
2967+
final DocumentCursor<UserEntity> documentCursor = simpleDriver.executeSimpleAllDocuments(DATABASE_SYSTEM,
2968+
COLLECTION_USERS, 0, 0, UserEntity.class);
29652969
return documentCursor.asEntityList();
29662970
}
29672971

src/test/java/com/arangodb/ArangoDriverCursorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public void test_warning() throws ArangoException {
283283
}
284284
driver.truncateCollection(collectionName);
285285

286+
driver.setDefaultDatabase(null);
286287
final String query = "return _users + 1";
287288
final Map<String, Object> bindVars = new HashMap<String, Object>();
288289
final CursorResult<Long> cursor = driver.executeAqlQuery(query, bindVars, null, Long.class);

src/test/java/com/arangodb/ArangoDriverDatabaseAndUserTest.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,19 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc
7777
new UserEntity("user3", "pass3", true, new MapBuilder().put("attr1", "value1").get()),
7878
new UserEntity("user4", "pass4", false, new MapBuilder().put("attr2", "value2").get()));
7979
assertThat(entity.getResult(), is(true));
80+
driver.grantDatabaseAccess("user1", "_system");
81+
driver.grantDatabaseAccess("user4", DATABASE);
8082

8183
// change default db
82-
try {
83-
driver.createUser("user1", "pass1", true, null);
84-
} catch (final ArangoException e) {
85-
}
8684
driver.setDefaultDatabase(DATABASE);
8785

88-
// root user cannot access
89-
try {
90-
driver.getUsers();
91-
fail();
92-
} catch (final ArangoException e) {
93-
assertThat(e.isUnauthorized(), is(true));
94-
}
95-
9686
// user1 can access
9787
configure.setUser("user1");
9888
configure.setPassword("pass1");
9989
final StringsResultEntity res2 = driver.getDatabases(true);
10090
assertThat(res2.getResult(), is(Arrays.asList("_system", DATABASE)));
10191

102-
// user2 cannot access
92+
// user2 cannot access (inactive)
10393
configure.setUser("user2");
10494
configure.setPassword("pass2");
10595
try {
@@ -109,9 +99,11 @@ public void test_create_database_with_users_and_database_user() throws ArangoExc
10999
assertThat(e.isUnauthorized(), is(true));
110100
}
111101

102+
configure.setUser("root");
103+
configure.setPassword("");
104+
112105
final StringsResultEntity res3 = driver.getDatabases("user1", "pass1");
113106
assertThat(res3.getResult(), is(Arrays.asList("_system", DATABASE)));
114-
115107
}
116108

117109
}

0 commit comments

Comments
 (0)