-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4759 from mightyguava/enable-ssh-tests
Enable SSH tests
- Loading branch information
Showing
2 changed files
with
34 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,10 @@ | |
package krusty_test | ||
|
||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
|
@@ -17,6 +20,7 @@ import ( | |
"sigs.k8s.io/kustomize/api/loader" | ||
"sigs.k8s.io/kustomize/api/resmap" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
) | ||
|
||
const resourcesField = `resources: | ||
|
@@ -97,11 +101,36 @@ func runResourceTests(t *testing.T, cases map[string]*remoteResourceCase) { | |
if savedTest.local && !isLocalEnv(req) { | ||
t.SkipNow() | ||
} | ||
configureGitSSHCommand(t) | ||
testRemoteResource(req, test) | ||
}) | ||
} | ||
} | ||
|
||
func configureGitSSHCommand(t *testing.T) { | ||
t.Helper() | ||
|
||
// This contains a read-only Deploy Key for the kustomize repo. | ||
node, err := yaml.ReadFile("testdata/repo_read_only_ssh_key.yaml") | ||
require.NoError(t, err) | ||
keyB64, err := node.GetString("key") | ||
require.NoError(t, err) | ||
key, err := base64.StdEncoding.DecodeString(keyB64) | ||
require.NoError(t, err) | ||
|
||
// Write the key to a temp file and use it in SSH | ||
f, err := os.CreateTemp("", "kustomize_ssh") | ||
require.NoError(t, err) | ||
_, err = io.Copy(f, bytes.NewReader(key)) | ||
require.NoError(t, err) | ||
cmd := fmt.Sprintf("ssh -i %s", f.Name()) | ||
const SSHCommandKey = "GIT_SSH_COMMAND" | ||
t.Setenv(SSHCommandKey, cmd) | ||
t.Cleanup(func() { | ||
_ = os.Remove(f.Name()) | ||
}) | ||
} | ||
|
||
func TestRemoteLoad(t *testing.T) { | ||
req := require.New(t) | ||
|
||
|
@@ -148,17 +177,14 @@ namePrefix: dev-`, | |
} | ||
|
||
func TestRemoteResourceSsh(t *testing.T) { | ||
// TODO: add ssh keys to server to run these tests | ||
tests := map[string]*remoteResourceCase{ | ||
"scp shorthand": { | ||
local: true, | ||
kustomization: ` | ||
resources: | ||
- [email protected]:kubernetes-sigs/kustomize//examples/multibases/dev/?ref=v1.0.6`, | ||
expected: multibaseDevExampleBuild, | ||
}, | ||
"full ssh, no ending slash": { | ||
local: true, | ||
kustomization: ` | ||
resources: | ||
- ssh://[email protected]/kubernetes-sigs/kustomize//examples/multibases/dev?ref=v1.0.6`, | ||
|
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# This is a base64 encoded SSH private key configured as a GitHub Deploy key, | ||
# with read-only access to the kustomize repo | ||
# DO NOT copy this key anywhere else. | ||
# DO NOT give it additional permissions. | ||
key: LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUFNd0FBQUF0emMyZ3RaVwpReU5UVXhPUUFBQUNBVHRxUEpEUFI3dW5QMHF5YTVYZGhYQ1pJSmVRaDgzNHoyUk9zSm9rTWE2QUFBQUppdGppaE5yWTRvClRRQUFBQXR6YzJndFpXUXlOVFV4T1FBQUFDQVR0cVBKRFBSN3VuUDBxeWE1WGRoWENaSUplUWg4MzR6MlJPc0pva01hNkEKQUFBRUM3KzcvdnRlQW5QdWVBTm5vaEE5b0U2dHBCeHJSWUVubnA5Y1lURnFqOGhCTzJvOGtNOUh1NmMvU3JKcmxkMkZjSgprZ2w1Q0h6ZmpQWkU2d21pUXhyb0FBQUFFbXR1TG5abGNtVjVRR2R0WVdsc0xtTnZiUUVDQXc9PQotLS0tLUVORCBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0K |