Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public void setup(KeycloakQuarkusConfiguration configuration) {
@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
try {
log.infof("Deploying archive %s to quarkus container", archive.getName());
deployArchiveToServer(archive);
restartServer();
log.infof("Deployed archive %s and restarted quarkus container", archive.getName());
} catch (Exception e) {
throw new DeploymentException(e.getMessage(), e);
}
Expand All @@ -96,6 +98,7 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {

@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
log.infof("Undeploying archive %s from quarkus container", archive.getName());
File wrkDir = configuration.getProvidersPath().resolve("providers").toFile();
try {
if (isWindows()) {
Expand All @@ -104,6 +107,7 @@ public void undeploy(Archive<?> archive) throws DeploymentException {
}
Files.deleteIfExists(wrkDir.toPath().resolve(archive.getName()));
restartServer();
log.infof("Undeployed archive %s and restarted quarkus container", archive.getName());
} catch (Exception e) {
throw new DeploymentException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jboss.arquillian.container.spi.client.container.LifecycleException;
import org.jboss.logging.Logger;
import org.keycloak.testsuite.model.StoreProvider;
import org.keycloak.testsuite.util.WaitUtils;

/**
* @author mhajas
Expand Down Expand Up @@ -194,6 +195,11 @@ private void destroyDescendantsOnWindows(Process parent, boolean force) {
return;
}

// Wait some time before killing the windows processes. Otherwise there is a risk that some already commited H2 transactions
// won't be written to disk in time and hence those transactions may be lost, which could result in test failures in the next step after server restart.
// See http://repository.transtep.com/repository/thirdparty/H2/1.0.63/docs/html/advanced.html#durability_problems for the details
WaitUtils.pause(2000);

CompletableFuture allProcesses = CompletableFuture.completedFuture(null);

for (ProcessHandle process : parent.descendants().collect(Collectors.toList())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@

import jakarta.ws.rs.core.Response;

import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.keycloak.common.Profile;
import org.keycloak.dom.saml.v2.assertion.AssertionType;
import org.keycloak.dom.saml.v2.assertion.AttributeType;
import org.keycloak.protocol.saml.SamlProtocol;
Expand All @@ -29,8 +25,8 @@
import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.saml.common.constants.JBossSAMLURIConstants;
import org.keycloak.saml.processing.core.saml.v2.common.SAMLDocumentHolder;
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.arquillian.annotation.EnableFeatures;
import org.keycloak.testsuite.saml.AbstractSamlTest;
import org.keycloak.testsuite.saml.RoleMapperTest;
import org.keycloak.testsuite.updaters.ClientAttributeUpdater;
Expand All @@ -53,14 +49,16 @@
/**
* @author <a href="mailto:[email protected]">Marek Posolda</a>
*/
@EnableFeature(value = SCRIPTS, skipRestart = true)
public class DeployedSAMLScriptMapperTest extends AbstractSamlTest {

private static final String SCRIPT_DEPLOYMENT_NAME = "scripts.jar";

private ClientAttributeUpdater cau;
private ProtocolMappersUpdater pmu;

@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
// Managed to make sure that archive is deployed once in @BeforeClass stage and undeployed once in @AfterClass stage
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = true, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
Expand All @@ -78,15 +76,6 @@ public static void verifyEnvironment() {
ContainerAssume.assumeNotAuthServerUndertow();
}

@ArquillianResource
private Deployer deployer;

@Before
public void deployScripts() throws Exception {
deployer.deploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

@Before
public void cleanMappersAndScopes() {
this.cau = ClientAttributeUpdater.forClient(adminClient, REALM_NAME, SAML_CLIENT_ID_EMPLOYEE_2)
Expand All @@ -101,13 +90,8 @@ public void cleanMappersAndScopes() {
.addCleanup(this.pmu);
}

@After
public void onAfter() throws Exception {
deployer.undeploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

@Test
@DisableFeature(value = SCRIPTS, executeAsLast = false, skipRestart = true)
public void testScriptMapperNotAvailableThroughAdminRest() {
assertFalse(adminClient.serverInfo().getInfo().getProtocolMapperTypes().get(SamlProtocol.LOGIN_PROTOCOL).stream()
.anyMatch(
Expand All @@ -127,7 +111,6 @@ public void testScriptMapperNotAvailableThroughAdminRest() {


@Test
@EnableFeature(value = SCRIPTS, skipRestart = true, executeAsLast = false)
public void testScriptMappingThroughServerDeploy() {
// ScriptBasedMapper still not available even if SCRIPTS feature is enabled
testScriptMapperNotAvailableThroughAdminRest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@

import jakarta.ws.rs.core.Response;

import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.graphene.page.Page;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Rule;
Expand Down Expand Up @@ -69,7 +66,8 @@ public class DeployedScriptAuthenticatorTest extends AbstractFlowTest {
public static final String EXECUTION_ID = "scriptAuth";
private static final String SCRIPT_DEPLOYMENT_NAME = "scripts.jar";

@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
// Managed to make sure that archive is deployed once in @BeforeClass stage and undeployed once in @AfterClass stage
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = true, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
Expand All @@ -93,9 +91,6 @@ public static void verifyEnvironment() {
@Page
protected LoginPage loginPage;

@ArquillianResource
private Deployer deployer;

private AuthenticationFlowRepresentation flow;

@Override
Expand All @@ -122,8 +117,6 @@ public void configureTestRealm(RealmRepresentation testRealm) {
}

public void configureFlows() throws Exception {
deployer.deploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
if (testContext.isInitialized()) {
return;
}
Expand Down Expand Up @@ -173,12 +166,6 @@ public void configureFlows() throws Exception {
testContext.setInitialized(true);
}

@After
public void onAfter() throws Exception {
deployer.undeploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

/**
* KEYCLOAK-3491
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@

import java.io.IOException;

import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.keycloak.admin.client.resource.ClientResource;
Expand All @@ -44,6 +40,7 @@
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.testsuite.AbstractTestRealmKeycloakTest;
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
import org.keycloak.testsuite.arquillian.annotation.EnableFeature;
import org.keycloak.testsuite.util.ContainerAssume;
import org.keycloak.testsuite.util.OAuthClient;
Expand All @@ -52,11 +49,13 @@
/**
* @author <a href="mailto:[email protected]">Pedro Igor</a>
*/
@EnableFeature(value = SCRIPTS, skipRestart = true)
public class DeployedScriptMapperTest extends AbstractTestRealmKeycloakTest {

private static final String SCRIPT_DEPLOYMENT_NAME = "scripts.jar";

@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
// Managed to make sure that archive is deployed once in @BeforeClass stage and undeployed once in @AfterClass stage
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = true, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
Expand All @@ -74,35 +73,20 @@ public static void verifyEnvironment() {
ContainerAssume.assumeNotAuthServerUndertow();
}

@ArquillianResource
private Deployer deployer;

@Before
public void configureFlows() throws Exception {
deployer.deploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

@After
public void onAfter() throws Exception {
deployer.undeploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

@Override
public void configureTestRealm(RealmRepresentation testRealm) {

}

@Test
@DisableFeature(value = SCRIPTS, executeAsLast = false, skipRestart = true)
public void testScriptMapperNotAvailable() {
assertFalse(adminClient.serverInfo().getInfo().getProtocolMapperTypes().get(OIDCLoginProtocol.LOGIN_PROTOCOL).stream()
.anyMatch(
mapper -> ScriptBasedOIDCProtocolMapper.PROVIDER_ID.equals(mapper.getId())));
}

@Test
@EnableFeature(value = SCRIPTS, skipRestart = true, executeAsLast = false)
public void testTokenScriptMapping() {
{
ClientResource app = findClientResourceByClientId(adminClient.realm("test"), "test-app");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@
import java.io.IOException;
import java.util.List;

import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.TargetsContainer;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -50,7 +47,6 @@
import org.keycloak.representations.idm.authorization.ResourcePermissionRepresentation;
import org.keycloak.representations.idm.authorization.ResourceRepresentation;
import org.keycloak.representations.provider.ScriptProviderDescriptor;
import org.keycloak.testsuite.arquillian.annotation.DisableFeature;
import org.keycloak.testsuite.arquillian.annotation.UncaughtServerErrorExpected;
import org.keycloak.testsuite.authz.AbstractAuthzTest;
import org.keycloak.testsuite.util.ClientBuilder;
Expand All @@ -68,7 +64,8 @@ public class DeployedScriptPolicyTest extends AbstractAuthzTest {

private static final String SCRIPT_DEPLOYMENT_NAME = "scripts.jar";

@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = false, testable = false)
// Managed to make sure that archive is deployed once in @BeforeClass stage and undeployed once in @AfterClass stage
@Deployment(name = SCRIPT_DEPLOYMENT_NAME, managed = true, testable = false)
@TargetsContainer(AUTH_SERVER_CURRENT)
public static JavaArchive deploy() throws IOException {
ScriptProviderDescriptor representation = new ScriptProviderDescriptor();
Expand All @@ -88,9 +85,6 @@ public static void verifyEnvironment() {
ContainerAssume.assumeNotAuthServerUndertow();
}

@ArquillianResource
private Deployer deployer;

@Override
public void addTestRealms(List<RealmRepresentation> testRealms) {
testRealms.add(RealmBuilder.create().name("authz-test")
Expand All @@ -108,18 +102,10 @@ public void addTestRealms(List<RealmRepresentation> testRealms) {

@Before
public void onBefore() throws Exception {
deployer.deploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
AuthorizationResource authorization = getAuthorizationResource();
authorization.resources().create(new ResourceRepresentation("Default Resource"));
}

@After
public void onAfter() throws Exception {
deployer.undeploy(SCRIPT_DEPLOYMENT_NAME);
reconnectAdminClient();
}

@Test
public void testJSPolicyProviderNotAvailable() {
assertFalse(getAuthorizationResource().policies().policyProviders().stream().anyMatch(rep -> "js".equals(rep.getType())));
Expand Down