Search in sources :

Example 6 with VirtualHostResolver

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

the class VirtualHostResolverImplTest method testMatches_wrongSource.

@Test
public void testMatches_wrongSource() {
    this.virtualHostMapping = new VirtualHostMapping("mymapping", "foo.no", "/b", "/a", VirtualHostIdProvidersMapping.create().build(), 0);
    when(virtualHostService.getVirtualHosts()).thenReturn(List.of(this.virtualHostMapping));
    VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("foo.no");
    when(req.getRequestURI()).thenReturn("/a");
    assertNull(virtualHostResolver.resolveVirtualHost(req));
}
Also used : VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping) Test(org.junit.jupiter.api.Test)

Example 7 with VirtualHostResolver

use of com.enonic.xp.web.vhost.VirtualHostResolver 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 8 with VirtualHostResolver

use of com.enonic.xp.web.vhost.VirtualHostResolver 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 9 with VirtualHostResolver

use of com.enonic.xp.web.vhost.VirtualHostResolver 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 10 with VirtualHostResolver

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

the class VirtualHostResolverImplTest method testMatches_host.

@Test
public void testMatches_host() {
    this.virtualHostMapping = new VirtualHostMapping("mymapping", "foo.no", "/", "/a", VirtualHostIdProvidersMapping.create().build(), 0);
    when(virtualHostService.getVirtualHosts()).thenReturn(List.of(this.virtualHostMapping));
    VirtualHostResolver virtualHostResolver = new VirtualHostResolverImpl(virtualHostService);
    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getServerName()).thenReturn("foo.no");
    when(req.getRequestURI()).thenReturn("/a/b");
    assertNotNull(virtualHostResolver.resolveVirtualHost(req));
}
Also used : VirtualHostResolver(com.enonic.xp.web.vhost.VirtualHostResolver) HttpServletRequest(javax.servlet.http.HttpServletRequest) VirtualHostMapping(com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping) Test(org.junit.jupiter.api.Test)

Aggregations

VirtualHostResolver (com.enonic.xp.web.vhost.VirtualHostResolver)11 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Test (org.junit.jupiter.api.Test)11 VirtualHost (com.enonic.xp.web.vhost.VirtualHost)8 ArrayList (java.util.ArrayList)8 VirtualHostMapping (com.enonic.xp.web.vhost.impl.mapping.VirtualHostMapping)3