Skip to content

Commit 253422e

Browse files
committed
Merge branch 'OWLS-130070-port' into 'main'
Porting crossdomaintransactionsecurity tests from 4.2 branch See merge request weblogic-cloud/weblogic-kubernetes-operator!5003
2 parents 8466d7b + f527b41 commit 253422e

30 files changed

+1723
-741
lines changed

integration-tests/src/test/java/oracle/weblogic/kubernetes/ItCrossDomainTransactionSecurity.java

Lines changed: 339 additions & 704 deletions
Large diffs are not rendered by default.

integration-tests/src/test/java/oracle/weblogic/kubernetes/actions/impl/WDTArchiveHelper.java

Lines changed: 134 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,24 @@
2727
import static org.junit.jupiter.api.Assertions.assertTrue;
2828

2929
/**
30-
* Implementation of actions that createArchive an application archive file.
30+
* Implementation of actions that createArchive an application archive file.
3131
*/
32-
3332
public class WDTArchiveHelper {
34-
33+
3534
private AppParams params;
3635

3736
/**
3837
* Create an AppParams instance with the default values.
39-
* @return an AppParams instance
38+
*
39+
* @return an AppParams instance
4040
*/
4141
public static AppParams defaultAppParams() {
4242
return new AppParams().defaults();
4343
}
4444

4545
/**
4646
* Create an AppParams instance with the custom values.
47+
*
4748
* @return an AppParams instance
4849
*/
4950
public static AppParams customAppParams(List<String> srcDirList) {
@@ -52,9 +53,9 @@ public static AppParams customAppParams(List<String> srcDirList) {
5253

5354
/**
5455
* Set up the AppBuilder with given parameters.
55-
*
56+
*
5657
* @param params instance of {@link AppParams} that contains parameters to createArchive an application archive
57-
* @return the AppBuilder instance
58+
* @return the AppBuilder instance
5859
*/
5960
public static WDTArchiveHelper withParams(AppParams params) {
6061
return new WDTArchiveHelper().params(params);
@@ -82,10 +83,10 @@ public boolean createArchive(boolean structuredApplication) throws IOException {
8283
checkDirectory(archiveSrcDir);
8384
for (String item : params.srcDirList()) {
8485
copyFolder(
85-
APP_DIR + "/" + item,
86+
APP_DIR + "/" + item,
8687
archiveSrcDir);
8788
}
88-
} catch (IOException ioe) {
89+
} catch (IOException ioe) {
8990
getLogger().severe("Failed to get the directory " + archiveSrcDir + " ready", ioe);
9091
return false;
9192
}
@@ -100,7 +101,7 @@ public boolean createArchive(boolean structuredApplication) throws IOException {
100101
String jarPath = String.format("%s.ear", params.appName());
101102
jarBuilt = buildJarArchive(jarPath, archiveSrcDir);
102103
}
103-
104+
104105
// createArchive a zip file that can be passed to WIT
105106
String zipPath = String.format("%s/%s.zip", params.appArchiveDir(), params.appName());
106107
boolean zipBuilt = buildZipArchive(zipPath, params.appArchiveDir());
@@ -132,19 +133,57 @@ public boolean addToArchive() throws IOException {
132133
return createArchive();
133134
}
134135
}
135-
136+
136137
/**
137138
* Build an application archive using a pre-populated AppParams instance.
138-
* @return true if the command succeeds
139+
*
140+
* @return true if the command succeeds
139141
* @throws java.io.IOException when WDT download fails
140142
*/
141-
public boolean createArchiveWithStructuredApplication() throws IOException {
142-
return createArchive(true);
143+
public boolean createArchiveWithStructuredApplication(String archiveName) throws IOException {
144+
// check and install WDT
145+
checkAndInstallWDT();
146+
// make sure that we always have an app name
147+
if (params.appName() == null) {
148+
getLogger().info("Appname is not set, setting it to app src dir name");
149+
params.appName(params.srcDirList().get(0));
150+
}
151+
String archiveSrcDir = params.appArchiveDir()
152+
+ "/wlsdeploy/applications/" + params.appName();
153+
// prepare the archive directory and copy over the app src
154+
try {
155+
cleanupDirectory(archiveSrcDir);
156+
checkDirectory(archiveSrcDir);
157+
for (String item : params.srcDirList()) {
158+
getLogger().info("Copying {0} to {1}", item, archiveSrcDir);
159+
copyFolder(
160+
item,
161+
archiveSrcDir);
162+
}
163+
} catch (IOException ioe) {
164+
getLogger().severe("Failed to get the directory " + archiveSrcDir + " ready", ioe);
165+
return false;
166+
}
167+
168+
// createArchive a zip file that can be passed to WIT
169+
String zipPath = String.format("%s/%s.zip", params.appArchiveDir(), archiveName);
170+
String cmd = String.format(
171+
archiveHelperScript + " add structuredApplication"
172+
+ " -archive_file %s"
173+
+ " -source %s ",
174+
zipPath,
175+
archiveSrcDir);
176+
return Command.withParams(
177+
defaultCommandParams()
178+
.command(cmd)
179+
.verbose(true)
180+
.redirect(false))
181+
.execute();
143182
}
144-
145183

146184
/**
147185
* Build an application archive using a pre-populated AppParams instance.
186+
*
148187
* @return true if the command succeeds
149188
*/
150189
public boolean buildCoherence() {
@@ -172,7 +211,7 @@ public boolean buildCoherence() {
172211
String jarPath = String.format("%s.gar", params.appName());
173212
jarBuilt = buildJarArchive(jarPath, archiveSrcDir);
174213
} else if (params.appName().contains("CoherenceApp")) {
175-
String [] appTypes = {"ear", "gar"};
214+
String[] appTypes = {"ear", "gar"};
176215
try {
177216
for (String appType : appTypes) {
178217
String appSrcDir = String.format("%s/%s/u01/application/builddir/%s.%s",
@@ -205,14 +244,14 @@ public boolean buildCoherence() {
205244
* @param srcDir source directory
206245
*/
207246
private boolean buildJarArchive(
208-
String jarPath,
247+
String jarPath,
209248
String srcDir
210249
) {
211250

212251
String cmd = String.format("cd %s; jar -cfM %s . ", srcDir, jarPath);
213252

214253
return Command.withParams(
215-
defaultCommandParams()
254+
defaultCommandParams()
216255
.command(cmd)
217256
.redirect(false))
218257
.execute();
@@ -225,7 +264,7 @@ private boolean buildJarArchive(
225264
* @param srcDir source directory
226265
*/
227266
public boolean buildZipArchive(
228-
String zipPath,
267+
String zipPath,
229268
String srcDir
230269
) {
231270

@@ -251,6 +290,64 @@ public boolean buildZipArchive(
251290
.execute();
252291
}
253292

293+
/**
294+
* Build a zip archive that includes an ear file in the srcDir.
295+
*
296+
* @param zipPath zip file path for the resulting archive
297+
* @param serverName server name
298+
* @param source source directory
299+
*/
300+
public boolean addServerKeystore(
301+
String zipPath,
302+
String serverName,
303+
String source
304+
) {
305+
306+
String cmd = String.format(
307+
archiveHelperScript + " add serverKeystore"
308+
+ " -archive_file %s"
309+
+ " -server_name %s"
310+
+ " -source %s ",
311+
zipPath,
312+
serverName,
313+
source);
314+
315+
return Command.withParams(
316+
defaultCommandParams()
317+
.command(cmd)
318+
.verbose(true)
319+
.redirect(false))
320+
.execute();
321+
}
322+
323+
/**
324+
* Build a zip archive that includes an ear file in the srcDir.
325+
*
326+
* @param zipPath zip file path for the resulting archive
327+
* @param source source directory
328+
*/
329+
public boolean addCustom(
330+
String zipPath,
331+
String source
332+
) {
333+
334+
String cmd = String.format(
335+
archiveHelperScript + " add custom"
336+
+ " -archive_file %s"
337+
+ "-path patch"
338+
+ "-use_non_replicable_location"
339+
+ " -source %s ",
340+
zipPath,
341+
source);
342+
343+
return Command.withParams(
344+
defaultCommandParams()
345+
.command(cmd)
346+
.verbose(true)
347+
.redirect(false))
348+
.execute();
349+
}
350+
254351
/**
255352
* Build a zip archive that includes coh-proxy-server.gar in the srcDir.
256353
*
@@ -272,27 +369,27 @@ public boolean buildCoherenceZipArchive(String zipPath, String srcDir) {
272369

273370
if (params.appName().contains("CoherenceApp")) {
274371
cmd = String.format(
275-
"cd %s ; zip -r %s.zip wlsdeploy/applications ",
276-
params.appArchiveDir(),
277-
params.appName()
372+
"cd %s ; zip -r %s.zip wlsdeploy/applications ",
373+
params.appArchiveDir(),
374+
params.appName()
278375
);
279376
}
280377

281378
return Command.withParams(
282-
defaultCommandParams()
283-
.command(cmd)
284-
.redirect(false))
285-
.execute();
379+
defaultCommandParams()
380+
.command(cmd)
381+
.redirect(false))
382+
.execute();
286383
}
287384

288385
/**
289-
* Archive an application from provided ear or war file that can be used by WebLogic Image Tool
290-
* to create an image with the application for a model-in-image use case.
386+
* Archive an application from provided ear or war file that can be used by WebLogic Image Tool to create an image
387+
* with the application for a model-in-image use case.
291388
*
292389
* @return true if the operation succeeds
293390
*/
294391
public boolean archiveApp() {
295-
List<String> srcFiles = params.srcDirList();
392+
List<String> srcFiles = params.srcDirList();
296393
String srcFile = srcFiles.get(0);
297394
String appName = srcFile.substring(srcFile.lastIndexOf("/") + 1, srcFile.lastIndexOf("."));
298395
params.appName(appName);
@@ -306,7 +403,7 @@ public boolean archiveApp() {
306403
getLogger().info("copy {0} to {1} ", appSrcFile, archiveSrcDir);
307404
String fileName = appSrcFile.substring(appSrcFile.lastIndexOf("/") + 1);
308405
Files.copy(Paths.get(appSrcFile), Paths.get(archiveSrcDir + "/" + fileName),
309-
StandardCopyOption.REPLACE_EXISTING);
406+
StandardCopyOption.REPLACE_EXISTING);
310407
}
311408
}
312409
} catch (IOException ioe) {
@@ -315,18 +412,18 @@ public boolean archiveApp() {
315412
}
316413

317414
String cmd = String.format(
318-
"cd %s ; zip -r %s.zip wlsdeploy/applications ",
319-
params.appArchiveDir(),
320-
appName
415+
"cd %s ; zip -r %s.zip wlsdeploy/applications ",
416+
params.appArchiveDir(),
417+
appName
321418
);
322419

323420
return Command.withParams(
324-
defaultCommandParams()
325-
.command(cmd)
326-
.redirect(false))
327-
.execute();
421+
defaultCommandParams()
422+
.command(cmd)
423+
.redirect(false))
424+
.execute();
328425
}
329-
426+
330427
static Path archiveHelperScript = Path.of(DOWNLOAD_DIR, "wdt", "weblogic-deploy", "bin", "archiveHelper.sh");
331428

332429
private static void downloadAndInstallWDT() throws IOException {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="5.0"
3+
xmlns="https://jakarta.ee/xml/ns/jakartaee"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee web-app_5_0.xsd">
6+
</web-app>

integration-tests/src/test/resources/apps/jakartawebapp/WEB-INF/weblogic.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3+
</weblogic-web-app>

0 commit comments

Comments
 (0)