Clear import/export properties at the end of the test

This avoids the pollution of system properties that might lead to failures following tests.

Closes #11670
This commit is contained in:
Alexander Schwartz 2022-04-27 10:07:31 +02:00 committed by Hynek Mlnařík
parent 302e152f86
commit 29233f33c8
3 changed files with 37 additions and 29 deletions

View file

@ -46,59 +46,59 @@ public interface TestingExportImportResource {
@Path("/get-users-per-file")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Integer getUsersPerFile();
Integer getUsersPerFile();
@PUT
@Path("/set-users-per-file")
@Consumes(MediaType.APPLICATION_JSON)
public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile);
void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile);
@GET
@Path("/get-dir")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getDir();
String getDir();
@PUT
@Path("/set-dir")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String setDir(@QueryParam("dir") String dir);
String setDir(@QueryParam("dir") String dir);
@PUT
@Path("/set-import-strategy")
@Consumes(MediaType.APPLICATION_JSON)
public void setStrategy(@QueryParam("importStrategy") Strategy strategy);
void setStrategy(@QueryParam("importStrategy") Strategy strategy);
@PUT
@Path("/export-import-provider")
@Consumes(MediaType.APPLICATION_JSON)
public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider);
void setProvider(@QueryParam("exportImportProvider") String exportImportProvider);
@PUT
@Path("/export-import-file")
@Consumes(MediaType.APPLICATION_JSON)
public void setFile(@QueryParam("file") String file);
void setFile(@QueryParam("file") String file);
@PUT
@Path("/export-import-action")
@Consumes(MediaType.APPLICATION_JSON)
public void setAction(@QueryParam("exportImportAction") String exportImportAction);
void setAction(@QueryParam("exportImportAction") String exportImportAction);
@PUT
@Path("/set-realm-name")
@Consumes(MediaType.APPLICATION_JSON)
public void setRealmName(@QueryParam("realmName") String realmName);
void setRealmName(@QueryParam("realmName") String realmName);
@GET
@Path("/get-test-dir")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getExportImportTestDirectory();
String getExportImportTestDirectory();
@GET
@Path("/clear")
@Produces(MediaType.APPLICATION_JSON)
public Response clear();
void clear();
}

View file

@ -460,7 +460,7 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
@Test
@UncaughtServerErrorExpected
public void testAccountLinkNoTokenStore() throws Exception {
public void testAccountLinkNoTokenStore() {
testingClient.server().run(BrokerLinkAndTokenExchangeTest::turnOffTokenStore);
RealmResource realm = adminClient.realms().realm(CHILD_IDP);
@ -500,8 +500,6 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
/**
* KEYCLOAK-6026
*
* @throws Exception
*/
@Test
@UncaughtServerErrorExpected
@ -509,19 +507,22 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
ContainerAssume.assumeNotAuthServerRemote();
testExternalExchange();
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
testingClient.testing().exportImport().setFile(targetFilePath);
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
testingClient.testing().exportImport().setRealmName(CHILD_IDP);
testingClient.testing().exportImport().runExport();
adminClient.realms().realm(CHILD_IDP).remove();
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
try {
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
testingClient.testing().exportImport().setFile(targetFilePath);
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
testingClient.testing().exportImport().setRealmName(CHILD_IDP);
testingClient.testing().exportImport().runExport();
testingClient.testing().exportImport().runImport();
adminClient.realms().realm(CHILD_IDP).remove();
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
testingClient.testing().exportImport().clear();
testingClient.testing().exportImport().runImport();
} finally {
testingClient.testing().exportImport().clear();
}
testExternalExchange();
}
@ -552,8 +553,8 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
rep.getConfig().put("issuer", parentIssuer);
adminClient.realm(CHILD_IDP).identityProviders().get(PARENT_IDP).update(rep);
String exchangedUserId = null;
String exchangedUsername = null;
String exchangedUserId;
String exchangedUsername;
{
// test signature validation
@ -699,7 +700,7 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
{
// test unauthorized client gets 403
Response response = exchangeUrl.request()
try (Response response = exchangeUrl.request()
.header(HttpHeaders.AUTHORIZATION, BasicAuthHelper.createHeader(UNAUTHORIZED_CHILD_CLIENT, "password"))
.post(Entity.form(
new Form()
@ -708,8 +709,9 @@ public class BrokerLinkAndTokenExchangeTest extends AbstractServletsAdapterTest
.param(OAuth2Constants.SUBJECT_TOKEN_TYPE, OAuth2Constants.JWT_TOKEN_TYPE)
.param(OAuth2Constants.SUBJECT_ISSUER, PARENT_IDP)
));
Assert.assertEquals(403, response.getStatus());
))) {
Assert.assertEquals(403, response.getStatus());
}
}
} finally {
httpClient.close();

View file

@ -17,6 +17,7 @@
package org.keycloak.testsuite.client;
import org.junit.After;
import org.junit.Test;
import org.keycloak.exportimport.ExportImportConfig;
import org.keycloak.exportimport.singlefile.SingleFileExportProviderFactory;
@ -57,6 +58,11 @@ public class ClientPoliciesImportExportTest extends AbstractClientPoliciesTest {
removeAllRealmsDespiteMaster();
}
@After
public void afterImportExport() {
testingClient.testing().exportImport().clear();
}
@Test
public void testSingleFileRealmExportImport() throws Throwable {
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);