Merge pull request #3119 from fkiss/master-exportimport
KEYCLOAK-3211 - ExportImportTest fix for Wildfly
This commit is contained in:
commit
7f6fc170dc
3 changed files with 150 additions and 23 deletions
|
@ -17,6 +17,7 @@
|
|||
|
||||
package org.keycloak.testsuite.rest;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
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.UserRepresentation;
|
||||
|
||||
import static org.keycloak.exportimport.ExportImportConfig.*;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
||||
*/
|
||||
|
@ -649,4 +652,78 @@ public class TestingResourceProvider implements RealmResourceProvider {
|
|||
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")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -75,11 +75,11 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testDirFullExportImport() throws Throwable {
|
||||
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = getExportImportTestDirectory() + File.separator + "dirExport";
|
||||
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().getExportImportTestDirectory()+ File.separator + "dirExport";
|
||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||
ExportImportConfig.setDir(targetDirPath);
|
||||
ExportImportConfig.setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
||||
testingClient.testing().setDir(targetDirPath);
|
||||
testingClient.testing().setUsersPerFile(ExportImportConfig.DEFAULT_USERS_PER_FILE);
|
||||
|
||||
testFullExportImport();
|
||||
|
||||
|
@ -89,11 +89,11 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testDirRealmExportImport() throws Throwable {
|
||||
ExportImportConfig.setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
||||
testingClient.testing().setProvider(DirExportProviderFactory.PROVIDER_ID);
|
||||
String targetDirPath = testingClient.testing().getExportImportTestDirectory() + File.separator + "dirRealmExport";
|
||||
DirExportProvider.recursiveDeleteDir(new File(targetDirPath));
|
||||
ExportImportConfig.setDir(targetDirPath);
|
||||
ExportImportConfig.setUsersPerFile(3);
|
||||
testingClient.testing().setDir(targetDirPath);
|
||||
testingClient.testing().setUsersPerFile(3);
|
||||
|
||||
testRealmExportImport();
|
||||
|
||||
|
@ -104,18 +104,18 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
|
||||
@Test
|
||||
public void testSingleFileFullExportImport() throws Throwable {
|
||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
||||
ExportImportConfig.setFile(targetFilePath);
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-full.json";
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
|
||||
testFullExportImport();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleFileRealmExportImport() throws Throwable {
|
||||
ExportImportConfig.setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
ExportImportConfig.setFile(targetFilePath);
|
||||
testingClient.testing().setProvider(SingleFileExportProviderFactory.PROVIDER_ID);
|
||||
String targetFilePath = testingClient.testing().getExportImportTestDirectory() + File.separator + "singleFile-realm.json";
|
||||
testingClient.testing().setFile(targetFilePath);
|
||||
|
||||
testRealmExportImport();
|
||||
}
|
||||
|
@ -126,12 +126,12 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
removeRealm("test-realm");
|
||||
|
||||
// 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");
|
||||
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();
|
||||
|
||||
|
@ -203,8 +203,8 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
}
|
||||
|
||||
private void testFullExportImport() throws LifecycleException {
|
||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
ExportImportConfig.setRealmName(null);
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().setRealmName("");
|
||||
|
||||
testingClient.testing().runExport();
|
||||
|
||||
|
@ -218,7 +218,7 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
assertNotAuthenticated("test", "user3", "password");
|
||||
|
||||
// Configure import
|
||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
|
||||
|
@ -232,8 +232,8 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
}
|
||||
|
||||
private void testRealmExportImport() throws LifecycleException {
|
||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
ExportImportConfig.setRealmName("test");
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_EXPORT);
|
||||
testingClient.testing().setRealmName("test");
|
||||
|
||||
testingClient.testing().runExport();
|
||||
|
||||
|
@ -248,7 +248,7 @@ public class ExportImportTest extends AbstractExportImportTest {
|
|||
assertNotAuthenticated("test", "user3", "password");
|
||||
|
||||
// Configure import
|
||||
ExportImportConfig.setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
testingClient.testing().setAction(ExportImportConfig.ACTION_IMPORT);
|
||||
|
||||
testingClient.testing().runImport();
|
||||
|
||||
|
|
Loading…
Reference in a new issue