use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class ApiTokenAuthenticationTest method testAllowedReferrerRule.
@Test
void testAllowedReferrerRule() {
final TokenAndKey tokenAndKey = createNewToken();
final String key = tokenAndKey.key;
final ApiToken apiToken = tokenAndKey.apiToken;
apiToken.addReferrerToAllowedList("https://one.io");
apiTokenService.update(apiToken);
assertEquals("Failed to authenticate API token, request http referrer is missing or not allowed.", GET(URI, ApiTokenHeader(key)).error(HttpStatus.UNAUTHORIZED).getMessage());
apiToken.addReferrerToAllowedList("https://two.io");
apiTokenService.update(apiToken);
JsonUser user = GET(URI, ApiTokenHeader(key), Header("referer", "https://two.io")).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 testAllowedIpRule.
@Test
void testAllowedIpRule() {
final TokenAndKey tokenAndKey = createNewToken();
final String key = tokenAndKey.key;
final ApiToken apiToken = tokenAndKey.apiToken;
apiToken.addIpToAllowedList("192.168.2.1");
apiTokenService.update(apiToken);
assertEquals("Failed to authenticate API token, request ip address is not allowed.", GET(URI, ApiTokenHeader(key)).error(HttpStatus.UNAUTHORIZED).getMessage());
apiToken.addIpToAllowedList("127.0.0.1");
apiTokenService.update(apiToken);
JsonUser user = GET(URI, ApiTokenHeader(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 JwtBearerTokenTest method testSuccessfulRequest.
@Test
void testSuccessfulRequest() {
setupTestingProvider(CLIENT_ID_1, TEST_PROVIDER_ONE_NAME, TEST_PROVIDER_ONE_URI);
User openIDUser = createOpenIDUser("openiduser", "openiduser@oidc.org");
String tokenValue = createJwt(TEST_PROVIDER_ONE_URI, CLIENT_ID_1, "email", "openiduser@oidc.org").getTokenValue();
JsonUser user = GET("/me?fields=settings,id", JwtTokenHeader(tokenValue)).content().as(JsonUser.class);
assertEquals(openIDUser.getUid(), user.getId());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class UserLookupControllerTest method testLookUpUsers.
/**
* This test makes sure a user having the same role as users in the system
* can see those users.
*/
@Test
void testLookUpUsers() {
User tester = switchToNewUser("tester");
switchToSuperuser();
assertStatus(HttpStatus.NO_CONTENT, POST("/userRoles/" + roleId + "/users/" + tester.getUid()));
switchContextToUser(tester);
JsonArray matches = GET("/userLookup?query=John").content().getArray("users");
assertEquals(1, matches.size());
JsonUser user = matches.get(0, JsonUser.class);
assertEquals("John", user.getFirstName());
}
use of org.hisp.dhis.webapi.json.domain.JsonUser in project dhis2-core by dhis2.
the class AbstractCrudControllerTest method testUpdateObject.
@Test
void testUpdateObject() {
String peter = "{'name': 'Peter', 'firstName':'Peter', 'surname':'Pan', 'username':'peter47'}";
String peterUserId = assertStatus(HttpStatus.CREATED, POST("/users", peter));
JsonResponse roles = GET("/userRoles?fields=id").content();
String roleId = roles.getArray("userRoles").getObject(0).getString("id").string();
assertStatus(HttpStatus.NO_CONTENT, POST("/userRoles/" + roleId + "/users/" + peterUserId));
JsonUser oldPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
assertEquals("Peter", oldPeter.getFirstName());
assertEquals(1, oldPeter.getArray("userRoles").size());
assertStatus(HttpStatus.OK, PUT("/users/" + peterUserId, Body(oldPeter.getString("firstName").node().replaceWith("\"Fry\"").getDeclaration()), ContentType(MediaType.APPLICATION_JSON)));
JsonUser newPeter = GET("/users/{id}", peterUserId).content().as(JsonUser.class);
assertEquals("Fry", newPeter.getFirstName());
// are user roles still there?
assertEquals(1, newPeter.getArray("userRoles").size());
}
Aggregations