Search in sources :

Example 1 with EndpointInfo

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EndpointInfo(com.hw.helper.EndpointInfo) HttpEntity(org.springframework.http.HttpEntity)

Example 2 with EndpointInfo

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EndpointInfo(com.hw.helper.EndpointInfo) HttpEntity(org.springframework.http.HttpEntity)

Example 3 with EndpointInfo

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EndpointInfo(com.hw.helper.EndpointInfo) HttpEntity(org.springframework.http.HttpEntity)

Example 4 with EndpointInfo

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());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EndpointInfo(com.hw.helper.EndpointInfo) HttpEntity(org.springframework.http.HttpEntity) SumTotal(com.hw.helper.SumTotal) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with EndpointInfo

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<>() {
    });
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) EndpointInfo(com.hw.helper.EndpointInfo) HttpEntity(org.springframework.http.HttpEntity)

Aggregations

EndpointInfo (com.hw.helper.EndpointInfo)7 HttpEntity (org.springframework.http.HttpEntity)5 HttpHeaders (org.springframework.http.HttpHeaders)5 Test (org.junit.Test)3 Ignore (org.junit.Ignore)2 SumTotal (com.hw.helper.SumTotal)1