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());
}
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());
}
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");
}
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());
}
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());
}
Aggregations