use of dev.hilla.auth.CsrfChecker in project flow by vaadin.
the class EndpointControllerTest method createVaadinController.
private <T> EndpointController createVaadinController(T endpoint, ObjectMapper vaadinEndpointMapper, EndpointAccessChecker accessChecker, EndpointNameChecker endpointNameChecker, ExplicitNullableTypeChecker explicitNullableTypeChecker, CsrfChecker csrfChecker) {
ServletContext servletContext = Mockito.mock(ServletContext.class);
Lookup lookup = Mockito.mock(Lookup.class);
Mockito.when(servletContext.getAttribute(Lookup.class.getName())).thenReturn(lookup);
if (vaadinEndpointMapper == null) {
vaadinEndpointMapper = new ObjectMapper();
}
if (accessChecker == null) {
accessChecker = mock(EndpointAccessChecker.class);
when(accessChecker.check(TEST_METHOD, requestMock)).thenReturn(null);
}
if (csrfChecker == null) {
csrfChecker = new CsrfChecker(servletContext);
}
if (endpointNameChecker == null) {
endpointNameChecker = mock(EndpointNameChecker.class);
when(endpointNameChecker.check(TEST_ENDPOINT_NAME)).thenReturn(null);
}
if (explicitNullableTypeChecker == null) {
explicitNullableTypeChecker = mock(ExplicitNullableTypeChecker.class);
when(explicitNullableTypeChecker.checkValueForType(any(), any())).thenReturn(null);
}
ApplicationContext mockApplicationContext = mockApplicationContext(endpoint);
EndpointRegistry registry = new EndpointRegistry(endpointNameChecker);
EndpointInvoker invoker = Mockito.spy(new EndpointInvoker(mockApplicationContext, vaadinEndpointMapper, explicitNullableTypeChecker, registry));
Mockito.doReturn(accessChecker).when(invoker).getAccessChecker(any());
EndpointController connectController = Mockito.spy(new EndpointController(mockApplicationContext, registry, invoker, csrfChecker));
return connectController;
}
use of dev.hilla.auth.CsrfChecker in project flow by vaadin.
the class EndpointControllerMockBuilder method build.
public EndpointController build() {
EndpointRegistry registry = new EndpointRegistry(endpointNameChecker);
CsrfChecker csrfChecker = Mockito.mock(CsrfChecker.class);
Mockito.when(csrfChecker.validateCsrfTokenInRequest(Mockito.any())).thenReturn(true);
EndpointInvoker invoker = Mockito.spy(new EndpointInvoker(applicationContext, objectMapper, explicitNullableTypeChecker, registry));
EndpointController controller = Mockito.spy(new EndpointController(applicationContext, registry, invoker, csrfChecker));
Mockito.doReturn(mock(EndpointAccessChecker.class)).when(invoker).getAccessChecker(Mockito.any());
return controller;
}
Aggregations