astefanutti commented on a change in pull request #2577:
URL: https://github.com/apache/camel-k/pull/2577#discussion_r701710732



##########
File path: e2e/common/traits/route_test.go
##########
@@ -0,0 +1,382 @@
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> 
Vendoring & Build Tags -> Custom Tags" and add "knative"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package traits
+
+import (
+       "bytes"
+       "crypto/rand"
+       "crypto/rsa"
+       "crypto/tls"
+       "crypto/x509"
+       "crypto/x509/pkix"
+       "encoding/pem"
+       "fmt"
+       "math/big"
+       "net/http"
+       "testing"
+       "time"
+
+       . "github.com/onsi/gomega"
+       "github.com/stretchr/testify/assert"
+
+       rand2 "math/rand"
+
+       corev1 "k8s.io/api/core/v1"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+
+       . "github.com/apache/camel-k/e2e/support"
+       "github.com/apache/camel-k/pkg/util/openshift"
+)
+
+const(
+       secretName = "test-certificate"
+       servingCertificateSecret = "serving-certificate"
+       integrationName = "platform-http-server"
+       waitBeforeHttpRequest = 6 * time.Second
+)
+
+type keyCertificatePair struct {
+       Key []byte
+       Certificate []byte
+}
+
+// self-signed certificate used when making the https request
+var certPem []byte
+
+// the e2e tests run on openshift3 in CI and there is no object to retrieve 
the base domain name
+// to create a valid hostname to later have it validate when doing the https 
request
+// as this a e2e test to validate the route object and not the certificate 
itself 
+// if the base domain name cannot be retrieved from dns/cluster we can safely 
skip TLS verification
+// if running on openshift4, there is the dns/cluster object to retrieve the 
base domain name, 
+// then in this case the http client validates the TLS certificate
+var skipClientTLSVerification = false
+
+func TestRunRoutes(t *testing.T) {
+       WithNewTestNamespace(t, func(ns string) {
+               ocp, err := openshift.IsOpenShift(TestClient())
+               if !ocp {
+                       t.Skip("This test requires route object which is 
available on OpenShift only.")
+                       return
+               }
+               assert.Nil(t, err)
+
+               Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+
+               // create a test secret of type tls with certificates
+               // this secret is used to setupt the route TLS object across 
diferent tests
+               secret, err := createSecret(ns)
+               assert.Nil(t, err)
+
+               // they refer to the certificates create in the secret and are 
reused the different tests
+               refKey := secretName + "/" + corev1.TLSPrivateKeyKey
+               refCert := secretName + "/" + corev1.TLSCertKey
+
+               // =============================
+               // Insecure Route / No TLS
+               // =============================
+               t.Run("Route unsecure http works", func(t *testing.T) {
+                       Expect(Kamel("run", "-n", ns, 
"files/PlatformHttpServer.java").Execute()).To(Succeed())
+                       Eventually(IntegrationPodPhase(ns, integrationName), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+                       route := Route(ns, integrationName)
+                       Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+                       // must wait a little time after route is created, 
before doing an http request, 
+                       // otherwise the route is unavailable and the http 
request will fail
+                       time.Sleep(waitBeforeHttpRequest)
+                       url := fmt.Sprintf("http://%s/hello?name=Simple";, 
route().Spec.Host)
+                       response, err := httpRequest(t, url, false)
+                       assert.Nil(t, err)
+                       assert.Equal(t, "Hello Simple", response)
+                       Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).Should(BeNil())
+               })
+
+               // =============================
+               // TLS Route Edge
+               // =============================
+
+               t.Run("Route Edge https works", func(t *testing.T) {
+                       Expect(Kamel("run", "-n", ns, 
"files/PlatformHttpServer.java",
+                               "-t", "route.tls-termination=edge",
+                               "-t", "route.tls-certificate-secret=" + refCert,
+                               "-t", "route.tls-key-secret=" + refKey,
+                       ).Execute()).To(Succeed())
+                       Eventually(IntegrationPodPhase(ns, integrationName), 
TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+                       route := Route(ns, integrationName)
+                       Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+                       // must wait a little time after route is created, 
before an http request, 
+                       // otherwise the route is unavailable and the http 
request will fail
+                       time.Sleep(waitBeforeHttpRequest)
+                       url := fmt.Sprintf("https://%s/hello?name=TLS_Edge";, 
route().Spec.Host)
+                       response, err := httpRequest(t, url, true)
+                       assert.Nil(t, err)
+                       assert.Equal(t, "Hello TLS_Edge", response)
+                       Expect(Kamel("delete", "--all", "-n", 
ns).Execute()).Should(BeNil())
+               })
+
+               // =============================
+               // TLS Route Passthrough
+               // =============================
+
+               t.Run("Route passthrough https works", func(t *testing.T) {
+                       Expect(Kamel("run", "-n", ns, 
"files/PlatformHttpServer.java",
+                               // the --resource mounts the certificates 
inside secret as files in the integration pod
+                               "--resource", "secret:" + secretName + 
"@/etc/ssl/" + secretName,
+                               // quarkus platform-http uses these two 
properties to setup the HTTP endpoint with TLS support
+                               "-p", 
"quarkus.http.ssl.certificate.file=/etc/ssl/" + secretName + "/tls.crt",
+                               "-p", 
"quarkus.http.ssl.certificate.key-file=/etc/ssl/" + secretName + "/tls.key",
+                               "-t", "route.tls-termination=passthrough",

Review comment:
       Can't this be automated by the route trait? The user could be able to 
provide the secret name and the termination type.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to