Skip to content

Commit 0c89e6e

Browse files
Special characters in Admin credential and mii encryption credential (#2319)
* Add more special character in password * changed the password format and test for config-map with db password * Add to encryption secret * Add env variable with special character * Added config check for custom env inside domain configuration * Add test for sitconfig and add admin user name 'wlsadmin' instead of standard 'weblogic' Co-authored-by: [email protected] <[email protected]>
1 parent db00391 commit 0c89e6e

File tree

7 files changed

+89
-29
lines changed

7 files changed

+89
-29
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
import static java.util.concurrent.TimeUnit.MINUTES;
2222
import static java.util.concurrent.TimeUnit.SECONDS;
23-
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_PASSWORD_DEFAULT;
24-
import static oracle.weblogic.kubernetes.TestConstants.ADMIN_USERNAME_DEFAULT;
2523
import static oracle.weblogic.kubernetes.TestConstants.DOMAIN_VERSION;
2624
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_NAME;
2725
import static oracle.weblogic.kubernetes.TestConstants.MII_BASIC_IMAGE_TAG;
@@ -53,9 +51,10 @@
5351

5452
/**
5553
* This test class verifies usage of CustomIdentityCustomTrust on PV.
56-
* Create a MII domain with an attached persistent volume.
54+
* Create an MII domain with an attached persistent volume.
5755
* Configure custom identity and custom trust on server template
58-
* Donot set the SSL port on server template. The default will be set to 8100.
56+
* Don't explicitly set the SSL port on the server template.
57+
* The default will be set to 8100.
5958
* Put the IdentityKeyStore.jks and TrustKeyStore.jks on /shared directory
6059
* after administration server pod is started so that it can be accessible
6160
* from all managed server pods
@@ -111,18 +110,20 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
111110
// install and verify operator
112111
installAndVerifyOperator(opNamespace, domainNamespace);
113112

114-
// create secret for admin credentials
113+
// create secret for admin credential with special characters
114+
// the resultant password is ##W%*}!"'"`']\\\\//1$$~x
115+
// let the user name be something other than weblogic say wlsadmin
115116
logger.info("Create secret for admin credentials");
116117
String adminSecretName = "weblogic-credentials";
117118
assertDoesNotThrow(() -> createDomainSecret(adminSecretName,
118-
ADMIN_USERNAME_DEFAULT, ADMIN_PASSWORD_DEFAULT, domainNamespace),
119+
"wlsadmin", "##W%*}!\"'\"`']\\\\//1$$~x", domainNamespace),
119120
String.format("createSecret failed for %s", adminSecretName));
120121

121-
// create encryption secret
122+
// create encryption secret with special characters
122123
logger.info("Create encryption secret");
123124
String encryptionSecretName = "encryptionsecret";
124125
assertDoesNotThrow(() -> createDomainSecret(encryptionSecretName, "weblogicenc",
125-
"weblogicenc", domainNamespace),
126+
"#%*!`${ls}'${DOMAIN_UID}1~3x", domainNamespace),
126127
String.format("createSecret failed for %s", encryptionSecretName));
127128

128129
String configMapName = "mii-ssl-configmap";
@@ -183,7 +184,7 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
183184

184185
/**
185186
* Verify a standalone java client can access JNDI Context inside a pod.
186-
* The client uses t3s cluster URL with custom SSL TrustStore on commandline
187+
* The client uses t3s cluster URL with custom SSL TrustStore on the command line
187188
*/
188189
@Test
189190
@Order(1)

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

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import static oracle.weblogic.kubernetes.actions.TestActions.createDomainCustomResource;
7575
import static oracle.weblogic.kubernetes.actions.TestActions.createSecret;
7676
import static oracle.weblogic.kubernetes.actions.TestActions.execCommand;
77+
import static oracle.weblogic.kubernetes.actions.TestActions.getDomainCustomResource;
7778
import static oracle.weblogic.kubernetes.actions.TestActions.getJob;
7879
import static oracle.weblogic.kubernetes.actions.TestActions.getPodLog;
7980
import static oracle.weblogic.kubernetes.actions.TestActions.getServiceNodePort;
@@ -191,7 +192,7 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
191192
logger.info("Create database secret");
192193
final String dbSecretName = domainUid + "-db-secret";
193194
assertDoesNotThrow(() -> createDatabaseSecret(dbSecretName, "scott",
194-
"tiger", "jdbc:oracle:thin:localhost:/ORCLCDB", domainNamespace),
195+
"##W%*}!\"'\"`']\\\\//1$$~x", "jdbc:oracle:thin:localhost:/ORCLCDB", domainNamespace),
195196
String.format("createSecret failed for %s", dbSecretName));
196197
String configMapName = "jdbc-jms-wldf-configmap";
197198

@@ -248,15 +249,62 @@ public void beforeEach() {
248249
}
249250
}
250251

252+
/**
253+
* Check the environment variable with special characters.
254+
*/
255+
@Test
256+
@Order(0)
257+
@DisplayName("Check environment variable with special characters")
258+
public void testMiiCustomEnv() {
259+
Domain domain1 = assertDoesNotThrow(() -> getDomainCustomResource(domainUid, domainNamespace),
260+
String.format("getDomainCustomResource failed with ApiException when tried to get domain %s in namespace %s",
261+
domainUid, domainNamespace));
262+
List<V1EnvVar> envList = domain1.getSpec().getServerPod().getEnv();
263+
264+
boolean found = false;
265+
for (int i = 0; i < envList.size(); i++) {
266+
logger.info("The name is: {0}, value is: {1}", envList.get(i).getName(), envList.get(i).getValue());
267+
if (envList.get(i).getName().equalsIgnoreCase("CUSTOM_ENV")) {
268+
assertTrue(
269+
envList.get(i).getValue().equalsIgnoreCase("${DOMAIN_UID}~##!'%*$(ls)"),
270+
"Expected value for CUSTOM_ENV variable does not mtach");
271+
found = true;
272+
}
273+
}
274+
assertTrue(found, "Couldn't find CUSTOM_ENV variable in domain resource");
275+
276+
int adminServiceNodePort
277+
= getServiceNodePort(domainNamespace, getExternalServicePodName(adminServerPodName), "default");
278+
StringBuffer curlString = new StringBuffer("curl --user weblogic:welcome1 ");
279+
curlString.append("\"http://" + K8S_NODEPORT_HOST + ":" + adminServiceNodePort)
280+
.append("/management/weblogic/latest/domainConfig")
281+
.append("/JMSServers/TestClusterJmsServer")
282+
.append("?fields=notes&links=none\"")
283+
.append(" --silent ");
284+
logger.info("checkJmsServerConfig: curl command {0}", new String(curlString));
285+
ExecResult result = null;
286+
try {
287+
result = exec(new String(curlString), true);
288+
getLogger().info("The command returned exit value: "
289+
+ result.exitValue() + " command output: "
290+
+ result.stderr() + "\n" + result.stdout());
291+
assertTrue((result.exitValue() == 0),
292+
"curl command returned non zero value");
293+
assertTrue((result.stdout().contains("${DOMAIN_UID}~##!'%*$(ls)")),
294+
"Custom environment variable is not reflected in domin config");
295+
} catch (Exception e) {
296+
getLogger().info("Got exception, command failed with errors " + e.getMessage());
297+
}
298+
}
299+
251300
/**
252301
* Check server logs are written on PersistentVolume(PV).
253-
* The test looks for the string RUNNING in server log
302+
* The test looks for the string RUNNING in the server log
254303
*/
255304
@Test
256305
@Order(1)
257306
@DisplayName("Check the server logs are written to PersistentVolume")
258307
public void testMiiServerLogsAreOnPV() {
259-
260308
// check server logs are written on PV and look for string RUNNING in log
261309
checkLogsOnPV("grep RUNNING /shared/logs/" + adminServerName + ".log", adminServerPodName);
262310
}
@@ -296,12 +344,12 @@ public void testMiiHttpServerLogsAreOnPV() {
296344
}
297345

298346
/**
299-
* Create a WebLogic domain with a defined configmap in configuration/model
300-
* section of the domain resource.
347+
* Create a WebLogic domain with a defined configmap in the
348+
* configuration/model section of the domain resource.
301349
* The configmap has multiple sparse WDT model files that define
302350
* a JDBCSystemResource, a JMSSystemResource and a WLDFSystemResource.
303351
* Verify all the SystemResource configurations using the rest API call
304-
* using the public nodeport of the administration server.
352+
* using the public node port of the administration server.
305353
*/
306354
@Test
307355
@Order(3)
@@ -475,15 +523,15 @@ public void testMiiAddSystemResources() {
475523
* Update the restart version of the domain resource.
476524
* Verify rolling restart of the domain by comparing PodCreationTimestamp
477525
* before and after rolling restart.
478-
* Verify servers from new cluster are not in running state, because
526+
* Verify servers from the new cluster are not in running state, because
479527
* the spec level replica count to zero(default).
480528
*/
481529
@Test
482530
@Order(6)
483531
@DisplayName("Add a dynamic cluster to the domain with default replica count")
484532
public void testMiiAddDynmicClusteriWithNoReplica() {
485533

486-
// This test uses the WebLogic domain created in BeforeAll method
534+
// This test uses the WebLogic domain created in the BeforeAll method
487535
// BeforeEach method ensures that the server pods are running
488536

489537
String configMapName = "noreplicaconfigmap";
@@ -518,8 +566,8 @@ public void testMiiAddDynmicClusteriWithNoReplica() {
518566
assertTrue(verifyRollingRestartOccurred(pods, 1, domainNamespace),
519567
"Rolling restart failed");
520568

521-
// The ServerNamePrefix for the new configured cluster is config-server
522-
// Make sure the managed server from new cluster is not running
569+
// The ServerNamePrefix for the newly configured cluster is config-server
570+
// Make sure the managed server from the new cluster is not running
523571

524572
String newServerPodName = domainUid + "-config-server1";
525573
checkPodNotCreated(newServerPodName, domainUid, domainNamespace);
@@ -536,14 +584,14 @@ public void testMiiAddDynmicClusteriWithNoReplica() {
536584
* Update the restart version of the domain resource.
537585
* Verify rolling restart of the domain by comparing PodCreationTimestamp
538586
* before and after rolling restart.
539-
* Verify servers from new cluster are in running state.
587+
* Verify servers from the new cluster are running.
540588
*/
541589
@Test
542590
@Order(7)
543591
@DisplayName("Add a dynamic cluster to domain with non-zero replica count")
544592
public void testMiiAddDynamicCluster() {
545593

546-
// This test uses the WebLogic domain created in BeforeAll method
594+
// This test uses the WebLogic domain created in the BeforeAll method
547595
// BeforeEach method ensures that the server pods are running
548596

549597
String configMapName = "dynamicclusterconfigmap";
@@ -613,14 +661,14 @@ public void testMiiAddDynamicCluster() {
613661
* Update the restart version of the domain resource.
614662
* Verify rolling restart of the domain by comparing PodCreationTimestamp
615663
* before and after rolling restart.
616-
* Verify servers from new cluster are in running state.
664+
* Verify servers from the new cluster are running.
617665
*/
618666
@Test
619667
@Order(8)
620668
@DisplayName("Add a configured cluster to the domain")
621669
public void testMiiAddConfiguredCluster() {
622670

623-
// This test uses the WebLogic domain created in BeforeAll method
671+
// This test uses the WebLogic domain created in the BeforeAll method
624672
// BeforeEach method ensures that the server pods are running
625673

626674
String configMapName = "configclusterconfigmap";
@@ -681,7 +729,7 @@ public void testMiiAddConfiguredCluster() {
681729
}
682730

683731
/**
684-
* Start a WebLogic domain with model-in-imge.
732+
* Start a WebLogic domain with model-in-image.
685733
* Patch the domain CRD with a new credentials secret.
686734
* Update domainRestartVersion to trigger a rolling restart of server pods.
687735
* Make sure all the server pods are re-started in a rolling fashion.
@@ -749,10 +797,10 @@ public void testMiiUpdateWebLogicCredential() {
749797
* Set allowReplicasBelowMinDynClusterSize to false.
750798
* Make sure that the cluster can be scaled up to 5 servers and
751799
* scaled down to 1 server.
752-
* Create a configmap with a sparse model file with following attributes for
800+
* Create a configmap with a sparse model file with the following attributes
753801
* Cluster/cluster-1/DynamicServers
754802
* MaxDynamicClusterSize(4) and MinDynamicClusterSize(2)
755-
* Patch the domain resource with the configmap and update restartVersion.
803+
* Patch the domain resource with the configmap and update the restartVersion.
756804
* Make sure a rolling restart is triggered.
757805
* Now with the modified value
758806
* Make sure that the cluster can be scaled up to 4 servers.
@@ -970,6 +1018,8 @@ private static void createDomainSecret(String secretName, String username, Strin
9701018
assertTrue(secretCreated, String.format("create secret failed for %s in namespace %s", secretName, domNamespace));
9711019
}
9721020

1021+
// Add an environmental variable with special character
1022+
// Make sure the variable is available in domain resource with right value
9731023
private static void createDomainResource(
9741024
String domainUid, String domNamespace, String adminSecretName,
9751025
String repoSecretName, String encryptionSecretName,
@@ -1004,6 +1054,9 @@ private static void createDomainResource(
10041054
.addEnvItem(new V1EnvVar()
10051055
.name("USER_MEM_ARGS")
10061056
.value("-Djava.security.egd=file:/dev/./urandom "))
1057+
.addEnvItem(new V1EnvVar()
1058+
.name("CUSTOM_ENV")
1059+
.value("${DOMAIN_UID}~##!'%*$(ls)"))
10071060
.addVolumesItem(new V1Volume()
10081061
.name(pvName)
10091062
.persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource()

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private void verifyJMSResourceOverride() {
241241
assertEquals(200, response.statusCode(), "Status code not equals to 200");
242242
assertTrue(response.body().contains("ExpirationPolicy:Discard"), "Didn't get ExpirationPolicy:Discard");
243243
assertTrue(response.body().contains("RedeliveryLimit:20"), "Didn't get RedeliveryLimit:20");
244+
assertTrue(response.body().contains("Notes:mysitconfigdomain"), "Didn't get Correct Notes description");
244245
}
245246

246247
private void verifyWLDFResourceOverride() {
@@ -373,6 +374,9 @@ private void createDomain() {
373374
.addEnvItem(new V1EnvVar()
374375
.name("USER_MEM_ARGS")
375376
.value("-Djava.security.egd=file:/dev/./urandom "))
377+
.addEnvItem(new V1EnvVar()
378+
.name("CUSTOM_ENV")
379+
.value("##~`!^${ls}"))
376380
.addVolumesItem(new V1Volume()
377381
.name(pvName)
378382
.persistentVolumeClaim(new V1PersistentVolumeClaimVolumeSource()

integration-tests/src/test/resources/apps/sitconfig/src/java/oracle/weblogic/kubernetes/applications/sitconfig/SitconfigServlet.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ public void testSystemResourcesJmsAttributeChange(PrintWriter out) {
110110

111111
out.println("ExpirationPolicy:" + uniformDistributedTopic.getDeliveryFailureParams().getExpirationPolicy());
112112
out.println("RedeliveryLimit:" + uniformDistributedTopic.getDeliveryFailureParams().getRedeliveryLimit());
113+
out.println("Notes:" + uniformDistributedTopic.getNotes());
113114
}
114115

115116
/**

integration-tests/src/test/resources/configfiles/configoverridesset2/jms-ClusterJmsSystemResource.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xmlns:fr="http://xmlns.oracle.com/weblogic/weblogic-jms-fragment"
55
xmlns:s="http://xmlns.oracle.com/weblogic/situational-config" >
66
<jms:uniform-distributed-topic name="UniformReplicatedTestTopic">
7-
<jms:notes fr:combine-mode="add">JMS System Resource UniformReplicatedTestTopic testSystemResourcesJMSAttributeChange</jms:notes>
7+
<jms:notes fr:combine-mode="add">${env:DOMAIN_UID}</jms:notes>
88
<jms:delivery-failure-params>
99
<jms:redelivery-limit fr:combine-mode="replace">20</jms:redelivery-limit>
1010
<jms:expiration-policy fr:combine-mode="replace">Discard</jms:expiration-policy>

integration-tests/src/test/resources/ssl/SslTestClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private Context getInitialContext()
3636

3737
props.put("java.naming.factory.initial",
3838
"weblogic.jndi.WLInitialContextFactory" );
39-
props.put("java.naming.security.principal","weblogic");
40-
props.put("java.naming.security.credentials","welcome1");
39+
props.put("java.naming.security.principal","wlsadmin");
40+
props.put("java.naming.security.credentials","##W%*}!\"'\"`']\\\\//1$$~x");
4141
try {
4242
jndiContext = new InitialContext(props);
4343
} catch (Exception e) {

integration-tests/src/test/resources/wdt-models/model.sysresources.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ resources:
1212
PersistentStore: 'TestClusterFileStore'
1313
InsertionPausedAtStartup: false
1414
MessageCompressionOptions: GZIP_DEFAULT_COMPRESSION
15+
Notes: '@@ENV:CUSTOM_ENV@@'
1516

1617
JMSSystemResource:
1718
TestClusterJmsModule:

0 commit comments

Comments
 (0)