1
- // Copyright (c) 2020, 2022 , Oracle and/or its affiliates.
1
+ // Copyright (c) 2020, 2023 , Oracle and/or its affiliates.
2
2
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
4
4
package oracle .weblogic .kubernetes ;
26
26
import oracle .weblogic .kubernetes .annotations .IntegrationTest ;
27
27
import oracle .weblogic .kubernetes .annotations .Namespaces ;
28
28
import oracle .weblogic .kubernetes .logging .LoggingFacade ;
29
+ import oracle .weblogic .kubernetes .utils .ExecCommand ;
29
30
import oracle .weblogic .kubernetes .utils .ExecResult ;
30
31
import org .junit .jupiter .api .BeforeAll ;
31
32
import org .junit .jupiter .api .DisplayName ;
37
38
import static oracle .weblogic .kubernetes .TestConstants .DOMAIN_API_VERSION ;
38
39
import static oracle .weblogic .kubernetes .TestConstants .IMAGE_PULL_POLICY ;
39
40
import static oracle .weblogic .kubernetes .TestConstants .K8S_NODEPORT_HOST ;
41
+ import static oracle .weblogic .kubernetes .TestConstants .KUBERNETES_CLI ;
40
42
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_NAME ;
41
43
import static oracle .weblogic .kubernetes .TestConstants .MII_BASIC_IMAGE_TAG ;
42
44
import static oracle .weblogic .kubernetes .TestConstants .TEST_IMAGES_REPO_SECRET_NAME ;
43
45
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_IMAGE_TAG ;
44
46
import static oracle .weblogic .kubernetes .TestConstants .WEBLOGIC_SLIM ;
45
47
import static oracle .weblogic .kubernetes .actions .ActionConstants .MODEL_DIR ;
46
48
import static oracle .weblogic .kubernetes .actions .ActionConstants .RESOURCE_DIR ;
49
+ import static oracle .weblogic .kubernetes .actions .ActionConstants .WORK_DIR ;
47
50
import static oracle .weblogic .kubernetes .actions .TestActions .addLabelsToNamespace ;
48
51
import static oracle .weblogic .kubernetes .actions .TestActions .patchDomainResourceWithNewIntrospectVersion ;
49
52
import static oracle .weblogic .kubernetes .utils .ApplicationUtils .checkAppUsingHostHeader ;
62
65
import static oracle .weblogic .kubernetes .utils .DomainUtils .createDomainAndVerify ;
63
66
import static oracle .weblogic .kubernetes .utils .ExecCommand .exec ;
64
67
import static oracle .weblogic .kubernetes .utils .FileUtils .generateFileFromTemplate ;
68
+ import static oracle .weblogic .kubernetes .utils .FileUtils .replaceStringInFile ;
65
69
import static oracle .weblogic .kubernetes .utils .ImageUtils .createTestRepoSecret ;
66
70
import static oracle .weblogic .kubernetes .utils .IstioUtils .createAdminServer ;
67
71
import static oracle .weblogic .kubernetes .utils .IstioUtils .deployHttpIstioGatewayAndVirtualservice ;
72
76
import static oracle .weblogic .kubernetes .utils .PodUtils .setPodAntiAffinity ;
73
77
import static oracle .weblogic .kubernetes .utils .SecretUtils .createSecretWithUsernamePassword ;
74
78
import static oracle .weblogic .kubernetes .utils .ThreadSafeLogger .getLogger ;
79
+ import static org .apache .commons .io .FileUtils .copyFile ;
75
80
import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
76
81
import static org .junit .jupiter .api .Assertions .assertEquals ;
77
82
import static org .junit .jupiter .api .Assertions .assertNotNull ;
@@ -126,6 +131,8 @@ public static void initAll(@Namespaces(2) List<String> namespaces) {
126
131
127
132
// install and verify operator
128
133
installAndVerifyOperator (opNamespace , domainNamespace );
134
+
135
+ enableStrictMode (domainNamespace );
129
136
}
130
137
131
138
/**
@@ -237,6 +244,17 @@ void testIstioModelInImageDomain() {
237
244
238
245
int istioIngressPort = getIstioHttpIngressPort ();
239
246
logger .info ("Istio Ingress Port is {0}" , istioIngressPort );
247
+
248
+ String curlCmd = "curl -j -sk --show-error --noproxy '*' "
249
+ + " -H 'Host: " + domainNamespace + ".org'"
250
+ + " --url http://" + K8S_NODEPORT_HOST + ":" + istioIngressPort + "/console/login/LoginForm.jsp" ;
251
+ ExecResult result = null ;
252
+ logger .info ("curl command {0}" , curlCmd );
253
+ result = assertDoesNotThrow (() -> exec (curlCmd , true ));
254
+ assertEquals (0 , result .exitValue (), "Got expected exit value" );
255
+ result = assertDoesNotThrow (() -> ExecCommand .exec (KUBERNETES_CLI + " delete -f "
256
+ + Paths .get (WORK_DIR , "istio-tls-mode.yaml" ).toString (), true ));
257
+ assertEquals (0 , result .exitValue (), "Got expected exit value" );
240
258
241
259
// We can not verify Rest Management console thru Adminstration NodePort
242
260
// in istio, as we can not enable Adminstration NodePort
@@ -254,7 +272,7 @@ void testIstioModelInImageDomain() {
254
272
+ "/management/weblogic/latest/domainRuntime/domainSecurityRuntime?"
255
273
+ "link=none" ;
256
274
257
- ExecResult result = null ;
275
+ result = null ;
258
276
logger .info ("curl command {0}" , curlCmd2 );
259
277
result = assertDoesNotThrow (
260
278
() -> exec (curlCmd2 , true ));
@@ -274,7 +292,7 @@ void testIstioModelInImageDomain() {
274
292
}
275
293
276
294
Path archivePath = Paths .get (testWebAppWarLoc );
277
- ExecResult result = null ;
295
+ result = null ;
278
296
result = deployToClusterUsingRest (K8S_NODEPORT_HOST ,
279
297
String .valueOf (istioIngressPort ),
280
298
ADMIN_USERNAME_DEFAULT , ADMIN_PASSWORD_DEFAULT ,
@@ -364,4 +382,19 @@ private DomainResource createDomainResource(String domainUid, String domNamespac
364
382
setPodAntiAffinity (domain );
365
383
return domain ;
366
384
}
385
+
386
+ private static void enableStrictMode (String namespace ) {
387
+ assertDoesNotThrow (() -> {
388
+ copyFile (Paths .get (RESOURCE_DIR , "istio" , "istio-tls-mode.yaml" ).toFile (),
389
+ Paths .get (WORK_DIR , "istio-tls-mode.yaml" ).toFile ());
390
+ });
391
+ assertDoesNotThrow (() -> {
392
+ replaceStringInFile (Paths .get (WORK_DIR , "istio-tls-mode.yaml" ).toString (),
393
+ "NAMESPACE" , namespace );
394
+ });
395
+ ExecResult result = assertDoesNotThrow (() -> ExecCommand .exec (KUBERNETES_CLI + " apply -f "
396
+ + Paths .get (WORK_DIR , "istio-tls-mode.yaml" ).toString (), true ));
397
+ logger .info (result .stdout ());
398
+ logger .info (result .stderr ());
399
+ }
367
400
}
0 commit comments