You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2021/08/18 09:36:32 UTC

[GitHub] [camel-k] astefanutti commented on a change in pull request #2577: trait: Add tests for route trait and read certificate from secrets

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



##########
File path: e2e/common/traits/route_test.go
##########
@@ -0,0 +1,124 @@
+// +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/tls"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"testing"
+	"time"
+
+	. "github.com/onsi/gomega"
+	"github.com/stretchr/testify/assert"
+
+	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 = "my-combined-tls"
+	keyName = "my-key"
+	certName = "my-cert"
+	keyFilePath = "files/key.key"
+	certFilePath = "files/crt.crt"
+)
+
+func TestRunRouteTLS(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)
+
+		createSecrets(ns)
+
+		refKey := secretName + "/" + keyName
+		refCert := secretName + "/" + certName
+		Expect(Kamel("install", "-n", ns).Execute()).To(Succeed())
+		Expect(Kamel("run", "-n", ns, "files/NettyServer.java",
+			"-t", "route.enabled=true",
+			"-t", "route.tls-termination=edge",
+			"-t", "route.tls-certificate-secret=" + refCert,
+			"-t", "route.tls-key-secret=" + refKey,
+		).Execute()).To(Succeed())
+		Eventually(IntegrationPodPhase(ns, "netty-server"), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+
+		t.Run("Route https works", func(t *testing.T) {
+			route := Route(ns, "netty-server")
+			Eventually(route, TestTimeoutMedium).ShouldNot(BeNil())
+			// must wait a little time after route is created, before an http request
+			time.Sleep(3 * time.Second)
+			response := httpsRequest(t, fmt.Sprintf("https://%s/hello", route().Spec.Host))
+			assert.Equal(t, "Hello World", response)
+		})
+		// Cleanup
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil())
+	// })
+	})
+}
+
+func httpsRequest(t *testing.T, url string) string {
+	transCfg := &http.Transport{
+		// ignore self signed SSL certificates
+		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},

Review comment:
       It would be better to use the CA that signed the certificate.

##########
File path: e2e/common/traits/route_test.go
##########
@@ -0,0 +1,124 @@
+// +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/tls"
+	"fmt"
+	"io/ioutil"
+	"net/http"
+	"testing"
+	"time"
+
+	. "github.com/onsi/gomega"
+	"github.com/stretchr/testify/assert"
+
+	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 = "my-combined-tls"
+	keyName = "my-key"
+	certName = "my-cert"
+	keyFilePath = "files/key.key"

Review comment:
       To improve readability and maintainability, it'd be better to have those filles code-generated. You can find an example at https://github.com/apache/camel-k/blob/69f0a4bc95f4f1efa6458d241fbc503cb979a7b0/e2e/common/build/maven_ca_secret_test.go.




-- 
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-unsubscribe@camel.apache.org

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