Search in sources :

Example 11 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 12 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) SomeUserId(org.hisp.dhis.webapi.snippets.SomeUserId) DhisControllerConvenienceTest(org.hisp.dhis.webapi.DhisControllerConvenienceTest) Test(org.junit.jupiter.api.Test)

Example 13 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerWithApiTokenAuthTest(org.hisp.dhis.webapi.DhisControllerWithApiTokenAuthTest) Test(org.junit.jupiter.api.Test)

Example 14 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) DhisControllerWithApiTokenAuthTest(org.hisp.dhis.webapi.DhisControllerWithApiTokenAuthTest) Test(org.junit.jupiter.api.Test)

Example 15 with JsonUser

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());
}
Also used : JsonUser(org.hisp.dhis.webapi.json.domain.JsonUser) ApiToken(org.hisp.dhis.security.apikey.ApiToken) DhisControllerWithApiTokenAuthTest(org.hisp.dhis.webapi.DhisControllerWithApiTokenAuthTest) Test(org.junit.jupiter.api.Test)

Aggregations

JsonUser (org.hisp.dhis.webapi.json.domain.JsonUser)15 Test (org.junit.jupiter.api.Test)15 DhisControllerConvenienceTest (org.hisp.dhis.webapi.DhisControllerConvenienceTest)9 DhisControllerWithApiTokenAuthTest (org.hisp.dhis.webapi.DhisControllerWithApiTokenAuthTest)5 ApiToken (org.hisp.dhis.security.apikey.ApiToken)3 User (org.hisp.dhis.user.User)3 JsonResponse (org.hisp.dhis.jsontree.JsonResponse)2 JsonArray (org.hisp.dhis.jsontree.JsonArray)1 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)1 DhisControllerWithJwtTokenAuthTest (org.hisp.dhis.webapi.DhisControllerWithJwtTokenAuthTest)1 SomeUserId (org.hisp.dhis.webapi.snippets.SomeUserId)1