use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testGetAccess.
@Test
public void testGetAccess() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
Id group = authManager.createGroup(makeGroup("group1"));
Id target1 = authManager.createTarget(makeTarget("graph1", "url1"));
Id target2 = authManager.createTarget(makeTarget("graph2", "url2"));
Id id1 = authManager.createAccess(makeAccess(group, target1, HugePermission.READ));
Id id2 = authManager.createAccess(makeAccess(group, target2, HugePermission.READ));
HugeAccess access1 = authManager.getAccess(id1);
Assert.assertEquals(target1, access1.target());
HugeAccess access2 = authManager.getAccess(id2);
Assert.assertEquals(target2, access2.target());
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getAccess(IdGenerator.of("fake"));
});
Assert.assertThrows(NotFoundException.class, () -> {
authManager.getAccess(null);
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Id user = authManager.createUser(makeUser("tom", "pass1"));
Id belong = authManager.createBelong(makeBelong(user, group));
authManager.getAccess(belong);
});
}
use of com.baidu.hugegraph.auth.AuthManager 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.AuthManager 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.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testListAllTargets.
@Test
public void testListAllTargets() {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
authManager.createTarget(makeTarget("target1", "url1"));
authManager.createTarget(makeTarget("target2", "url1"));
List<HugeTarget> targets = authManager.listAllTargets(-1);
Assert.assertEquals(2, targets.size());
Assert.assertEquals(ImmutableSet.of("target1", "target2"), ImmutableSet.of(targets.get(0).name(), targets.get(1).name()));
Assert.assertEquals(0, authManager.listAllTargets(0).size());
Assert.assertEquals(1, authManager.listAllTargets(1).size());
Assert.assertEquals(2, authManager.listAllTargets(2).size());
Assert.assertEquals(2, authManager.listAllTargets(3).size());
}
use of com.baidu.hugegraph.auth.AuthManager in project incubator-hugegraph by apache.
the class AuthTest method testUpdateGroup.
@Test
public void testUpdateGroup() throws InterruptedException {
HugeGraph graph = graph();
AuthManager authManager = graph.authManager();
HugeGroup group = makeGroup("group1");
group.description("description1");
Id id = authManager.createGroup(group);
group = authManager.getGroup(id);
Assert.assertEquals("group1", group.name());
Assert.assertEquals("description1", group.description());
Assert.assertEquals(group.create(), group.update());
Date oldUpdateTime = group.update();
Thread.sleep(1L);
group.description("description2");
authManager.updateGroup(group);
HugeGroup group2 = authManager.getGroup(id);
Assert.assertEquals("group1", group2.name());
Assert.assertEquals("description2", group2.description());
Assert.assertEquals(oldUpdateTime, group2.create());
Assert.assertNotEquals(oldUpdateTime, group2.update());
}
Aggregations