use of com.baidu.hugegraph.client.RestClient in project incubator-hugegraph-toolchain by apache.
the class LogoutApiTest method testLogout.
@Test
public void testLogout() {
User user1 = new User();
user1.name("user1");
user1.password("p1");
userAPI.create(user1);
Login login = new Login();
login.name("user1");
login.password("p1");
LoginResult result = loginAPI.login(login);
Assert.assertNotNull(result);
Assert.assertNotNull(result.token());
// Client will set Authentication Header use Basic
Assert.assertThrows(ServerException.class, () -> {
logoutAPI.logout();
}, e -> {
Assert.assertContains("Only HTTP Bearer authentication is supported", e.getMessage());
});
String token = result.token();
RestClient client = Whitebox.getInternalState(logoutAPI, "client");
client.setAuthContext("Bearer " + token);
logoutAPI.logout();
}
use of com.baidu.hugegraph.client.RestClient in project incubator-hugegraph-toolchain by apache.
the class TokenApiTest method testVerify.
@Test
public void testVerify() {
User user1 = new User();
user1.name("user1");
user1.password("p1");
User user = userAPI.create(user1);
Login login = new Login();
login.name("user1");
login.password("p1");
LoginResult result = loginAPI.login(login);
Assert.assertNotNull(result);
Assert.assertNotNull(result.token());
// Client will set Authentication Header use Basic
Assert.assertThrows(ServerException.class, () -> {
tokenAPI.verifyToken();
}, e -> {
Assert.assertContains("Only HTTP Bearer authentication is supported", e.getMessage());
});
String token = result.token();
RestClient client = Whitebox.getInternalState(tokenAPI, "client");
client.setAuthContext("Bearer " + token);
TokenPayload payload = tokenAPI.verifyToken();
Assert.assertEquals("user1", payload.username());
Assert.assertEquals(user.id(), payload.userId());
client.setAuthContext("Bearer qweqwaasa");
Assert.assertThrows(ServerException.class, () -> {
tokenAPI.verifyToken();
}, e -> {
Assert.assertContains("Invalid token", e.getMessage());
});
RestClient client2 = Whitebox.getInternalState(logoutAPI, "client");
Assert.assertThrows(ServerException.class, () -> {
logoutAPI.logout();
}, e -> {
Assert.assertContains("Only HTTP Bearer authentication is supported", e.getMessage());
});
client2.setAuthContext("Bearer " + token);
logoutAPI.logout();
}
Aggregations