use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testGetObjectList.
@Test
void testGetObjectList() {
JsonList<JsonUser> users = GET("/users/").content(HttpStatus.OK).getList("users", JsonUser.class);
assertEquals(1, users.size());
JsonUser user = users.get(0);
assertEquals("admin admin", user.getDisplayName());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testGetObject.
@Test
void testGetObject() {
String id = run(SomeUserId::new);
JsonUser userById = GET("/users/{id}", id).content(HttpStatus.OK).as(JsonUser.class);
assertTrue(userById.exists());
assertEquals(id, userById.getId());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class ApiTokenAuthenticationTest method testInvalidApiTokenAuthentication.
@Test
void testInvalidApiTokenAuthentication() {
final TokenAndKey tokenAndKey = createNewToken();
JsonUser user = GET(URI, ApiTokenHeader(tokenAndKey.key)).content().as(JsonUser.class);
assertEquals(adminUser.getUid(), user.getId());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class ApiTokenAuthenticationTest method testApiTokenAuthentication.
@Test
void testApiTokenAuthentication() {
final TokenAndKey tokenAndKey = createNewToken();
JsonUser user = GET(URI, ApiTokenHeader(tokenAndKey.key)).content().as(JsonUser.class);
assertEquals(adminUser.getUid(), user.getId());
assertEquals("The API token does not exists.", GET(URI, ApiTokenHeader("FAKE_KEY")).error(HttpStatus.UNAUTHORIZED).getMessage());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class ApiTokenAuthenticationTest method testAllowedMethodRule.
@Test
void testAllowedMethodRule() {
final TokenAndKey tokenAndKey = createNewToken();
final String key = tokenAndKey.key;
final ApiToken apiToken = tokenAndKey.apiToken;
apiToken.addMethodToAllowedList("POST");
apiTokenService.update(apiToken);
assertEquals("Failed to authenticate API token, request http method is not allowed.", GET(URI, ApiTokenHeader(key)).error(HttpStatus.UNAUTHORIZED).getMessage());
apiToken.addMethodToAllowedList("GET");
apiTokenService.update(apiToken);
JsonUser user = GET(URI, ApiTokenHeader(key)).content().as(JsonUser.class);
assertEquals(adminUser.getUid(), user.getId());
}
Aggregations