Search in sources :

Example 21 with VirtualHost

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());
}
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 22 with VirtualHost

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.enonic.xp.web.WebResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 23 with VirtualHost

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());
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebException(com.enonic.xp.web.WebException) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 24 with VirtualHost

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());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WebResponse(com.enonic.xp.web.WebResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 25 with VirtualHost

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));
}
Also used : IdProviderKey(com.enonic.xp.security.IdProviderKey) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) BeforeEach(org.junit.jupiter.api.BeforeEach)

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