mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 09:02:53 +00:00
Enable SSH tests
This commit is contained in:
@@ -4,7 +4,10 @@
|
|||||||
package krusty_test
|
package krusty_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -17,6 +20,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/api/loader"
|
"sigs.k8s.io/kustomize/api/loader"
|
||||||
"sigs.k8s.io/kustomize/api/resmap"
|
"sigs.k8s.io/kustomize/api/resmap"
|
||||||
"sigs.k8s.io/kustomize/kyaml/filesys"
|
"sigs.k8s.io/kustomize/kyaml/filesys"
|
||||||
|
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
const resourcesField = `resources:
|
const resourcesField = `resources:
|
||||||
@@ -97,11 +101,36 @@ func runResourceTests(t *testing.T, cases map[string]*remoteResourceCase) {
|
|||||||
if savedTest.local && !isLocalEnv(req) {
|
if savedTest.local && !isLocalEnv(req) {
|
||||||
t.SkipNow()
|
t.SkipNow()
|
||||||
}
|
}
|
||||||
|
configureGitSSHCommand(t)
|
||||||
testRemoteResource(req, test)
|
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) {
|
func TestRemoteLoad(t *testing.T) {
|
||||||
req := require.New(t)
|
req := require.New(t)
|
||||||
|
|
||||||
@@ -148,17 +177,14 @@ namePrefix: dev-`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoteResourceSsh(t *testing.T) {
|
func TestRemoteResourceSsh(t *testing.T) {
|
||||||
// TODO: add ssh keys to server to run these tests
|
|
||||||
tests := map[string]*remoteResourceCase{
|
tests := map[string]*remoteResourceCase{
|
||||||
"scp shorthand": {
|
"scp shorthand": {
|
||||||
local: true,
|
|
||||||
kustomization: `
|
kustomization: `
|
||||||
resources:
|
resources:
|
||||||
- git@github.com:kubernetes-sigs/kustomize//examples/multibases/dev/?ref=v1.0.6`,
|
- git@github.com:kubernetes-sigs/kustomize//examples/multibases/dev/?ref=v1.0.6`,
|
||||||
expected: multibaseDevExampleBuild,
|
expected: multibaseDevExampleBuild,
|
||||||
},
|
},
|
||||||
"full ssh, no ending slash": {
|
"full ssh, no ending slash": {
|
||||||
local: true,
|
|
||||||
kustomization: `
|
kustomization: `
|
||||||
resources:
|
resources:
|
||||||
- ssh://git@github.com/kubernetes-sigs/kustomize//examples/multibases/dev?ref=v1.0.6`,
|
- ssh://git@github.com/kubernetes-sigs/kustomize//examples/multibases/dev?ref=v1.0.6`,
|
||||||
|
|||||||
5
api/krusty/testdata/repo_read_only_ssh_key.yaml
vendored
Normal file
5
api/krusty/testdata/repo_read_only_ssh_key.yaml
vendored
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user