forked from hashicorp/go-getter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testing private ssh keys in git getter
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package getter | ||
|
||
import ( | ||
"encoding/base64" | ||
"net/url" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
@@ -229,3 +231,59 @@ func TestGitGetter_GetFile(t *testing.T) { | |
} | ||
assertContents(t, dst, "Hello\n") | ||
} | ||
|
||
func TestGitGetter_sshKey(t *testing.T) { | ||
if !testHasGit { | ||
t.Log("git not found, skipping") | ||
t.Skip() | ||
} | ||
|
||
g := new(GitGetter) | ||
dst := tempDir(t) | ||
|
||
encodedKey := base64.StdEncoding.EncodeToString([]byte(testGitToken)) | ||
|
||
u, err := url.Parse("ssh://[email protected]/hashicorp/test-private-repo" + | ||
"?sshkey=" + encodedKey) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if err := g.Get(dst, u); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
|
||
readmePath := filepath.Join(dst, "README.md") | ||
if _, err := os.Stat(readmePath); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
// This is a read-only deploy key for an empty test repository. | ||
var testGitToken = `-----BEGIN RSA PRIVATE KEY----- | ||
MIIEpgIBAAKCAQEArGJ7eweUMiT58m424ZHLu6UordeoTcOTPEMeOjIL2GuVhPU+ | ||
Y6sdW3gMKEYFKo5ywXxVgNo8VCI8Ny8+PPfR+BNJaAI+VYNDU5rvD3ecfIjH3We4 | ||
VyRbT/PcxNK1XJcE260P6nVXrnNLJQBbsP6tjqSswwVy/9gCiI0aa4GxvK4R1ZPJ |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