Skip to content

Commit 87eea94

Browse files
authored
Merge pull request #31179 from tloodu/validationkey-fat
Validation Key FAT Tests
2 parents 7698a5d + 51afae2 commit 87eea94

File tree

17 files changed

+1758
-29
lines changed

17 files changed

+1758
-29
lines changed

dev/com.ibm.ws.security.token.ltpa/src/com/ibm/ws/security/token/ltpa/internal/LTPAConfigurationImpl.java

+37-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2023 IBM Corporation and others.
2+
* Copyright (c) 2012, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -24,6 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.Properties;
27+
import java.util.StringJoiner;
2728
import java.util.concurrent.ExecutorService;
2829
import java.util.concurrent.locks.ReentrantReadWriteLock;
2930
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
@@ -237,14 +238,15 @@ private void loadConfig(Map<String, Object> props) {
237238
*/
238239
private void debugLTPAConfig() {
239240
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
240-
Tr.debug(tc, "primaryKeyImportFile: " + primaryKeyImportFile);
241-
//Tr.debug(tc, "primaryKeyPassword: " + primaryKeyPassword);
242-
Tr.debug(tc, "keyTokenExpiration: " + keyTokenExpiration);
243-
Tr.debug(tc, "monitorInterval: " + monitorInterval);
244-
Tr.debug(tc, "authFilterRef: " + authFilterRef);
245-
Tr.debug(tc, "monitorValidationKeysDir: " + monitorValidationKeysDir);
246-
Tr.debug(tc, "updateTrigger: " + updateTrigger);
247-
Tr.debug(tc, "validationKeys: " + (validationKeys == null ? "Null" : maskKeysPasswords(validationKeys)));
241+
StringJoiner sj = new StringJoiner(", ", "debugLTPAConfig[", "]");
242+
sj.add("primaryKeyImportFile: " + primaryKeyImportFile);
243+
sj.add("keyTokenExpiration: " + keyTokenExpiration);
244+
sj.add("monitorInterval: " + monitorInterval);
245+
sj.add("authFilterRef: " + authFilterRef);
246+
sj.add("monitorValidationKeysDir: " + monitorValidationKeysDir);
247+
sj.add("updateTrigger: " + updateTrigger);
248+
sj.add("validationKeys: " + (validationKeys == null ? "Null" : maskKeysPasswords(validationKeys)));
249+
Tr.debug(tc, sj.toString());
248250
}
249251
}
250252

@@ -319,8 +321,15 @@ private List<Properties> getNonConfiguredValidationKeys() {
319321
return validationKeysInDirectory;
320322
}
321323

324+
/*
325+
* Use the canonical path when comparing primaryKeyImportFile to fullFileName because fullFileName is
326+
* derived primaryKeyImportDir which is a canonical path. If we don't compare with a canonical path then the
327+
* comparison fails on windows when '/' are used in server.xml instead of '\'.
328+
*/
329+
String canonicalPrimaryKeyImportFile = getCanonicalPathWithDefault(primaryKeyImportFile, primaryKeyImportFile);
330+
322331
// Skip the primary LTPA keys file or validationKeys file configured in the valicationKeys element
323-
if (primaryKeyImportFile.equals(fullFileName) || isConfiguredValidationKeys(fullFileName)) {
332+
if (canonicalPrimaryKeyImportFile.equals(fullFileName) || isConfiguredValidationKeys(fullFileName)) {
324333
continue;
325334
}
326335

@@ -339,6 +348,24 @@ private List<Properties> getNonConfiguredValidationKeys() {
339348
return validationKeysInDirectory;
340349
}
341350

351+
/**
352+
* @param defaultValue
353+
* @param pathToResolve
354+
* @return
355+
*/
356+
private String getCanonicalPathWithDefault(String pathToResolve, String defaultValue) {
357+
String canonicalPrimaryKeyImportFile;
358+
try {
359+
canonicalPrimaryKeyImportFile = new File(pathToResolve).getCanonicalPath();
360+
361+
} catch (IOException ioe) {
362+
Tr.debug(tc, "Could not resolve canonical path to " + pathToResolve +
363+
", returning default '" + defaultValue + "'. Failure info: " + ioe.getMessage());
364+
canonicalPrimaryKeyImportFile = defaultValue;
365+
}
366+
return canonicalPrimaryKeyImportFile;
367+
}
368+
342369
/**
343370
* @param fn
344371
* @return
@@ -367,7 +394,6 @@ private void resolveActualPrimaryKeysFileLocation() {
367394

368395
if (monitorValidationKeysDir || isValidationKeysFileConfigured) {
369396
try {
370-
// primaryKeyImportFile has already been resolved when the server loads the config, this includes variable and .. being resolved.
371397
// primaryKeyImportDir is required to be set to load any validation keys.
372398
primaryKeyImportDir = new File(primaryKeyImportFile).getCanonicalFile().getParent() + File.separator;
373399
Tr.debug(tc, "primaryKeyImportDir: " + primaryKeyImportDir);

dev/com.ibm.ws.security.token.ltpa/test/com/ibm/ws/security/token/ltpa/internal/LTPAConfigurationImplTest.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2023 IBM Corporation and others.
2+
* Copyright (c) 2012, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -16,6 +16,8 @@
1616
import static org.junit.Assert.assertSame;
1717
import static org.junit.Assert.assertTrue;
1818

19+
import java.io.File;
20+
import java.io.IOException;
1921
import java.net.MalformedURLException;
2022
import java.util.ArrayList;
2123
import java.util.HashMap;
@@ -59,14 +61,10 @@ public class LTPAConfigurationImplTest {
5961
private static SharedOutputManager outputMgr;
6062

6163
private static final String PATH_TO_FILE = "/path/to/file";
62-
private static final String PATH_TO_DIR = "/path/to/";
6364
private static final String PATH_TO_ANOTHER_FILE = "/path/to/another/file";
64-
private static final String DEFAULT_CONFIG_LOCATION_DIR = "${server.config.dir}/resources/security/";
6565
private static final String DEFAULT_CONFIG_LOCATION = "${server.config.dir}/resources/security/ltpa.keys";
6666
private static final String DEFAULT_OUTPUT_LOCATION = "${server.output.dir}/resources/security/ltpa.keys";
67-
private static final String DEFAULT_VALIDATION_KEY_LOCATION = "${server.config.dir}/resources/security/validation.keys";
6867
private static final String RESOLVED_DEFAULT_CONFIG_LOCATION = "testServerName/resources/security/ltpa.keys";
69-
private static final String RESOLVED_DEFAULT_CONFIG_LOCATION_DIR = "testServerName/resources/security/";
7068
private static final String RESOLVED_DEFAULT_OUTPUT_LOCATION = "testServerName/resources/security/ltpa.keys";
7169
private static final String DEFAULT_VALIDATION_KEY_ELEMENT = "<validationKeys fileName=\"validation.keys\" password=\"pwd\" validUntilDate=\"2099-01-01T00:00:00Z\"/>";
7270
private static final String DEFAULT_VALIDATION_FILENAME = "validation.keys";
@@ -95,8 +93,18 @@ public class LTPAConfigurationImplTest {
9593
private final LTPAKeysChangeNotifier ltpaKeysChangeNotifier = mock.mock(LTPAKeysChangeNotifier.class);
9694

9795
private LTPAConfigurationImplTestDouble ltpaConfig;
96+
9897
private Map<String, Object> props;
9998

99+
private static String PATH_TO_DIR;
100+
static {
101+
try {
102+
PATH_TO_DIR = new File("/path/to/").getCanonicalPath() + File.separator;
103+
} catch (IOException ioe) {
104+
PATH_TO_DIR = "/path/to/" + File.separator;
105+
}
106+
}
107+
100108
@BeforeClass
101109
public static void setUpBeforeClass() throws Exception {
102110
outputMgr = SharedOutputManager.getInstance();
@@ -315,7 +323,7 @@ public void fileMonitorRegistration_updateTriggerMbean() throws Exception {
315323

316324
assertTrue("The LTPA file monitor registration must be set.", ltpaConfig.wasSetFileMonitorRegistrationCalled);
317325
}
318-
326+
319327
/**
320328
* Tests that the file monitor is not registered and set in the LTPAConfigImpl object when updateTrigger is set to disabled.
321329
*/
@@ -331,7 +339,6 @@ public void fileMonitorRegistration_updateTriggerDisabled() throws Exception {
331339
assertTrue("The LTPA file monitor registration must not be set.", !ltpaConfig.wasSetFileMonitorRegistrationCalled);
332340
}
333341

334-
@SuppressWarnings("deprecation")
335342
private void setupFileMonitorRegistrationsExpectations(final int numberOfInvocations) {
336343
mock.checking(new Expectations() {
337344
{
@@ -392,7 +399,7 @@ public void getUpdateTrigger() {
392399
@Test
393400
public void getValidationKeys() {
394401
assertEquals("The validationKeys value was not the expected value",
395-
"[{fileName=/path/to/validation.keys, password=pwd, validUntilDate=2099-01-01T00:00:00Z}]", ltpaConfig.getValidationKeys().toString());
402+
"[{fileName=" + PATH_TO_DIR + "validation.keys, password=pwd, validUntilDate=2099-01-01T00:00:00Z}]", ltpaConfig.getValidationKeys().toString());
396403
}
397404

398405
/**
@@ -652,6 +659,6 @@ public void maskKeysPasswords_replacesPasswordWithMask() {
652659
List<Properties> outputList = ltpaConfig.maskKeysPasswords(inputList);
653660

654661
// Assert
655-
assertEquals("The password was not masked correctly", expectedList, outputList);
662+
assertEquals("The password was not masked correctly", expectedList, outputList);
656663
}
657664
}

dev/com.ibm.ws.security.token.ltpa/test/com/ibm/ws/security/token/ltpa/internal/LTPAKeyCreateTaskTest.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2012, 2023 IBM Corporation and others.
2+
* Copyright (c) 2012, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -47,9 +47,7 @@ public class LTPAKeyCreateTaskTest {
4747

4848
private static SharedOutputManager outputMgr = SharedOutputManager.getInstance();
4949
private static final String DEFAULT_OUTPUT_LOCATION = "${server.output.dir}/resources/security/ltpa.keys";
50-
private static final String DEFAULT_OUTPUT_LOCATION_DIR = "${server.output.dir}/resources/security/";
5150
private static final String RESOLVED_DEFAULT_OUTPUT_LOCATION = "testServerName/resources/security/ltpa.keys";
52-
private static final String RESOLVED_DEFAULT_OUTPUT_LOCATION_DIR = "testServerName/resources/security/";
5351
private static String TEST_FILE_NAME = "testFileName";
5452

5553
/**
@@ -75,7 +73,8 @@ private class LTPAKeyCreatorDouble extends LTPAKeyCreateTask {
7573
}
7674

7775
@Override
78-
void createRequiredCollaborators() throws Exception {}
76+
void createRequiredCollaborators() throws Exception {
77+
}
7978
}
8079

8180
@Before

dev/com.ibm.ws.security.token.ltpa_fat/build.gradle

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2024 IBM Corporation and others.
2+
* Copyright (c) 2020, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -73,7 +73,9 @@ autoFVT.doLast {
7373
def servers = [
7474
'com.ibm.ws.security.token.ltpa.fat',
7575
'com.ibm.ws.security.token.ltpa.fat.contextRootCookiePathTestServer',
76-
'com.ibm.ws.security.token.ltpa.fat.ltpaKeyRotationTestServer'
76+
'com.ibm.ws.security.token.ltpa.fat.ltpaKeyRotationTestServer',
77+
'com.ibm.ws.security.token.ltpa.fat.validationKeyTestServer1',
78+
'com.ibm.ws.security.token.ltpa.fat.validationKeyTestServer2'
7779
]
7880
servers.each { server ->
7981
copy {
@@ -105,6 +107,16 @@ autoFVT.doLast {
105107
into new File(autoFvtDir, 'lib/LibertyFATTestFiles')
106108
rename 'server.xml', 'ltpaKeyRotationTestServer.server.orig.xml'
107109
}
110+
copy {
111+
from new File(projectDir, 'publish/servers/com.ibm.ws.security.token.ltpa.fat.validationKeyTestServer1/server.xml')
112+
into new File(autoFvtDir, 'lib/LibertyFATTestFiles')
113+
rename 'server.xml', 'validationKeyTestServer1.server.orig.xml'
114+
}
115+
copy {
116+
from new File(projectDir, 'publish/servers/com.ibm.ws.security.token.ltpa.fat.validationKeyTestServer2/server.xml')
117+
into new File(autoFvtDir, 'lib/LibertyFATTestFiles')
118+
rename 'server.xml', 'validationKeyTestServer2.server.orig.xml'
119+
}
108120
copy {
109121
from new File(projectDir, 'publish/files/server.xml')
110122
into new File(autoFvtDir, 'lib/LibertyFATTestFiles')

dev/com.ibm.ws.security.token.ltpa_fat/fat/src/com/ibm/ws/security/token/ltpa/fat/FATSuite.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2020, 2023 IBM Corporation and others.
2+
* Copyright (c) 2020, 2025 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License 2.0
55
* which accompanies this distribution, and is available at
@@ -35,6 +35,7 @@
3535
ContextRootCookiePathTests.class,
3636
FATTest.class,
3737
LTPAKeyRotationTests.class,
38+
LTPAValidationKeyTests.class
3839
})
3940
/**
4041
* Purpose: This suite collects and runs all known good test suites.

0 commit comments

Comments
 (0)