Search in sources :

Example 1 with MockRequest

use of oap.http.testng.MockRequest in project oap by oaplatform.

the class SecurityInterceptor2Test method testShouldVerifyUserIfPresentInSession.

@Test
public void testShouldVerifyUserIfPresentInSession() {
    val methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithAnnotation")).get();
    val userId = "testUser";
    final Session session = new Session();
    session.set(USER_ID, userId);
    when(mockAclService.checkOne("obj", userId, "parent.read")).thenReturn(true);
    final MockRequest request = new MockRequest();
    request.headers.put("authorization", "token1");
    val httpResponse = securityInterceptor.intercept(request, session, methodWithAnnotation, p -> "obj");
    assertThat(httpResponse).isEmpty();
}
Also used : lombok.val(lombok.val) DateTimeUtils(org.joda.time.DateTimeUtils) Reflection(oap.reflect.Reflection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) Reflect(oap.reflect.Reflect) InetAddress(java.net.InetAddress) Arrays.asList(java.util.Arrays.asList) USER_ID(oap.ws.Interceptor.USER_ID) Session(oap.http.Session) MockRequest(oap.http.testng.MockRequest) AclService(oap.security.acl.AclService) Id(oap.util.Id) Context(oap.http.Context) WsParam(oap.ws.WsParam) lombok.val(lombok.val) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) Request(oap.http.Request) List(java.util.List) HttpGet(org.apache.http.client.methods.HttpGet) Optional(java.util.Optional) Protocol(oap.http.Protocol) Mockito.mock(org.mockito.Mockito.mock) MockRequest(oap.http.testng.MockRequest) Session(oap.http.Session) Test(org.testng.annotations.Test)

Example 2 with MockRequest

use of oap.http.testng.MockRequest in project oap by oaplatform.

the class SecurityInterceptor2Test method testAccessDenied.

@Test
public void testAccessDenied() {
    val methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithAnnotation")).get();
    val userId = "testUser";
    final Session session = new Session();
    session.set(USER_ID, userId);
    when(mockAclService.checkOne("obj", userId, "parent.read")).thenReturn(false);
    val httpResponse = securityInterceptor.intercept(new MockRequest(), session, methodWithAnnotation, p -> "obj");
    assertThat(httpResponse).isPresent();
}
Also used : lombok.val(lombok.val) DateTimeUtils(org.joda.time.DateTimeUtils) Reflection(oap.reflect.Reflection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) Reflect(oap.reflect.Reflect) InetAddress(java.net.InetAddress) Arrays.asList(java.util.Arrays.asList) USER_ID(oap.ws.Interceptor.USER_ID) Session(oap.http.Session) MockRequest(oap.http.testng.MockRequest) AclService(oap.security.acl.AclService) Id(oap.util.Id) Context(oap.http.Context) WsParam(oap.ws.WsParam) lombok.val(lombok.val) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) Request(oap.http.Request) List(java.util.List) HttpGet(org.apache.http.client.methods.HttpGet) Optional(java.util.Optional) Protocol(oap.http.Protocol) Mockito.mock(org.mockito.Mockito.mock) MockRequest(oap.http.testng.MockRequest) Session(oap.http.Session) Test(org.testng.annotations.Test)

Example 3 with MockRequest

use of oap.http.testng.MockRequest in project oap by oaplatform.

the class SecurityInterceptor2Test method testShouldNotCheckMethodWithoutAnnotation.

@Test
public void testShouldNotCheckMethodWithoutAnnotation() {
    val methodWithAnnotation = REFLECTION.method(method -> method.name().equals("methodWithoutAnnotation")).get();
    val httpResponse = securityInterceptor.intercept(new MockRequest(), new Session(), methodWithAnnotation, p -> null);
    assertThat(httpResponse).isEmpty();
}
Also used : lombok.val(lombok.val) DateTimeUtils(org.joda.time.DateTimeUtils) Reflection(oap.reflect.Reflection) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Collections.singletonList(java.util.Collections.singletonList) Reflect(oap.reflect.Reflect) InetAddress(java.net.InetAddress) Arrays.asList(java.util.Arrays.asList) USER_ID(oap.ws.Interceptor.USER_ID) Session(oap.http.Session) MockRequest(oap.http.testng.MockRequest) AclService(oap.security.acl.AclService) Id(oap.util.Id) Context(oap.http.Context) WsParam(oap.ws.WsParam) lombok.val(lombok.val) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) UnknownHostException(java.net.UnknownHostException) Request(oap.http.Request) List(java.util.List) HttpGet(org.apache.http.client.methods.HttpGet) Optional(java.util.Optional) Protocol(oap.http.Protocol) Mockito.mock(org.mockito.Mockito.mock) MockRequest(oap.http.testng.MockRequest) Session(oap.http.Session) Test(org.testng.annotations.Test)

Aggregations

InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 Arrays.asList (java.util.Arrays.asList)3 Collections.singletonList (java.util.Collections.singletonList)3 List (java.util.List)3 Optional (java.util.Optional)3 UUID (java.util.UUID)3 lombok.val (lombok.val)3 Context (oap.http.Context)3 Protocol (oap.http.Protocol)3 Request (oap.http.Request)3 Session (oap.http.Session)3 MockRequest (oap.http.testng.MockRequest)3 Reflect (oap.reflect.Reflect)3 Reflection (oap.reflect.Reflection)3 AclService (oap.security.acl.AclService)3 Id (oap.util.Id)3 USER_ID (oap.ws.Interceptor.USER_ID)3 WsParam (oap.ws.WsParam)3 HttpGet (org.apache.http.client.methods.HttpGet)3