Skip to content

Commit 29233f3

Browse files
ahus1hmlnarik
authored andcommitted
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 keycloak#11670
1 parent 302e152 commit 29233f3

File tree

3 files changed

+37
-29
lines changed

3 files changed

+37
-29
lines changed

testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/client/resources/TestingExportImportResource.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,59 +46,59 @@ public interface TestingExportImportResource {
4646
@Path("/get-users-per-file")
4747
@Consumes(MediaType.APPLICATION_JSON)
4848
@Produces(MediaType.APPLICATION_JSON)
49-
public Integer getUsersPerFile();
49+
Integer getUsersPerFile();
5050

5151
@PUT
5252
@Path("/set-users-per-file")
5353
@Consumes(MediaType.APPLICATION_JSON)
54-
public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile);
54+
void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile);
5555

5656
@GET
5757
@Path("/get-dir")
5858
@Consumes(MediaType.APPLICATION_JSON)
5959
@Produces(MediaType.APPLICATION_JSON)
60-
public String getDir();
60+
String getDir();
6161

6262
@PUT
6363
@Path("/set-dir")
6464
@Consumes(MediaType.APPLICATION_JSON)
6565
@Produces(MediaType.APPLICATION_JSON)
66-
public String setDir(@QueryParam("dir") String dir);
66+
String setDir(@QueryParam("dir") String dir);
6767

6868
@PUT
6969
@Path("/set-import-strategy")
7070
@Consumes(MediaType.APPLICATION_JSON)
71-
public void setStrategy(@QueryParam("importStrategy") Strategy strategy);
71+
void setStrategy(@QueryParam("importStrategy") Strategy strategy);
7272

7373
@PUT
7474
@Path("/export-import-provider")
7575
@Consumes(MediaType.APPLICATION_JSON)
76-
public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider);
76+
void setProvider(@QueryParam("exportImportProvider") String exportImportProvider);
7777

7878
@PUT
7979
@Path("/export-import-file")
8080
@Consumes(MediaType.APPLICATION_JSON)
81-
public void setFile(@QueryParam("file") String file);
81+
void setFile(@QueryParam("file") String file);
8282

8383
@PUT
8484
@Path("/export-import-action")
8585
@Consumes(MediaType.APPLICATION_JSON)
86-
public void setAction(@QueryParam("exportImportAction") String exportImportAction);
86+
void setAction(@QueryParam("exportImportAction") String exportImportAction);
8787

8888
@PUT
8989
@Path("/set-realm-name")
9090
@Consumes(MediaType.APPLICATION_JSON)
91-
public void setRealmName(@QueryParam("realmName") String realmName);
91+
void setRealmName(@QueryParam("realmName") String realmName);
9292

9393
@GET
9494
@Path("/get-test-dir")
9595
@Consumes(MediaType.APPLICATION_JSON)
9696
@Produces(MediaType.APPLICATION_JSON)
97-
public String getExportImportTestDirectory();
97+
String getExportImportTestDirectory();
9898

9999
@GET
100100
@Path("/clear")
101101
@Produces(MediaType.APPLICATION_JSON)
102-
public Response clear();
102+
void clear();
103103

104104
}

testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/servlet/BrokerLinkAndTokenExchangeTest.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ protected String parentJwksUrl() {
460460

461461
@Test
462462
@UncaughtServerErrorExpected
463-
public void testAccountLinkNoTokenStore() throws Exception {
463+
public void testAccountLinkNoTokenStore() {
464464
testingClient.server().run(BrokerLinkAndTokenExchangeTest::turnOffTokenStore);
465465

466466
RealmResource realm = adminClient.realms().realm(CHILD_IDP);
@@ -500,28 +500,29 @@ public void testAccountLinkNoTokenStore() throws Exception {
500500

501501
/**
502502
* KEYCLOAK-6026
503-
*
504-
* @throws Exception
505503
*/
506504
@Test
507505
@UncaughtServerErrorExpected
508506
public void testExportImport() throws Exception {
509507
ContainerAssume.assumeNotAuthServerRemote();
510508

511509
testExternalExchange();
512-
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
513-
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
514-
testingClient.testing().exportImport().setFile(targetFilePath);
515-
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
516-
testingClient.testing().exportImport().setRealmName(CHILD_IDP);
517-
testingClient.testing().exportImport().runExport();
518510

519-
adminClient.realms().realm(CHILD_IDP).remove();
520-
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
511+
try {
512+
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
513+
String targetFilePath = testingClient.testing().exportImport().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
514+
testingClient.testing().exportImport().setFile(targetFilePath);
515+
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_EXPORT);
516+
testingClient.testing().exportImport().setRealmName(CHILD_IDP);
517+
testingClient.testing().exportImport().runExport();
521518

522-
testingClient.testing().exportImport().runImport();
519+
adminClient.realms().realm(CHILD_IDP).remove();
520+
testingClient.testing().exportImport().setAction(ExportImportConfig.ACTION_IMPORT);
523521

524-
testingClient.testing().exportImport().clear();
522+
testingClient.testing().exportImport().runImport();
523+
} finally {
524+
testingClient.testing().exportImport().clear();
525+
}
525526

526527
testExternalExchange();
527528
}
@@ -552,8 +553,8 @@ public void testExternalExchange() throws Exception {
552553
rep.getConfig().put("issuer", parentIssuer);
553554
adminClient.realm(CHILD_IDP).identityProviders().get(PARENT_IDP).update(rep);
554555

555-
String exchangedUserId = null;
556-
String exchangedUsername = null;
556+
String exchangedUserId;
557+
String exchangedUsername;
557558

558559
{
559560
// test signature validation
@@ -699,7 +700,7 @@ public void testExternalExchange() throws Exception {
699700

700701
{
701702
// test unauthorized client gets 403
702-
Response response = exchangeUrl.request()
703+
try (Response response = exchangeUrl.request()
703704
.header(HttpHeaders.AUTHORIZATION, BasicAuthHelper.createHeader(UNAUTHORIZED_CHILD_CLIENT, "password"))
704705
.post(Entity.form(
705706
new Form()
@@ -708,8 +709,9 @@ public void testExternalExchange() throws Exception {
708709
.param(OAuth2Constants.SUBJECT_TOKEN_TYPE, OAuth2Constants.JWT_TOKEN_TYPE)
709710
.param(OAuth2Constants.SUBJECT_ISSUER, PARENT_IDP)
710711

711-
));
712-
Assert.assertEquals(403, response.getStatus());
712+
))) {
713+
Assert.assertEquals(403, response.getStatus());
714+
}
713715
}
714716
} finally {
715717
httpClient.close();

testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/client/ClientPoliciesImportExportTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.keycloak.testsuite.client;
1919

20+
import org.junit.After;
2021
import org.junit.Test;
2122
import org.keycloak.exportimport.ExportImportConfig;
2223
import org.keycloak.exportimport.singlefile.SingleFileExportProviderFactory;
@@ -57,6 +58,11 @@ public void beforeAbstractKeycloakTestRealmImport() {
5758
removeAllRealmsDespiteMaster();
5859
}
5960

61+
@After
62+
public void afterImportExport() {
63+
testingClient.testing().exportImport().clear();
64+
}
65+
6066
@Test
6167
public void testSingleFileRealmExportImport() throws Throwable {
6268
testingClient.testing().exportImport().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);

0 commit comments

Comments
 (0)