use of com.hw.helper.EndpointInfo in project mt-auth by publicdevop2019.
the class EndpointTest method updateProfile.
private ResponseEntity<String> updateProfile(EndpointInfo endpointInfo, String id) {
String url = UrlUtility.getAccessUrl(ENDPOINTS + "/" + id);
HttpHeaders headers1 = new HttpHeaders();
headers1.setBearerAuth(UserUtility.getJwtAdmin());
HttpEntity<EndpointInfo> hashMapHttpEntity1 = new HttpEntity<>(endpointInfo, headers1);
return TestContext.getRestTemplate().exchange(url, HttpMethod.PUT, hashMapHttpEntity1, String.class);
}
use of com.hw.helper.EndpointInfo in project mt-auth by publicdevop2019.
the class EndpointTest method createProfile.
public static ResponseEntity<String> createProfile(EndpointInfo endpointInfo) {
String url = UrlUtility.getAccessUrl(ENDPOINTS);
HttpHeaders headers1 = new HttpHeaders();
headers1.setBearerAuth(UserUtility.getJwtAdmin());
HttpEntity<EndpointInfo> hashMapHttpEntity1 = new HttpEntity<>(endpointInfo, headers1);
return TestContext.getRestTemplate().exchange(url, HttpMethod.POST, hashMapHttpEntity1, String.class);
}
use of com.hw.helper.EndpointInfo in project mt-auth by publicdevop2019.
the class EndpointTest method readProfile.
public static ResponseEntity<EndpointInfo> readProfile(String id) {
String url = UrlUtility.getAccessUrl(ENDPOINTS + "/" + id);
HttpHeaders headers1 = new HttpHeaders();
headers1.setBearerAuth(UserUtility.getJwtAdmin());
HttpEntity<EndpointInfo> hashMapHttpEntity1 = new HttpEntity<>(headers1);
return TestContext.getRestTemplate().exchange(url, HttpMethod.GET, hashMapHttpEntity1, EndpointInfo.class);
}
use of com.hw.helper.EndpointInfo in project mt-auth by publicdevop2019.
the class EndpointTest method modify_existing_profile_to_prevent_access.
@Test
@Ignore
public void modify_existing_profile_to_prevent_access() {
String url2 = UrlUtility.getAccessUrl("/users/admin");
// before modify, admin is able to access resourceOwner apis
HttpHeaders headers1 = new HttpHeaders();
headers1.setBearerAuth(UserUtility.getJwtAdmin());
HttpEntity<Object> hashMapHttpEntity1 = new HttpEntity<>(headers1);
ResponseEntity<String> exchange1 = TestContext.getRestTemplate().exchange(url2, HttpMethod.GET, hashMapHttpEntity1, String.class);
Assert.assertEquals(HttpStatus.OK, exchange1.getStatusCode());
// modify profile to prevent admin access
ResponseEntity<SumTotal<EndpointInfo>> listResponseEntity = readEndpoints();
EndpointInfo endpointInfo = listResponseEntity.getBody().getData().get(6);
endpointInfo.getUserRoles().remove("ROLE_ADMIN");
endpointInfo.getUserRoles().add("ROLE_ROOT");
ResponseEntity<String> stringResponseEntity = updateProfile(endpointInfo, endpointInfo.getId());
Assert.assertEquals(HttpStatus.OK, stringResponseEntity.getStatusCode());
// after modify, admin is not able to access resourceOwner apis
try {
// wait for cache update
Thread.sleep(15 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ResponseEntity<String> exchange = TestContext.getRestTemplate().exchange(url2, HttpMethod.GET, hashMapHttpEntity1, String.class);
Assert.assertEquals(HttpStatus.FORBIDDEN, exchange.getStatusCode());
// modify profile to allow access
endpointInfo.getUserRoles().remove("ROLE_ROOT");
endpointInfo.getUserRoles().add("ROLE_ADMIN");
endpointInfo.setVersion(endpointInfo.getVersion() + 1);
ResponseEntity<String> stringResponseEntity1 = updateProfile(endpointInfo, endpointInfo.getId());
Assert.assertEquals(HttpStatus.OK, stringResponseEntity1.getStatusCode());
try {
// wait for cache update
Thread.sleep(15 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ResponseEntity<String> exchange2 = TestContext.getRestTemplate().exchange(url2, HttpMethod.GET, hashMapHttpEntity1, String.class);
Assert.assertEquals(HttpStatus.OK, exchange2.getStatusCode());
}
use of com.hw.helper.EndpointInfo in project mt-auth by publicdevop2019.
the class EndpointTest method readEndpoints.
private static ResponseEntity<SumTotal<EndpointInfo>> readEndpoints() {
String url = UrlUtility.getAccessUrl(ENDPOINTS);
HttpHeaders headers1 = new HttpHeaders();
headers1.setBearerAuth(UserUtility.getJwtAdmin());
HttpEntity<EndpointInfo> hashMapHttpEntity1 = new HttpEntity<>(headers1);
return TestContext.getRestTemplate().exchange(url, HttpMethod.GET, hashMapHttpEntity1, new ParameterizedTypeReference<>() {
});
}
Aggregations