Skip to content

Commit

Permalink
Merge pull request #27287 from c00crane/298364
Browse files Browse the repository at this point in the history
Reduce how many times we transform the idp war
  • Loading branch information
c00crane committed Jan 12, 2024
2 parents 14b4d3a + f36c076 commit 4d4b45d
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 49 deletions.
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2018, 2023 IBM Corporation and others.
* Copyright (c) 2018, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void addToAllowableTimeoutCount(int additionalCount) {
public static void timeoutChecker() throws Exception {
String method = "timeoutChecker";

int timeoutCounter = 0 ;
int timeoutCounter = 0;
boolean timeoutFound = false;
String outputFile = "./results/output.txt";
File f = new File(outputFile);
Expand Down Expand Up @@ -182,43 +182,47 @@ public WebClient getAndSaveWebClient(boolean override) throws Exception {

private static void transformAppsInDefaultDirs(TestServer server, String appDirName) {

LibertyServer myServer = server.getServer();
Machine machine = myServer.getMachine();
try {
LibertyServer myServer = server.getServer();
Machine machine = myServer.getMachine();

Log.info(thisClass, "transformAppsInDefaultDirs", "Processing " + appDirName + " for serverName: " + myServer.getServerName());
RemoteFile appDir = new RemoteFile(machine, LibertyServerUtils.makeJavaCompatible(myServer.getServerRoot() + File.separatorChar + appDirName, machine));
Log.info(thisClass, "transformAppsInDefaultDirs", "Processing " + appDirName + " for serverName: " + myServer.getServerName());
RemoteFile appDir = new RemoteFile(machine, LibertyServerUtils.makeJavaCompatible(myServer.getServerRoot() + File.separatorChar + appDirName, machine));

RemoteFile[] list = null;
try {
RemoteFile[] list = null;
if (appDir.isDirectory()) {
list = appDir.list(false);
}
if (list != null) {
for (RemoteFile app : list) {
if (!app.getName().contains("idp.war")) { // the idp.war should have already been transformed
JakartaEEAction.transformApp(Paths.get(app.getAbsolutePath()));
}
}
}
} catch (Exception e) {
Log.error(thisClass, "transformAppsInDefaultDirs", e);
}
if (list != null) {
for (RemoteFile app : list) {
JakartaEEAction.transformApp(Paths.get(app.getAbsolutePath()));
}
e.printStackTrace();
}
}

/**
* JakartaEE9 transform applications for a specified server.
*
* @param serverName The server to transform the applications on.
* @param serverName
* The server to transform the applications on.
*/
public static void transformApps(TestServer server) {
if (JakartaEEAction.isEE9OrLaterActive()) {

transformAppsInDefaultDirs(server, "dropins");
transformAppsInDefaultDirs(server, "test-apps");
// TODO - may break saml - may have to update saml rules
transformAppsInDefaultDirs(server, "idp-apps");
// // TODO - may break saml - may have to update saml rules
// transformAppsInDefaultDirs(server, "idp-apps");

}
}

@After
public void endTestCleanup() throws Exception {

Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2020, 2022 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -13,6 +13,7 @@
package com.ibm.ws.security.fat.common;

import java.io.File;
import java.nio.file.Paths;
import java.security.Provider;
import java.security.Security;
import java.util.HashMap;
Expand All @@ -29,9 +30,13 @@
import com.ibm.websphere.simplicity.log.Log;
import com.ibm.ws.security.fat.common.servers.ServerBootstrapUtils;

import componenttest.custom.junit.runner.RepeatTestFilter;
import componenttest.rules.repeater.JakartaEEAction;
import componenttest.rules.repeater.RepeatActions.EEVersion;
import componenttest.topology.impl.LibertyFileManager;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.utils.LDAPUtils;
import componenttest.topology.utils.LibertyServerUtils;

public class ShibbolethHelpers {
private final static Class<?> thisClass = ShibbolethHelpers.class;
Expand Down Expand Up @@ -480,16 +485,36 @@ public void fixShibbolethJvmOptions(TestServer server) throws Exception {

public void chooseIdpWarVersion(TestServer idpServer) throws Exception {

EEVersion eeVersion = null;
String eeVersionString = "";

String currentRepeatAction = RepeatTestFilter.getRepeatActionsAsString();
if (currentRepeatAction.contains(JakartaEEAction.EE9_ACTION_ID)) {
eeVersion = EEVersion.EE9;
}
if (currentRepeatAction.contains(JakartaEEAction.EE10_ACTION_ID)) {
eeVersion = EEVersion.EE10;
}

String thisMethod = "chooseIdpWarVersion";
LibertyServer theServer = idpServer.getServer();

File transformedWarFile = new java.io.File(LibertyServerUtils.makeJavaCompatible(theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war"));

// copy the appropriate version of the idp.war file
if (System.getProperty("java.specification.version").matches("1\\.[789]")) {
Log.info(thisClass, thisMethod, "################## Copying the 3.1.1 version of Shibbolet ##################h");
LibertyFileManager.copyFileIntoLiberty(theServer.getMachine(), theServer.getServerRoot() + "/test-apps", "idp.war", theServer.getServerRoot() + "/idp-apps/idp-war-3.3.1.war");
} else {
Log.info(thisClass, thisMethod, "################## Copying the 4.1.0 version of Shibboleth ##################");
LibertyFileManager.copyFileIntoLiberty(theServer.getMachine(), theServer.getServerRoot() + "/test-apps", "idp.war", theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war");
if (eeVersion != null) {
eeVersionString = "." + eeVersion.toString();
transformedWarFile = new java.io.File(LibertyServerUtils.makeJavaCompatible(theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war" + eeVersionString));
}
if (!transformedWarFile.exists() && eeVersion != null) {
JakartaEEAction.transformApp(Paths.get(theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war"), Paths.get(theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war" + eeVersionString), eeVersion);
}
LibertyFileManager.copyFileIntoLiberty(theServer.getMachine(), theServer.getServerRoot() + "/test-apps", "idp.war", theServer.getServerRoot() + "/idp-apps/idp-war-4.1.0.war" + eeVersionString);
}

}
Expand Down
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* Copyright (c) 2023, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand All @@ -12,26 +12,36 @@
*******************************************************************************/
package com.ibm.ws.security.fat.common.actions;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Set;

import com.ibm.websphere.simplicity.Machine;
import com.ibm.websphere.simplicity.OperatingSystem;
import com.ibm.websphere.simplicity.log.Log;

import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.custom.junit.runner.RepeatTestFilter;
import componenttest.custom.junit.runner.TestModeFilter;
import componenttest.rules.repeater.EmptyAction;
import componenttest.rules.repeater.FeatureReplacementAction;
import componenttest.rules.repeater.JakartaEE10Action;
import componenttest.rules.repeater.JakartaEE9Action;
import componenttest.rules.repeater.JakartaEEAction;
import componenttest.rules.repeater.RepeatActions.EEVersion;
import componenttest.rules.repeater.RepeatTestAction;
import componenttest.rules.repeater.RepeatTests;
import componenttest.topology.impl.JavaInfo;
import componenttest.topology.utils.LibertyServerUtils;

public class LargeProjectRepeatActions {

public static Class<?> thisClass = LargeProjectRepeatActions.class;

private static boolean doIDPTransform = false;

/**
* Create repeats for large security projects.
* On Windows, always run the default/empty/EE7/EE8 tests.
Expand All @@ -44,19 +54,52 @@ public class LargeProjectRepeatActions {
* @return repeat test instances
*/
public static RepeatTests createEE9OrEE10Repeats() {
return createEE9OrEE10Repeats(null, null, null, null);
doIDPTransform = false;
return createEE9OrEE10RepeatsWorker(null, null, null, null);
}

public static RepeatTests createEE9OrEE10SamlRepeats() {
doIDPTransform = true;
return createEE9OrEE10RepeatsWorker(null, null, null, null);

}

public static RepeatTests createEE9OrEE10Repeats(String addEE9Feature, String addEE10Feature) {
return createEE9OrEE10Repeats(addEE9Feature, addEE10Feature, null, null);
doIDPTransform = false;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, null, null);
}

public static RepeatTests createEE9OrEE10SamlRepeats(String addEE9Feature, String addEE10Feature) {
doIDPTransform = true;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, null, null);
}

public static RepeatTests createEE9OrEE10Repeats(String addEE9Feature, String addEE10Feature, Set<String> removeFeatureList, Set<String> insertFeatureList) {
return createEE9OrEE10Repeats(addEE9Feature, addEE10Feature, removeFeatureList, insertFeatureList, null);
doIDPTransform = false;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, removeFeatureList, insertFeatureList, null);
}

public static RepeatTests createEE9OrEE10SamlRepeats(String addEE9Feature, String addEE10Feature, Set<String> removeFeatureList, Set<String> insertFeatureList) {
doIDPTransform = true;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, removeFeatureList, insertFeatureList, null);
}

public static RepeatTests createEE9OrEE10Repeats(String addEE9Feature, String addEE10Feature, Set<String> removeFeatureList, Set<String> insertFeatureList, String... serverPaths) {

doIDPTransform = false;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, removeFeatureList, insertFeatureList, serverPaths);

}

public static RepeatTests createEE9OrEE10SamlRepeats(String addEE9Feature, String addEE10Feature, Set<String> removeFeatureList, Set<String> insertFeatureList, String... serverPaths) {

doIDPTransform = true;
return createEE9OrEE10RepeatsWorker(addEE9Feature, addEE10Feature, removeFeatureList, insertFeatureList, serverPaths);

}

public static RepeatTests createEE9OrEE10RepeatsWorker(String addEE9Feature, String addEE10Feature, Set<String> removeFeatureList, Set<String> insertFeatureList, String... serverPaths) {

RepeatTests rTests = null;

OperatingSystem currentOS = null;
Expand All @@ -75,9 +118,15 @@ public static RepeatTests createEE9OrEE10Repeats(String addEE9Feature, String ad
if (TestModeFilter.FRAMEWORK_TEST_MODE == TestMode.LITE) {
Log.info(thisClass, "createLargeProjectRepeats", "Enabling the EE9 test instance (Not on Windows, Java > 8, Lite Mode)");
rTests = addRepeat(rTests, adjustFeatures(JakartaEE9Action.ID, addEE9Feature, removeFeatureList, insertFeatureList, serverPaths));
if (doIDPTransform) {
idpWarTransform(EEVersion.EE9);
}
} else {
Log.info(thisClass, "createLargeProjectRepeats", "Enabling the EE10 test instance (Not on Windows, Java > 8, FULL Mode)");
rTests = addRepeat(rTests, adjustFeatures(JakartaEE10Action.ID, addEE10Feature, removeFeatureList, insertFeatureList, serverPaths));
if (doIDPTransform) {
idpWarTransform(EEVersion.EE10);
}
}
} else {
Log.info(thisClass, "createLargeProjectRepeats", "Enabling the default EE7/EE8 test instance (Not on Windows, Java = 8, any Mode)");
Expand Down Expand Up @@ -132,4 +181,52 @@ public static FeatureReplacementAction adjustFeatures(String featureType, String
return featureAction;
}

public static void idpWarTransform(EEVersion eeVersion) {

try {
List<RepeatTestAction> actions = RepeatTestFilter.getRepeatActions();

String currentPath = new java.io.File(".").getCanonicalPath();
Log.info(thisClass, "idpWarTransform", "Current dir :" + currentPath);
String shibDir = currentPath + "/publish/servers/com.ibm.ws.security.saml.sso-2.0_fat.shibboleth/idp-apps";
Log.info(thisClass, "idpWarTransform", "shibDir: " + shibDir);

File appDir = new java.io.File(LibertyServerUtils.makeJavaCompatible(shibDir));

File[] list = null;
try {
if (appDir.isDirectory()) {
Log.info(thisClass, "idpWarTransform", "appDir is a directory");
list = appDir.listFiles();
}
} catch (Exception e) {
Log.error(thisClass, "idpWarTransform", e);
}
if (list != null) {
Log.info(thisClass, "idpWarTransform", "list is not null");
for (File app : list) {
String fullAppName = shibDir + "/" + app.getName();
if (!app.getName().contains("3.3.1") && !app.getName().contains(eeVersion.toString())) {
Path appPathName = Paths.get(fullAppName);
Path appPathNewName = Paths.get(fullAppName + "." + eeVersion.toString());
Log.info(thisClass, "idpWarTransform", "From IDP war name: " + appPathName.toString());
Log.info(thisClass, "idpWarTransform", "To IDP war name: " + appPathNewName.toString());
JakartaEEAction.transformApp(appPathName, appPathNewName, eeVersion);
} else {
Log.info(thisClass, "idpWarTransform", "Skipping transform since we will only use the 3.3.1 version with Java 8");
}
}
}

} catch (Exception e) {
Log.info(thisClass, "idpWarTransform", "Failure trying to transform the idp wars" + e.getMessage());
e.getStackTrace();
}

}

public static String getParent(String dir) {
Log.info(thisClass, "getParent", "Starting path: " + dir);
return new java.io.File(dir).getParent();
}
}
Expand Up @@ -47,6 +47,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats("servlet-5.0", "servlet-6.0");
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats("servlet-5.0", "servlet-6.0");

}
Expand Up @@ -47,6 +47,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats("servlet-5.0", "servlet-6.0");
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats("servlet-5.0", "servlet-6.0");

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corporation and others.
* Copyright (c) 2014, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -77,6 +77,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats();
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats();

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corporation and others.
* Copyright (c) 2014, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -64,6 +64,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats();
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats();

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corporation and others.
* Copyright (c) 2014, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -43,6 +43,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats();
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats();

}
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2014, 2023 IBM Corporation and others.
* Copyright (c) 2014, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -46,6 +46,6 @@ public class FATSuite extends CommonLocalLDAPServerSuite {
*
*/
@ClassRule
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10Repeats();
public static RepeatTests repeat = LargeProjectRepeatActions.createEE9OrEE10SamlRepeats();

}

0 comments on commit 4d4b45d

Please sign in to comment.