use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testListAllUsers.
@Test
public void testListAllUsers() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
authManager.createUser(makeUser("tom", "pass1"));
authManager.createUser(makeUser("james", "pass2"));
List<HugeUser> users = authManager.listAllUsers(-1);
Assert.assertEquals(2, users.size());
Assert.assertEquals(ImmutableSet.of("tom", "james"), ImmutableSet.of(users.get(0).name(), users.get(1).name()));
Assert.assertEquals(0, authManager.listAllUsers(0).size());
Assert.assertEquals(1, authManager.listAllUsers(1).size());
Assert.assertEquals(2, authManager.listAllUsers(2).size());
Assert.assertEquals(2, authManager.listAllUsers(3).size());
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testCreateUser.
@Test
public void testCreateUser() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id = authManager.createUser(makeUser("tom", "pass1"));
HugeUser user = authManager.getUser(id);
Assert.assertEquals("tom", user.name());
Assert.assertEquals("pass1", user.password());
Assert.assertEquals(user.create(), user.update());
Assert.assertNull(user.phone());
Assert.assertNull(user.email());
Assert.assertNull(user.avatar());
Map<String, Object> expected = new HashMap<>();
expected.putAll(ImmutableMap.of("user_name", "tom", "user_password", "pass1", "user_creator", "admin"));
expected.putAll(ImmutableMap.of("user_create", user.create(), "user_update", user.update(), "id", user.id()));
Assert.assertEquals(expected, user.asMap());
Assert.assertThrows(IllegalArgumentException.class, () -> {
authManager.createUser(makeUser("tom", "pass1"));
}, e -> {
Assert.assertContains("Can't save user", e.getMessage());
Assert.assertContains("that already exists", e.getMessage());
});
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class AuthTest method testListUsers.
@Test
public void testListUsers() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id id1 = authManager.createUser(makeUser("tom", "pass1"));
Id id2 = authManager.createUser(makeUser("james", "pass2"));
List<HugeUser> users = authManager.listUsers(ImmutableList.of(id1, id2));
Assert.assertEquals(2, users.size());
Assert.assertEquals("tom", users.get(0).name());
Assert.assertEquals("james", users.get(1).name());
users = authManager.listUsers(ImmutableList.of(id1, id2, id2));
Assert.assertEquals(3, users.size());
Assert.assertEquals("tom", users.get(0).name());
Assert.assertEquals("james", users.get(1).name());
Assert.assertEquals("james", users.get(2).name());
users = authManager.listUsers(ImmutableList.of(id1, id2, id1));
Assert.assertEquals(3, users.size());
Assert.assertEquals("tom", users.get(0).name());
Assert.assertEquals("james", users.get(1).name());
Assert.assertEquals("tom", users.get(2).name());
users = authManager.listUsers(ImmutableList.of(id1, id2, IdGenerator.of("fake")));
Assert.assertEquals(2, users.size());
}
use of com.baidu.hugegraph.auth.HugeUser in project incubator-hugegraph by apache.
the class RolePermissionTest method testHugeResourceFilterUser.
@Test
public void testHugeResourceFilterUser() {
HugeResource all = HugeResource.ALL;
// user
ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.USER_GROUP, NameObject.ANY);
Assert.assertFalse(all.filter(r3));
HugeResource user = new HugeResource(ResourceType.USER_GROUP, HugeResource.ANY, null);
Assert.assertTrue(user.filter(r3));
ResourceObject<?> r4 = ResourceObject.of("g1", new HugeUser("fake"));
Assert.assertTrue(user.filter(r4));
HugeResource user2 = new HugeResource(ResourceType.USER_GROUP, "bj-.*", null);
Assert.assertTrue(user2.filter(r3));
Assert.assertFalse(user2.filter(r4));
HugeResource user3 = new HugeResource(ResourceType.USER_GROUP, "fa.*", null);
Assert.assertTrue(user3.filter(r3));
Assert.assertTrue(user3.filter(r4));
ResourceObject<?> r5 = ResourceObject.of("g1", new HugeTarget("g", ""));
Assert.assertFalse(user.filter(r5));
HugeResource root = new HugeResource(ResourceType.ROOT, HugeResource.ANY, null);
Assert.assertTrue(root.filter(r3));
Assert.assertTrue(root.filter(r4));
Assert.assertTrue(root.filter(r5));
}
Aggregations