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();
}
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();
}
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();
}
Aggregations