-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove logic behind --disable-compression but keep it to avoid breakage
We decided to entirely remove the logic behind --disable-compression because the validation logic was looking super weird; we don't think folks should be using --disable-compression=false anyways. If we want to re-introduce a similar flag later on, we can create a new, for example --no-compression.
- Loading branch information
Showing
5 changed files
with
46 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package agent | ||
|
||
import ( | ||
"bytes" | ||
"compress/gzip" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"testing" | ||
|
@@ -165,6 +162,25 @@ func Test_ValidateAndCombineConfig(t *testing.T) { | |
assert.Equal(t, true, got.StrictMode) | ||
}) | ||
|
||
t.Run("--disable-compression is deprecated and doesn't do anything", func(t *testing.T) { | ||
path := withFile(t, `{"user_id":"[email protected]","user_secret":"foo","client_id": "k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo","client_secret": "f39w_3KT9Vp0VhzcPzvh-uVbudzqCFmHER3Huj0dvHgJwVrjxsoOQPIw_1SDiCfa","auth_server_domain":"auth.jetstack.io"}`) | ||
log, b := recordLogs(t) | ||
_, _, err := ValidateAndCombineConfig(log, | ||
withConfig(testutil.Undent(` | ||
server: https://api.venafi.eu | ||
period: 1h | ||
organization_id: foo | ||
cluster_id: bar | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--credentials-file", path, "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
assert.Equal(t, testutil.Undent(` | ||
INFO Using the Jetstack Secure OAuth auth mode since --credentials-file was specified without --venafi-cloud. | ||
INFO Using period from config period="1h0m0s" | ||
INFO The flag --disable-compression has been deprecated an no longer has any effect. | ||
`), b.String()) | ||
}) | ||
|
||
t.Run("error when no auth method specified", func(t *testing.T) { | ||
_, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
|
@@ -375,19 +391,6 @@ func Test_ValidateAndCombineConfig(t *testing.T) { | |
assert.IsType(t, &client.OAuthClient{}, cl) | ||
}) | ||
|
||
t.Run("jetstack-secure-oauth-auth: can't use --disable-compression", func(t *testing.T) { | ||
path := withFile(t, `{"user_id":"[email protected]","user_secret":"foo","client_id": "k3TrDbfLhCgnpAbOiiT2kIE1AbovKzjo","client_secret": "f39w_3KT9Vp0VhzcPzvh-uVbudzqCFmHER3Huj0dvHgJwVrjxsoOQPIw_1SDiCfa","auth_server_domain":"auth.jetstack.io"}`) | ||
_, _, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: https://api.venafi.eu | ||
period: 1h | ||
organization_id: foo | ||
cluster_id: bar | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--credentials-file", path, "--install-namespace", "venafi")) | ||
require.EqualError(t, err, "1 error occurred:\n\t* --disable-compression can only be used with the Venafi Cloud Key Pair Service Account and Venafi Cloud VenafiConnection modes\n\n") | ||
}) | ||
|
||
t.Run("jetstack-secure-oauth-auth: --credential-file used but file is missing", func(t *testing.T) { | ||
t.Setenv("POD_NAMESPACE", "venafi") | ||
got, _, err := ValidateAndCombineConfig(discardLogs(), | ||
|
@@ -647,83 +650,6 @@ func Test_ValidateAndCombineConfig_VenafiCloudKeyPair(t *testing.T) { | |
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("the request body is compressed", func(t *testing.T) { | ||
srv, cert, setVenafiCloudAssert := testutil.FakeVenafiCloud(t) | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
if gotReq.URL.Path == "/v1/oauth/token/serviceaccount" { | ||
return | ||
} | ||
assert.Equal(t, "/v1/tlspk/upload/clusterdata/no", gotReq.URL.Path) | ||
|
||
// Let's check that the body is compressed as expected. | ||
assert.Equal(t, "gzip", gotReq.Header.Get("Content-Encoding")) | ||
uncompressR, err := gzip.NewReader(gotReq.Body) | ||
require.NoError(t, err, "body might not be compressed") | ||
defer uncompressR.Close() | ||
uncompressed, err := io.ReadAll(uncompressR) | ||
require.NoError(t, err) | ||
assert.Contains(t, string(uncompressed), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
privKeyPath := withFile(t, fakePrivKeyPEM) | ||
got, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: "test cluster name" | ||
venafi-cloud: | ||
uploader_id: no | ||
upload_path: /v1/tlspk/upload/clusterdata | ||
`)), | ||
withCmdLineFlags("--client-id", "5bc7d07c-45da-11ef-a878-523f1e1d7de1", "--private-key-path", privKeyPath, "--install-namespace", "venafi"), | ||
) | ||
require.NoError(t, err) | ||
testutil.TrustCA(t, cl, cert) | ||
assert.Equal(t, VenafiCloudKeypair, got.AuthMode) | ||
require.NoError(t, err) | ||
|
||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("--disable-compression works", func(t *testing.T) { | ||
srv, cert, setVenafiCloudAssert := testutil.FakeVenafiCloud(t) | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Only care about /v1/tlspk/upload/clusterdata/:uploader_id?name= | ||
if gotReq.URL.Path == "/v1/oauth/token/serviceaccount" { | ||
return | ||
} | ||
|
||
assert.Equal(t, "/v1/tlspk/upload/clusterdata/no", gotReq.URL.Path) | ||
|
||
// Let's check that the body isn't compressed. | ||
assert.Equal(t, "", gotReq.Header.Get("Content-Encoding")) | ||
b := new(bytes.Buffer) | ||
_, err := b.ReadFrom(gotReq.Body) | ||
require.NoError(t, err) | ||
assert.Contains(t, b.String(), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
|
||
privKeyPath := withFile(t, fakePrivKeyPEM) | ||
got, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: "test cluster name" | ||
venafi-cloud: | ||
uploader_id: no | ||
upload_path: /v1/tlspk/upload/clusterdata | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--client-id", "5bc7d07c-45da-11ef-a878-523f1e1d7de1", "--private-key-path", privKeyPath, "--install-namespace", "venafi"), | ||
) | ||
require.NoError(t, err) | ||
testutil.TrustCA(t, cl, cert) | ||
assert.Equal(t, VenafiCloudKeypair, got.AuthMode) | ||
require.NoError(t, err) | ||
|
||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: "test cluster name"}) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
// Slower test cases due to envtest. That's why they are separated from the | ||
|
@@ -820,53 +746,6 @@ func Test_ValidateAndCombineConfig_VenafiConnection(t *testing.T) { | |
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("the request is compressed by default", func(t *testing.T) { | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Let's check that the body is compressed as expected. | ||
assert.Equal(t, "gzip", gotReq.Header.Get("Content-Encoding")) | ||
uncompressR, err := gzip.NewReader(gotReq.Body) | ||
require.NoError(t, err, "body might not be compressed") | ||
defer uncompressR.Close() | ||
uncompressed, err := io.ReadAll(uncompressR) | ||
require.NoError(t, err) | ||
assert.Contains(t, string(uncompressed), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
cfg, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
period: 1h | ||
cluster_id: test cluster name | ||
`)), | ||
withCmdLineFlags("--venafi-connection", "venafi-components", "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
testutil.VenConnStartWatching(t, cl) | ||
testutil.TrustCA(t, cl, cert) | ||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("--disable-compression works", func(t *testing.T) { | ||
setVenafiCloudAssert(func(t testing.TB, gotReq *http.Request) { | ||
// Let's check that the body isn't compressed. | ||
assert.Equal(t, "", gotReq.Header.Get("Content-Encoding")) | ||
b := new(bytes.Buffer) | ||
_, err := b.ReadFrom(gotReq.Body) | ||
require.NoError(t, err) | ||
assert.Contains(t, b.String(), `{"agent_metadata":{"version":"development","cluster_id":"test cluster name"}`) | ||
}) | ||
cfg, cl, err := ValidateAndCombineConfig(discardLogs(), | ||
withConfig(testutil.Undent(` | ||
server: `+srv.URL+` | ||
period: 1h | ||
cluster_id: test cluster name | ||
`)), | ||
withCmdLineFlags("--disable-compression", "--venafi-connection", "venafi-components", "--install-namespace", "venafi")) | ||
require.NoError(t, err) | ||
testutil.VenConnStartWatching(t, cl) | ||
testutil.TrustCA(t, cl, cert) | ||
err = cl.PostDataReadingsWithOptions(nil, client.Options{ClusterName: cfg.ClusterID}) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
|
||
func Test_ParseConfig(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.