use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.
the class VirtualHostServiceImplTest method testGetVirtualHosts.
@Test
public void testGetVirtualHosts() {
final Map<String, String> configurationMap = new HashMap<>();
configurationMap.put("enabled", "true");
configurationMap.put("mapping.a.host", "localhost");
configurationMap.put("mapping.a.source", "/a");
configurationMap.put("mapping.a.target", "/other/a");
final VirtualHostServiceImpl virtualHostService = new VirtualHostServiceImpl(configurationMap);
final List<VirtualHost> virtualHosts = virtualHostService.getVirtualHosts();
assertNotNull(virtualHosts);
assertFalse(virtualHosts.isEmpty());
assertEquals("a", virtualHosts.get(0).getName());
}
use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.
the class IdentityHandlerTest method testHandleWithVirtualHostEnabled.
@Test
public void testHandleWithVirtualHostEnabled() throws Exception {
final HttpServletRequest rawRequest = this.request.getRawRequest();
final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from("otherEnabledIdProvider", "myidprovider"));
VirtualHostHelper.setVirtualHost(rawRequest, initVirtualHost(rawRequest, virtualHost));
final WebResponse portalResponse = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertEquals(HttpStatus.OK, portalResponse.getStatus());
assertEquals(HttpStatus.OK, portalResponse.getStatus());
assertEquals("/site/draft/_/idprovider/myidprovider", this.request.getContextPath());
}
use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.
the class IdentityHandlerTest method testHandleWithVirtualHostNotEnabled.
@Test
public void testHandleWithVirtualHostNotEnabled() throws Exception {
final HttpServletRequest rawRequest = this.request.getRawRequest();
final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from("otherEnabledIdProvider"));
VirtualHostHelper.setVirtualHost(rawRequest, initVirtualHost(rawRequest, virtualHost));
try {
this.handler.handle(this.request, PortalResponse.create().build(), null);
} catch (final WebException e) {
assertEquals("'myidprovider' id provider is forbidden", e.getMessage());
}
}
use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.
the class IdentityHandlerTest method testHandleWithEmptyVirtualHostIdProviderConfig.
@Test
public void testHandleWithEmptyVirtualHostIdProviderConfig() throws Exception {
final HttpServletRequest rawRequest = this.request.getRawRequest();
final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.empty());
VirtualHostHelper.setVirtualHost(rawRequest, virtualHost);
final WebResponse portalResponse = this.handler.handle(this.request, PortalResponse.create().build(), null);
assertEquals(HttpStatus.OK, portalResponse.getStatus());
assertEquals(HttpStatus.OK, portalResponse.getStatus());
assertEquals("/site/draft/_/idprovider/myidprovider", this.request.getContextPath());
}
use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.
the class VirtualHostHandlerTest method setUp.
@BeforeEach
public void setUp() {
Mockito.when(virtualHostService.isEnabled()).thenReturn(true);
virtualHost = Mockito.mock(VirtualHost.class);
Mockito.when(virtualHost.getName()).thenReturn("a");
Mockito.when(virtualHost.getSource()).thenReturn("/a");
Mockito.when(virtualHost.getTarget()).thenReturn("/other/a");
Mockito.when(virtualHost.getHost()).thenReturn("localhost");
final IdProviderKey defaultIdProviderKey = IdProviderKey.from("default");
Mockito.when(virtualHost.getDefaultIdProviderKey()).thenReturn(defaultIdProviderKey);
Mockito.when(virtualHost.getIdProviderKeys()).thenReturn(IdProviderKeys.from(defaultIdProviderKey));
}
Aggregations