Search in sources :

Example 16 with VirtualHost

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

the class VirtualHostResolverImplTest method testResolve_NotMatched.

@Test
public void testResolve_NotMatched() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "domain.com", "/source", "/other/a", 1));
    virtualHosts.add(createVirtualHostMapping("b", "domain.com", "/", "/other/b", 1));
    when(virtualHostService.getVirtualHosts()).thenReturn(virtualHosts);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("foo.com");
    final VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    assertNull(virtualHostResolver.resolveVirtualHost(req));
}
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 17 with VirtualHost

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

the class VirtualHostResolverImplTest method testResolve_multipleHosts_sortedBySource_natural.

@Test
public void testResolve_multipleHosts_sortedBySource_natural() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "no.domain.com", "/", "/other/a", 1));
    virtualHosts.add(createVirtualHostMapping("b", "domain.com ~(?<sub>.+)\\.domain\\.com", "/source", "/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("a", mapping.getName());
    assertEquals("/other/a", 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)

Example 18 with VirtualHost

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

the class VirtualHostResolverImplTest method testResolve_multipleHosts.

@Test
public void testResolve_multipleHosts() {
    final List<VirtualHost> virtualHosts = new ArrayList<>();
    virtualHosts.add(createVirtualHostMapping("a", "subdomain.com", "/source", "/other/a", 1));
    virtualHosts.add(createVirtualHostMapping("c", "domain.com ~(?<sub>.+)\\.domain\\.com", "/", "/other/c/${sub}", 1));
    virtualHosts.add(createVirtualHostMapping("b", "domain.com", "/", "/other/b", 1));
    virtualHosts.add(createVirtualHostMapping("d", "no.domain.com", "/", "/other/d", 1));
    virtualHosts.add(createVirtualHostMapping("e", "~.+", "/", "/other/e", 2));
    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("c", mapping.getName());
    assertEquals("/other/c/no", mapping.getTarget());
    assertEquals("no.domain.com", mapping.getHost());
    when(req.getServerName()).thenReturn("foo.com");
    when(req.getRequestURI()).thenReturn(URI.create("https://foo.com").getPath());
    mapping = virtualHostResolver.resolveVirtualHost(req);
    assertNotNull(mapping);
    assertEquals("e", mapping.getName());
}
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 19 with VirtualHost

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

the class VirtualHostConfigMapTest method testGetTarget.

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

Example 20 with VirtualHost

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

the class VirtualHostConfigMapTest method testDefaultIdProvider.

@Test
public void testDefaultIdProvider() {
    map.put("mapping.myapp1.idProvider.system", "default");
    map.put("mapping.myapp1.idProvider.myProvider", "enabled");
    VirtualHostConfigMap virtualHostConfig = new VirtualHostConfigMap(map);
    VirtualHost virtualHost = virtualHostConfig.buildMappings().get(0);
    assertEquals("system", virtualHost.getDefaultIdProviderKey().toString());
    assertEquals(2, virtualHost.getIdProviderKeys().getSize());
    assertTrue(virtualHost.getIdProviderKeys().contains(IdProviderKey.from("myProvider")));
}
Also used : 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