Skip to content

Commit

Permalink
Merge pull request #4759 from mightyguava/enable-ssh-tests
Browse files Browse the repository at this point in the history
Enable SSH tests
  • Loading branch information
k8s-ci-robot authored Aug 26, 2022
2 parents a8388f4 + 5dcbd35 commit b6fae2a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
32 changes: 29 additions & 3 deletions api/krusty/remoteload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
package krusty_test

import (
"bytes"
"encoding/base64"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
Expand All @@ -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:
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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`,
Expand Down
5 changes: 5 additions & 0 deletions api/krusty/testdata/repo_read_only_ssh_key.yaml
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

0 comments on commit b6fae2a

Please sign in to comment.