Search in sources :

Example 11 with ContainerInfo

use of org.keycloak.testsuite.arquillian.ContainerInfo in project keycloak by keycloak.

the class ComponentInvalidationClusterTest method testComponentUpdating.

@Test
public void testComponentUpdating() {
    ComponentRepresentation testEntity = createTestEntityRepresentation();
    // CREATE
    log.info("(1) createEntityOnCurrentFailNode");
    ComponentRepresentation comp = createEntityOnCurrentFailNode(testEntity);
    for (ContainerInfo ci : suiteContext.getAuthServerBackendsInfo()) {
        assertComponentHasCorrectConfig(comp, ci);
    }
    iterateCurrentFailNode();
    // config - add new
    comp.getConfig().putSingle("val3", "val3 value");
    comp = updateEntityOnCurrentFailNode(comp, "config - adding");
    for (ContainerInfo ci : suiteContext.getAuthServerBackendsInfo()) {
        assertComponentHasCorrectConfig(comp, ci);
    }
    iterateCurrentFailNode();
    // config - remove
    comp.getConfig().remove("val3");
    comp = updateEntityOnCurrentFailNode(comp, "config - removing");
    for (ContainerInfo ci : suiteContext.getAuthServerBackendsInfo()) {
        assertComponentHasCorrectConfig(comp, ci);
    }
    iterateCurrentFailNode();
    // config - update 1
    comp.getConfig().get("val1").set(0, comp.getConfig().get("val1").get(0) + " - updated");
    comp = updateEntityOnCurrentFailNode(comp, "config");
    for (ContainerInfo ci : suiteContext.getAuthServerBackendsInfo()) {
        assertComponentHasCorrectConfig(comp, ci);
    }
}
Also used : ComponentRepresentation(org.keycloak.representations.idm.ComponentRepresentation) ContainerInfo(org.keycloak.testsuite.arquillian.ContainerInfo) Test(org.junit.Test)

Example 12 with ContainerInfo

use of org.keycloak.testsuite.arquillian.ContainerInfo in project keycloak by keycloak.

the class RoleInvalidationClusterTest method assertEntityOnSurvivorNodesEqualsTo.

@Override
protected void assertEntityOnSurvivorNodesEqualsTo(RoleRepresentation testEntityOnFailNode) {
    super.assertEntityOnSurvivorNodesEqualsTo(testEntityOnFailNode);
    // composites
    boolean entityDiffers = false;
    for (ContainerInfo survivorNode : getCurrentSurvivorNodes()) {
        log.debug(String.format("Attempt to verify %s on survivor %s (%s)", getEntityType(testEntityOnFailNode), survivorNode, survivorNode.getContextRoot()));
        RoleRepresentation testEntityOnSurvivorNode = readEntity(testEntityOnFailNode, survivorNode);
        if (EqualsBuilder.reflectionEquals(sortFieldsComposites(testEntityOnSurvivorNode.getComposites()), sortFieldsComposites(testEntityOnFailNode.getComposites()))) {
            log.info(String.format("Verification of %s on survivor %s PASSED", getEntityType(testEntityOnFailNode), survivorNode));
        } else {
            entityDiffers = true;
            log.error(String.format("Verification of %s on survivor %s FAILED", getEntityType(testEntityOnFailNode), survivorNode));
            String tf = ReflectionToStringBuilder.reflectionToString(testEntityOnFailNode.getComposites(), ToStringStyle.SHORT_PREFIX_STYLE);
            String ts = ReflectionToStringBuilder.reflectionToString(testEntityOnSurvivorNode.getComposites(), ToStringStyle.SHORT_PREFIX_STYLE);
            log.error(String.format("\nEntity on fail node: \n%s\n" + "\nEntity on survivor node: \n%s\n" + "\nDifference: \n%s\n", tf, ts, StringUtils.difference(tf, ts)));
        }
    }
    assertFalse(entityDiffers);
}
Also used : RoleRepresentation(org.keycloak.representations.idm.RoleRepresentation) ContainerInfo(org.keycloak.testsuite.arquillian.ContainerInfo)

Example 13 with ContainerInfo

use of org.keycloak.testsuite.arquillian.ContainerInfo in project keycloak by keycloak.

the class URLProvider method doLookup.

@Override
public Object doLookup(ArquillianResource resource, Annotation... qualifiers) {
    URL url = (URL) super.doLookup(resource, qualifiers);
    if (url == null) {
        String appServerContextRoot = ServerURLs.getAppServerContextRoot();
        try {
            for (Annotation a : qualifiers) {
                if (OperateOnDeployment.class.isAssignableFrom(a.annotationType())) {
                    return new URL(appServerContextRoot + "/" + ((OperateOnDeployment) a).value() + "/");
                }
            }
        } catch (MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
    }
    // inject context roots if annotation present
    for (Annotation a : qualifiers) {
        if (AuthServerContext.class.isAssignableFrom(a.annotationType())) {
            return suiteContext.get().getAuthServerInfo().getContextRoot();
        }
        if (AppServerContext.class.isAssignableFrom(a.annotationType())) {
            // standalone
            ContainerInfo appServerInfo = testContext.get().getAppServerInfo();
            if (appServerInfo != null)
                return appServerInfo.getContextRoot();
            // cluster
            List<ContainerInfo> appServerBackendsInfo = testContext.get().getAppServerBackendsInfo();
            if (appServerBackendsInfo.isEmpty())
                throw new IllegalStateException("Both testContext's appServerInfo and appServerBackendsInfo not set.");
            return appServerBackendsInfo.get(0).getContextRoot();
        }
        if (AuthServerBrowserContext.class.isAssignableFrom(a.annotationType())) {
            return suiteContext.get().getAuthServerInfo().getBrowserContextRoot();
        }
        if (AppServerBrowserContext.class.isAssignableFrom(a.annotationType())) {
            // standalone
            ContainerInfo appServerInfo = testContext.get().getAppServerInfo();
            if (appServerInfo != null)
                return appServerInfo.getBrowserContextRoot();
            // cluster
            List<ContainerInfo> appServerBackendsInfo = testContext.get().getAppServerBackendsInfo();
            if (appServerBackendsInfo.isEmpty())
                throw new IllegalStateException("Both testContext's appServerInfo and appServerBackendsInfo not set.");
            return appServerBackendsInfo.get(0).getBrowserContextRoot();
        }
    }
    // fix injected URL
    if (url != null) {
        try {
            url = new URIBuilder(url.toURI()).setScheme(APP_SERVER_SCHEME).setHost(APP_SERVER_HOST).setPort(Integer.parseInt(APP_SERVER_PORT)).build().toURL();
        } catch (URISyntaxException | MalformedURLException ex) {
            throw new RuntimeException(ex);
        }
    }
    return url;
}
Also used : MalformedURLException(java.net.MalformedURLException) ContainerInfo(org.keycloak.testsuite.arquillian.ContainerInfo) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) Annotation(java.lang.annotation.Annotation) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 14 with ContainerInfo

use of org.keycloak.testsuite.arquillian.ContainerInfo in project keycloak by keycloak.

the class SpiProvidersSwitchingUtils method resetProvider.

public static void resetProvider(SuiteContext suiteContext, SetDefaultProvider annotation) {
    ContainerInfo authServerInfo = suiteContext.getAuthServerInfo();
    SpiSwitcher spiSwitcher = SpiSwitcher.getSpiSwitcherFor(authServerInfo);
    String spi = annotation.spi();
    Container container = authServerInfo.getArquillianContainer();
    if (annotation.onlyUpdateDefault()) {
        String originalValue = originalSettingsBackup.get(spi);
        log.infof("Resetting default provider for %s to %s", spi, originalValue == null ? "<null>" : originalValue);
        if (originalValue != null) {
            spiSwitcher.updateDefaultProvider(container, spi, originalValue);
        } else {
            spiSwitcher.unsetDefaultProvider(container, spi);
        }
    } else {
        log.infof("Removing default provider for %s to %s", spi);
        spiSwitcher.removeProviderConfig(container, spi);
    }
}
Also used : KeycloakQuarkusServerDeployableContainer(org.keycloak.testsuite.arquillian.containers.KeycloakQuarkusServerDeployableContainer) Container(org.jboss.arquillian.container.spi.Container) ContainerInfo(org.keycloak.testsuite.arquillian.ContainerInfo)

Aggregations

ContainerInfo (org.keycloak.testsuite.arquillian.ContainerInfo)14 Container (org.jboss.arquillian.container.spi.Container)3 KeycloakQuarkusServerDeployableContainer (org.keycloak.testsuite.arquillian.containers.KeycloakQuarkusServerDeployableContainer)3 Before (org.junit.Before)2 Annotation (java.lang.annotation.Annotation)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 URIBuilder (org.apache.http.client.utils.URIBuilder)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Test (org.junit.Test)1 ComponentRepresentation (org.keycloak.representations.idm.ComponentRepresentation)1 RealmRepresentation (org.keycloak.representations.idm.RealmRepresentation)1 RoleRepresentation (org.keycloak.representations.idm.RoleRepresentation)1 SamlClient (org.keycloak.testsuite.util.SamlClient)1 SamlClientBuilder (org.keycloak.testsuite.util.SamlClientBuilder)1