KEYCLOAK-3211 - ExportImportTest fix for Wildfly
This commit is contained in:
parent
d94515cdae
commit
4974079794
3 changed files with 150 additions and 23 deletions
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package org.keycloak.testsuite.rest;
|
package org.keycloak.testsuite.rest;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -76,6 +77,8 @@ import org.keycloak.representations.idm.AuthDetailsRepresentation;
|
||||||
import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
|
import org.keycloak.representations.idm.AuthenticationFlowRepresentation;
|
||||||
import org.keycloak.representations.idm.UserRepresentation;
|
import org.keycloak.representations.idm.UserRepresentation;
|
||||||
|
|
||||||
|
import static org.keycloak.exportimport.ExportImportConfig.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||||
*/
|
*/
|
||||||
|
@ -649,4 +652,78 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
||||||
return realmProvider.getRealmByName(realmName);
|
return realmProvider.getRealmByName(realmName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-users-per-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Integer getUsersPerFile() {
|
||||||
|
String usersPerFile = System.getProperty(USERS_PER_FILE, String.valueOf(DEFAULT_USERS_PER_FILE));
|
||||||
|
return Integer.parseInt(usersPerFile.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-users-per-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile) {
|
||||||
|
System.setProperty(USERS_PER_FILE, String.valueOf(usersPerFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getDir() {
|
||||||
|
return System.getProperty(DIR);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String setDir(@QueryParam("dir") String dir) {
|
||||||
|
return System.setProperty(DIR, dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-provider")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider) {
|
||||||
|
System.setProperty(PROVIDER, exportImportProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setFile(@QueryParam("file") String file) {
|
||||||
|
System.setProperty(FILE, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-action")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setAction(@QueryParam("exportImportAction") String exportImportAction) {
|
||||||
|
System.setProperty(ACTION, exportImportAction);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-realm-name")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setRealmName(@QueryParam("realmName") String realmName) {
|
||||||
|
if (realmName != null && !realmName.isEmpty()) {
|
||||||
|
System.setProperty(REALM_NAME, realmName);
|
||||||
|
} else {
|
||||||
|
System.getProperties().remove(REALM_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-test-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getExportImportTestDirectory() {
|
||||||
|
System.setProperty("project.build.directory", "target");
|
||||||
|
String absolutePath = new File(System.getProperty("project.build.directory", "target")).getAbsolutePath();
|
||||||
|
return absolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -249,4 +249,54 @@ public interface TestingResource {
|
||||||
@Path("/get-user-by-service-account-client")
|
@Path("/get-user-by-service-account-client")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
public UserRepresentation getUserByServiceAccountClient(@QueryParam("realmName") String realmName, @QueryParam("clientId") String clientId);
|
public UserRepresentation getUserByServiceAccountClient(@QueryParam("realmName") String realmName, @QueryParam("clientId") String clientId);
|
||||||
|
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-users-per-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public Integer getUsersPerFile();
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-users-per-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setUsersPerFile(@QueryParam("usersPerFile") Integer usersPerFile);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getDir();
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String setDir(@QueryParam("dir") String dir);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-provider")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setProvider(@QueryParam("exportImportProvider") String exportImportProvider);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-file")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setFile(@QueryParam("file") String file);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/export-import-action")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setAction(@QueryParam("exportImportAction") String exportImportAction);
|
||||||
|
|
||||||
|
@PUT
|
||||||
|
@Path("/set-realm-name")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
public void setRealmName(@QueryParam("realmName") String realmName);
|
||||||
|
|
||||||
|
@GET
|
||||||
|
@Path("/get-test-dir")
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
public String getExportImportTestDirectory();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,11 +73,11 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirFullExportImport() throws Throwable {
|
public void testDirFullExportImport() throws Throwable {
|
||||||
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||||
String targetDirPath = getExportImportTestDirectory() + File.separator + "dirExport";
|
String targetDirPath = testingClient.testing().getExportImportTestDirectory()+ File.separator + "dirExport";
|
||||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||||
ExportImportConfig.setDir(targetDirPath);
|
testingClient.testing().setDir(targetDirPath);
|
||||||
ExportImportConfig.setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
testingClient.testing().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
||||||
|
|
||||||
testFullExportImport();
|
testFullExportImport();
|
||||||
|
|
||||||
|
@ -87,11 +87,11 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirRealmExportImport() throws Throwable {
|
public void testDirRealmExportImport() throws Throwable {
|
||||||
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||||
String targetDirPath = getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
String targetDirPath = testingClient.testing().getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
||||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||||
ExportImportConfig.setDir(targetDirPath);
|
testingClient.testing().setDir(targetDirPath);
|
||||||
ExportImportConfig.setUsersPerFile(3);
|
testingClient.testing().setUsersPerFile(3);
|
||||||
|
|
||||||
testRealmExportImport();
|
testRealmExportImport();
|
||||||
|
|
||||||
|
@ -102,18 +102,18 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleFileFullExportImport() throws Throwable {
|
public void testSingleFileFullExportImport() throws Throwable {
|
||||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||||
String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
||||||
ExportImportConfig.setFile(targetFilePath);
|
testingClient.testing().setFile(targetFilePath);
|
||||||
|
|
||||||
testFullExportImport();
|
testFullExportImport();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingleFileRealmExportImport() throws Throwable {
|
public void testSingleFileRealmExportImport() throws Throwable {
|
||||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||||
String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||||
ExportImportConfig.setFile(targetFilePath);
|
testingClient.testing().setFile(targetFilePath);
|
||||||
|
|
||||||
testRealmExportImport();
|
testRealmExportImport();
|
||||||
}
|
}
|
||||||
|
@ -124,12 +124,12 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
removeRealm("test-realm");
|
removeRealm("test-realm");
|
||||||
|
|
||||||
// Set the realm, which doesn't have builtin clients/roles inside JSON
|
// Set the realm, which doesn't have builtin clients/roles inside JSON
|
||||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||||
URL url = ExportImportTest.class.getResource("/model/testrealm.json");
|
URL url = ExportImportTest.class.getResource("/model/testrealm.json");
|
||||||
String targetFilePath = new File(url.getFile()).getAbsolutePath();
|
String targetFilePath = new File(url.getFile()).getAbsolutePath();
|
||||||
ExportImportConfig.setFile(targetFilePath);
|
testingClient.testing().setFile(targetFilePath);
|
||||||
|
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||||
|
|
||||||
testingClient.testing().runImport();
|
testingClient.testing().runImport();
|
||||||
|
|
||||||
|
@ -144,8 +144,8 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testFullExportImport() throws LifecycleException {
|
private void testFullExportImport() throws LifecycleException {
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||||
ExportImportConfig.setRealmName(null);
|
testingClient.testing().setRealmName("");
|
||||||
|
|
||||||
testingClient.testing().runExport();
|
testingClient.testing().runExport();
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
assertNotAuthenticated("test", "user3", "password");
|
assertNotAuthenticated("test", "user3", "password");
|
||||||
|
|
||||||
// Configure import
|
// Configure import
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||||
|
|
||||||
testingClient.testing().runImport();
|
testingClient.testing().runImport();
|
||||||
|
|
||||||
|
@ -173,8 +173,8 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testRealmExportImport() throws LifecycleException {
|
private void testRealmExportImport() throws LifecycleException {
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||||
ExportImportConfig.setRealmName("test");
|
testingClient.testing().setRealmName("test");
|
||||||
|
|
||||||
testingClient.testing().runExport();
|
testingClient.testing().runExport();
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class ExportImportTest extends AbstractExportImportTest {
|
||||||
assertNotAuthenticated("test", "user3", "password");
|
assertNotAuthenticated("test", "user3", "password");
|
||||||
|
|
||||||
// Configure import
|
// Configure import
|
||||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||||
|
|
||||||
testingClient.testing().runImport();
|
testingClient.testing().runImport();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue