Search in sources :

Example 11 with VirtualHost

use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.

the class VirtualHostServiceTest method shouldFail_create_existingPath_trailingSlash.

@Test(expected = ApiContextPathAlreadyExistsException.class)
public void shouldFail_create_existingPath_trailingSlash() {
    Api api1 = createMock("mock1", "/context");
    when(apiRepository.search(null)).thenReturn(Collections.singletonList(api1));
    virtualHostService.sanitizeAndValidate(Collections.singletonList(new VirtualHost("/context/")));
}
Also used : Api(io.gravitee.repository.management.model.Api) VirtualHost(io.gravitee.definition.model.VirtualHost) Test(org.junit.Test)

Example 12 with VirtualHost

use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.

the class VirtualHostServiceImpl method validateDomainRestrictions.

private void validateDomainRestrictions(Collection<VirtualHost> virtualHosts) {
    final EnvironmentEntity currentEnv = environmentService.findById(GraviteeContext.getCurrentEnvironment());
    final List<String> domainRestrictions = currentEnv.getDomainRestrictions();
    if (domainRestrictions != null && !domainRestrictions.isEmpty()) {
        for (VirtualHost vHost : virtualHosts) {
            String host = vHost.getHost();
            if (!StringUtils.isEmpty(host)) {
                String hostWithoutPort = host.split(":")[0];
                if (!isValidDomainOrSubDomain(hostWithoutPort, domainRestrictions)) {
                    throw new InvalidVirtualHostException(hostWithoutPort, domainRestrictions);
                }
            } else {
                vHost.setHost(domainRestrictions.get(0));
            }
        }
    }
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) InvalidVirtualHostException(io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException) VirtualHost(io.gravitee.definition.model.VirtualHost)

Example 13 with VirtualHost

use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.

the class ApiResource method filterSensitiveData.

private void filterSensitiveData(ApiEntity entity) {
    final Proxy filteredProxy = new Proxy();
    final VirtualHost virtualHost = entity.getProxy().getVirtualHosts().get(0);
    virtualHost.setHost(null);
    filteredProxy.setVirtualHosts(singletonList(virtualHost));
    entity.setProxy(filteredProxy);
    entity.setPaths(null);
    entity.setProperties(null);
    entity.setServices(null);
    entity.setResources(null);
    entity.setPathMappings(null);
    entity.setResponseTemplates(null);
}
Also used : Proxy(io.gravitee.definition.model.Proxy) VirtualHost(io.gravitee.definition.model.VirtualHost)

Example 14 with VirtualHost

use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.

the class ApiResourceNotAdminTest method init.

@Before
public void init() {
    mockApi = new ApiEntity();
    mockApi.setId(API);
    mockApi.setName(API);
    Proxy proxy = new Proxy();
    proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/test")));
    mockApi.setProxy(proxy);
    mockApi.setUpdatedAt(new Date());
    doReturn(mockApi).when(apiService).findById(API);
}
Also used : Proxy(io.gravitee.definition.model.Proxy) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) Date(java.util.Date) Before(org.junit.Before)

Example 15 with VirtualHost

use of io.gravitee.definition.model.VirtualHost in project gravitee-management-rest-api by gravitee-io.

the class ApiResourceTest method init.

@Before
public void init() {
    reset(apiService);
    mockApi = new ApiEntity();
    mockApi.setId(API);
    mockApi.setName(API);
    Proxy proxy = new Proxy();
    proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/test")));
    mockApi.setProxy(proxy);
    mockApi.setUpdatedAt(new Date());
    doReturn(mockApi).when(apiService).findById(API);
    doThrow(ApiNotFoundException.class).when(apiService).findById(UNKNOWN_API);
    updateApiEntity = new UpdateApiEntity();
    updateApiEntity.setDescription("toto");
    updateApiEntity.setVisibility(Visibility.PUBLIC);
    updateApiEntity.setName(API);
    updateApiEntity.setVersion("v1");
    proxy = new Proxy();
    proxy.setVirtualHosts(Collections.singletonList(new VirtualHost("/test")));
    updateApiEntity.setProxy(proxy);
    updateApiEntity.setLifecycleState(ApiLifecycleState.CREATED);
    doReturn(mockApi).when(apiService).update(eq(API), any(), eq(true));
}
Also used : Proxy(io.gravitee.definition.model.Proxy) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) UpdateApiEntity(io.gravitee.rest.api.model.api.UpdateApiEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) VirtualHost(io.gravitee.definition.model.VirtualHost) Date(java.util.Date) Before(org.junit.Before)

Aggregations

VirtualHost (io.gravitee.definition.model.VirtualHost)25 Test (org.junit.Test)17 Api (io.gravitee.repository.management.model.Api)10 Proxy (io.gravitee.definition.model.Proxy)7 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)6 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)6 UpdateApiEntity (io.gravitee.rest.api.model.api.UpdateApiEntity)3 Date (java.util.Date)3 PrimaryOwnerEntity (io.gravitee.rest.api.model.PrimaryOwnerEntity)2 UserEntity (io.gravitee.rest.api.model.UserEntity)2 Api (io.gravitee.rest.api.portal.rest.model.Api)2 RatingSummary (io.gravitee.rest.api.portal.rest.model.RatingSummary)2 Before (org.junit.Before)2 RatingSummaryEntity (io.gravitee.rest.api.model.RatingSummaryEntity)1 ApiEntrypointEntity (io.gravitee.rest.api.model.api.ApiEntrypointEntity)1 DuplicateApiEntity (io.gravitee.rest.api.model.api.DuplicateApiEntity)1 PageQuery (io.gravitee.rest.api.model.documentation.PageQuery)1 User (io.gravitee.rest.api.portal.rest.model.User)1 UuidString (io.gravitee.rest.api.service.common.UuidString)1 InvalidVirtualHostException (io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException)1