You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gf...@apache.org on 2024/06/11 08:42:19 UTC
(camel-k) branch release-2.3.x updated (1a80acfa3 -> 99679d761)
This is an automated email from the ASF dual-hosted git repository.
gfournier pushed a change to branch release-2.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
from 1a80acfa3 chore: nightly automatic updates
new 5965c3979 test: Add Unit test for maven proxy settings
new 99679d761 test(e2e): Add check on env vars for pod
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
e2e/advanced/maven_http_proxy_test.go | 17 +++
pkg/util/maven/maven_proxies_test.go | 246 ++++++++++++++++++++++++++++++++++
2 files changed, 263 insertions(+)
create mode 100644 pkg/util/maven/maven_proxies_test.go
(camel-k) 01/02: test: Add Unit test for maven proxy settings
Posted by gf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gfournier pushed a commit to branch release-2.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 5965c3979550c80a1b452049f908e2a8f0ecaf50
Author: Gaelle Fournier <ga...@gmail.com>
AuthorDate: Wed Jun 5 13:04:29 2024 +0200
test: Add Unit test for maven proxy settings
---
pkg/util/maven/maven_proxies_test.go | 246 +++++++++++++++++++++++++++++++++++
1 file changed, 246 insertions(+)
diff --git a/pkg/util/maven/maven_proxies_test.go b/pkg/util/maven/maven_proxies_test.go
new file mode 100644
index 000000000..f7fc4ad67
--- /dev/null
+++ b/pkg/util/maven/maven_proxies_test.go
@@ -0,0 +1,246 @@
+/*
+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 maven
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestProxyHTTPEnvVar(t *testing.T) {
+
+ testcases := []struct {
+ name string
+ proxyHTTPEnvVar string
+ proxyHostResult string
+ proxyPortResult string
+ proxyProtocolResult string
+ proxyUsernameResult string
+ proxyPasswordResult string
+ }{
+ {
+ name: "HTTP_PROXY_Port",
+ proxyHTTPEnvVar: "http://proxy.namespace.svc:8080",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "8080",
+ proxyProtocolResult: "http",
+ proxyUsernameResult: "",
+ proxyPasswordResult: "",
+ },
+ {
+ name: "HTTP_PROXY_No_Port",
+ proxyHTTPEnvVar: "http://proxy.namespace.svc",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "80",
+ proxyProtocolResult: "http",
+ proxyUsernameResult: "",
+ proxyPasswordResult: "",
+ },
+ {
+ name: "HTTP_PROXY_full",
+ proxyHTTPEnvVar: "http://user:password@proxy.namespace.svc:8081",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "8081",
+ proxyProtocolResult: "http",
+ proxyUsernameResult: "user",
+ proxyPasswordResult: "password",
+ },
+ }
+
+ for _, tc := range testcases {
+ t.Run(tc.name, func(t *testing.T) {
+ settings, err := NewSettings(DefaultRepositories, ProxyFromEnvironment)
+ require.NoError(t, err)
+
+ t.Setenv("HTTP_PROXY", tc.proxyHTTPEnvVar)
+ err = ProxyFromEnvironment.apply(&settings)
+
+ require.NoError(t, err)
+ assert.Equal(t, "http-proxy", settings.Proxies[0].ID)
+ assert.Equal(t, true, settings.Proxies[0].Active)
+ assert.Equal(t, tc.proxyHostResult, settings.Proxies[0].Host)
+ assert.Equal(t, tc.proxyPortResult, settings.Proxies[0].Port)
+ assert.Equal(t, tc.proxyProtocolResult, settings.Proxies[0].Protocol)
+ assert.Equal(t, tc.proxyUsernameResult, settings.Proxies[0].Username)
+ assert.Equal(t, tc.proxyPasswordResult, settings.Proxies[0].Password)
+ })
+ }
+}
+
+func TestProxyHTTPSEnvVar(t *testing.T) {
+
+ testcases := []struct {
+ name string
+ proxyHTTPSEnvVar string
+ proxyHostResult string
+ proxyPortResult string
+ proxyProtocolResult string
+ proxyUsernameResult string
+ proxyPasswordResult string
+ }{
+ {
+ name: "HTTPS_PROXY_Port",
+ proxyHTTPSEnvVar: "https://proxy.namespace.svc:8443",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "8443",
+ proxyProtocolResult: "https",
+ proxyUsernameResult: "",
+ proxyPasswordResult: "",
+ },
+ {
+ name: "HTTPS_PROXY_No_Port",
+ proxyHTTPSEnvVar: "https://proxy.namespace.svc",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "443",
+ proxyProtocolResult: "https",
+ proxyUsernameResult: "",
+ proxyPasswordResult: "",
+ },
+ {
+ name: "HTTP_PROXY_full",
+ proxyHTTPSEnvVar: "https://user:password@proxy.namespace.svc:8444",
+ proxyHostResult: "proxy.namespace.svc",
+ proxyPortResult: "8444",
+ proxyProtocolResult: "https",
+ proxyUsernameResult: "user",
+ proxyPasswordResult: "password",
+ },
+ }
+
+ for _, tc := range testcases {
+ t.Run(tc.name, func(t *testing.T) {
+ settings, err := NewSettings(DefaultRepositories, ProxyFromEnvironment)
+ require.NoError(t, err)
+
+ t.Setenv("HTTPS_PROXY", tc.proxyHTTPSEnvVar)
+ err = ProxyFromEnvironment.apply(&settings)
+
+ require.NoError(t, err)
+ assert.Equal(t, "https-proxy", settings.Proxies[0].ID)
+ assert.Equal(t, true, settings.Proxies[0].Active)
+ assert.Equal(t, tc.proxyHostResult, settings.Proxies[0].Host)
+ assert.Equal(t, tc.proxyPortResult, settings.Proxies[0].Port)
+ assert.Equal(t, tc.proxyProtocolResult, settings.Proxies[0].Protocol)
+ assert.Equal(t, tc.proxyUsernameResult, settings.Proxies[0].Username)
+ assert.Equal(t, tc.proxyPasswordResult, settings.Proxies[0].Password)
+ })
+ }
+}
+
+func TestNoPROXYEnvVar(t *testing.T) {
+ testcases := []struct {
+ name string
+ proxyHTTPEnvVar string
+ proxyHTTPSEnvVar string
+ noPROXYEnvVar string
+ noProxyResult string
+ }{
+ {
+ name: "Valid_NOPROXY_simple",
+ proxyHTTPEnvVar: "http://www.proxy.com",
+ proxyHTTPSEnvVar: "",
+ noPROXYEnvVar: "www.no.proxy.com",
+ noProxyResult: "www.no.proxy.com",
+ },
+ {
+ name: "Valid_NOPROXY_IPS",
+ proxyHTTPEnvVar: "http://www.proxy.com",
+ proxyHTTPSEnvVar: "",
+ noPROXYEnvVar: "10.96.0.1,10.96.0.4",
+ noProxyResult: "10.96.0.1|10.96.0.4",
+ },
+ {
+ name: "Valid_NOPROXY_Complexe",
+ proxyHTTPEnvVar: "",
+ proxyHTTPSEnvVar: "https://www.proxy.com",
+ noPROXYEnvVar: "localhost, 127.0.0.1, *.local, .my-co.com",
+ noProxyResult: "localhost|127.0.0.1|*.local|*.my-co.com",
+ },
+ }
+
+ for _, tc := range testcases {
+ t.Run(tc.name, func(t *testing.T) {
+ settings, err := NewSettings(DefaultRepositories, ProxyFromEnvironment)
+ require.NoError(t, err)
+
+ if tc.proxyHTTPEnvVar != "" {
+ t.Setenv("HTTP_PROXY", tc.proxyHTTPEnvVar)
+ }
+
+ if tc.proxyHTTPSEnvVar != "" {
+ t.Setenv("HTTPS_PROXY", tc.proxyHTTPSEnvVar)
+ }
+
+ t.Setenv("NO_PROXY", tc.noPROXYEnvVar)
+
+ err = ProxyFromEnvironment.apply(&settings)
+
+ require.NoError(t, err)
+ assert.Equal(t, true, settings.Proxies[0].Active)
+ assert.Equal(t, tc.noProxyResult, settings.Proxies[0].NonProxyHosts)
+ })
+ }
+}
+
+func TestAllProxyEnvVar(t *testing.T) {
+ t.Run("All proxy env vars", func(t *testing.T) {
+
+ settings, err := NewSettings(DefaultRepositories, ProxyFromEnvironment)
+ require.NoError(t, err)
+
+ t.Setenv("HTTP_PROXY", "http://www.unsercure-proxy.com")
+ t.Setenv("HTTPS_PROXY", "https://www.sercure-proxy.com")
+ t.Setenv("NO_PROXY", "localhost, 10.96.0.1, *.local")
+
+ err = ProxyFromEnvironment.apply(&settings)
+
+ require.NoError(t, err)
+ assert.Equal(t, 2, len(settings.Proxies))
+ assert.Equal(t, "http-proxy", settings.Proxies[0].ID)
+ assert.Equal(t, "https-proxy", settings.Proxies[1].ID)
+ assert.Equal(t, "localhost|10.96.0.1|*.local", settings.Proxies[0].NonProxyHosts)
+ assert.Equal(t, "localhost|10.96.0.1|*.local", settings.Proxies[1].NonProxyHosts)
+ })
+}
+
+func TestAddAnotherProxyEnvVar(t *testing.T) {
+ t.Run("Add a proxy from env vars", func(t *testing.T) {
+
+ settings, err := NewSettings(DefaultRepositories, ProxyFromEnvironment)
+ require.NoError(t, err)
+
+ settings.Proxies = append(settings.Proxies, Proxy{
+ ID: "other",
+ Active: false,
+ Protocol: "http",
+ Host: "otherproxy.com",
+ Port: "8088",
+ })
+
+ t.Setenv("HTTP_PROXY", "http://www.unsercure-proxy.com")
+
+ err = ProxyFromEnvironment.apply(&settings)
+
+ require.NoError(t, err)
+ assert.Equal(t, 2, len(settings.Proxies))
+ assert.Equal(t, "other", settings.Proxies[0].ID)
+ assert.Equal(t, "http-proxy", settings.Proxies[1].ID)
+ })
+}
(camel-k) 02/02: test(e2e): Add check on env vars for pod
Posted by gf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
gfournier pushed a commit to branch release-2.3.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 99679d761b5f179a8b4a21e1d5c14e02e107d7ff
Author: Gaelle Fournier <ga...@gmail.com>
AuthorDate: Wed Jun 5 15:59:06 2024 +0200
test(e2e): Add check on env vars for pod
---
e2e/advanced/maven_http_proxy_test.go | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/e2e/advanced/maven_http_proxy_test.go b/e2e/advanced/maven_http_proxy_test.go
index 965118f62..551934a93 100644
--- a/e2e/advanced/maven_http_proxy_test.go
+++ b/e2e/advanced/maven_http_proxy_test.go
@@ -37,6 +37,7 @@ import (
"time"
"github.com/apache/camel-k/v2/pkg/util"
+ "github.com/apache/camel-k/v2/pkg/util/envvar"
"github.com/apache/camel-k/v2/pkg/util/kubernetes"
"github.com/apache/camel-k/v2/pkg/util/olm"
@@ -187,6 +188,22 @@ func TestMavenProxy(t *testing.T) {
g.Eventually(PlatformPhase(t, ctx, ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+ // Check that operator pod has env_vars
+ g.Eventually(OperatorPodHas(t, ctx, ns, func(op *corev1.Pod) bool {
+ if envVar := envvar.Get(op.Spec.Containers[0].Env, "HTTP_PROXY"); envVar != nil {
+ return envVar.Value == fmt.Sprintf("http://%s", hostname)
+ }
+ return false
+
+ }), TestTimeoutShort).Should(BeTrue())
+ g.Eventually(OperatorPodHas(t, ctx, ns, func(op *corev1.Pod) bool {
+ if envVar := envvar.Get(op.Spec.Containers[0].Env, "NO_PROXY"); envVar != nil {
+ return envVar.Value == strings.Join(noProxy, ",")
+ }
+ return false
+
+ }), TestTimeoutShort).Should(BeTrue())
+
// Run the Integration
name := RandomizedSuffixName("java")
g.Expect(KamelRunWithID(t, ctx, operatorID, ns, "files/Java.java", "--name", name).Execute()).To(Succeed())