Search in sources :

Example 6 with VirtualHost

use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.

the class VirtualHostConfigMapTest method testGetSource.

@Test
public void testGetSource() {
    map.put("mapping.myapp.source", "/");
    VirtualHostConfigMap virtualHostConfig = new VirtualHostConfigMap(map);
    VirtualHost virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("/", virtualHost.getSource());
    map.put("mapping.myapp.source", "a/b");
    virtualHostConfig = new VirtualHostConfigMap(map);
    virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("/a/b", virtualHost.getSource());
    map.put("mapping.myapp.source", "a/b/");
    virtualHostConfig = new VirtualHostConfigMap(map);
    virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("/a/b", virtualHost.getSource());
    map.put("mapping.myapp.source", "/a/b/");
    virtualHostConfig = new VirtualHostConfigMap(map);
    virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("/a/b", virtualHost.getSource());
    map.put("mapping.myapp.source", "/a/b//");
    virtualHostConfig = new VirtualHostConfigMap(map);
    virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("/a/b/", virtualHost.getSource());
    map.put("mapping.myapp.source", "//a/b/");
    virtualHostConfig = new VirtualHostConfigMap(map);
    virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("//a/b", virtualHost.getSource());
}
Also used : VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Example 7 with VirtualHost

use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.

the class VirtualHostConfigMapTest method testDefaultVirtualHostConfig.

@Test
public void testDefaultVirtualHostConfig() {
    map.put("mapping.myapp.host", "");
    final VirtualHostConfigMap virtualHostConfig = new VirtualHostConfigMap(map);
    final VirtualHost virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("myapp", virtualHost.getName());
    assertEquals("localhost", virtualHost.getHost());
    assertEquals("/", virtualHost.getSource());
    assertEquals("/", virtualHost.getTarget());
    assertNull(virtualHost.getDefaultIdProviderKey());
    assertEquals(0, virtualHost.getIdProviderKeys().getSize());
}
Also used : VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Example 8 with VirtualHost

use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.

the class VirtualHostServiceImplTest method testOrder.

@Test
public void testOrder() {
    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");
    configurationMap.put("mapping.b.host", "localhost");
    configurationMap.put("mapping.b.source", "/b");
    configurationMap.put("mapping.b.target", "/other/b");
    configurationMap.put("mapping.c.host", "~localhost");
    configurationMap.put("mapping.c.source", "/a/c");
    configurationMap.put("mapping.c.target", "/other/a/c");
    configurationMap.put("mapping.d.host", "enonic.com");
    configurationMap.put("mapping.d.source", "/d");
    configurationMap.put("mapping.d.target", "/other/d");
    configurationMap.put("mapping.d.order", "1");
    final VirtualHostServiceImpl virtualHostService = new VirtualHostServiceImpl(configurationMap);
    final List<VirtualHost> virtualHosts = virtualHostService.getVirtualHosts();
    assertThat(virtualHosts.stream().map(VirtualHost::getName)).containsExactly("d", "c", "a", "b");
}
Also used : VirtualHostServiceImpl(com.enonic.xp.web.vhost.impl.config.VirtualHostServiceImpl) HashMap(java.util.HashMap) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Example 9 with VirtualHost

use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.

the class VirtualHostResolverImplTest method testMatchesHostInLowerCase.

@Test
public void testMatchesHostInLowerCase() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "doMain.com", "/source", "/other/a", 1));
    virtualHosts.add(createVirtualHostMapping("b", "no.domain.com", "/", "/other/b", 1));
    when(virtualHostService.getVirtualHosts()).thenReturn(virtualHosts);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getRequestURI()).thenReturn(URI.create("https://domain.com/source").getPath());
    when(req.getServerName()).thenReturn("DoMaIn.com");
    final VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    VirtualHost mapping = virtualHostResolver.resolveVirtualHost(req);
    assertNotNull(mapping);
    assertEquals("a", mapping.getName());
    assertEquals("/other/a", mapping.getTarget());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) ArrayList(java.util.ArrayList) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Example 10 with VirtualHost

use of com.enonic.xp.web.vhost.VirtualHost in project xp by enonic.

the class VirtualHostResolverImplTest method testResolve_multipleHosts_sortedBySource_reversed.

@Test
public void testResolve_multipleHosts_sortedBySource_reversed() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "no.domain.com", "/source", "/other/a", 1));
    virtualHosts.add(createVirtualHostMapping("b", "domain.com ~(?<sub>.+)\\.domain\\.com", "/", "/other/b/${sub}", 1));
    virtualHosts.add(createVirtualHostMapping("c", "domain.com", "/", "/other/c", 1));
    when(virtualHostService.getVirtualHosts()).thenReturn(virtualHosts);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("no.domain.com");
    when(req.getRequestURI()).thenReturn(URI.create("https://no.domain.com").getPath());
    final VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    VirtualHost mapping = virtualHostResolver.resolveVirtualHost(req);
    assertNotNull(mapping);
    assertEquals("b", mapping.getName());
    assertEquals("/other/b/no", mapping.getTarget());
    assertEquals("/", mapping.getSource());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) ArrayList(java.util.ArrayList) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) Test(org.junit.jupiter.api.Test)

Aggregations

VirtualHost (com.enonic.xp.web.vhost.VirtualHost)32 Test (org.junit.jupiter.api.Test)27 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 VirtualHostResolver (com.enonic.xp.web.vhost.VirtualHostResolver)8 ArrayList (java.util.ArrayList)8 VirtualHostServiceImpl (com.enonic.xp.web.vhost.impl.config.VirtualHostServiceImpl)6 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)2 IdProviderKey (com.enonic.xp.security.IdProviderKey)2 WebResponse (com.enonic.xp.web.WebResponse)2 HashMap (java.util.HashMap)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 PortalRequest (com.enonic.xp.portal.PortalRequest)1 IdProviderControllerExecutionParams (com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)1 ContentResolver (com.enonic.xp.portal.impl.ContentResolver)1 AbstractControllerTest (com.enonic.xp.portal.impl.controller.AbstractControllerTest)1 AssetUrlParams (com.enonic.xp.portal.url.AssetUrlParams)1 GenerateUrlParams (com.enonic.xp.portal.url.GenerateUrlParams)1 IdentityUrlParams (com.enonic.xp.portal.url.IdentityUrlParams)1 ResourceKey (com.enonic.xp.resource.ResourceKey)1