-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add env var for ssh private key (#396)
(cherry picked from commit 08bdb8d)
- Loading branch information
1 parent
179f3c8
commit b2400e8
Showing
7 changed files
with
137 additions
and
6 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
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ package git_test | |
import ( | ||
"context" | ||
"crypto/ed25519" | ||
"encoding/base64" | ||
"fmt" | ||
"io" | ||
"net/http/httptest" | ||
|
@@ -433,6 +434,22 @@ func TestSetupRepoAuth(t *testing.T) { | |
require.Equal(t, actualSigner, pk.Signer) | ||
}) | ||
|
||
t.Run("SSH/Base64PrivateKey", func(t *testing.T) { | ||
opts := &options.Options{ | ||
GitURL: "ssh://[email protected]:repo/path", | ||
GitSSHPrivateKeyBase64: base64EncodeTestPrivateKey(), | ||
} | ||
auth := git.SetupRepoAuth(t.Logf, opts) | ||
|
||
pk, ok := auth.(*gitssh.PublicKeys) | ||
require.True(t, ok) | ||
require.NotNil(t, pk.Signer) | ||
|
||
actualSigner, err := gossh.ParsePrivateKey([]byte(testKey)) | ||
require.NoError(t, err) | ||
require.Equal(t, actualSigner, pk.Signer) | ||
}) | ||
|
||
t.Run("SSH/NoAuthMethods", func(t *testing.T) { | ||
opts := &options.Options{ | ||
GitURL: "ssh://[email protected]:repo/path", | ||
|
@@ -502,3 +519,7 @@ func writeTestPrivateKey(t *testing.T) string { | |
require.NoError(t, os.WriteFile(kPath, []byte(testKey), 0o600)) | ||
return kPath | ||
} | ||
|
||
func base64EncodeTestPrivateKey() string { | ||
return base64.StdEncoding.EncodeToString([]byte(testKey)) | ||
} |
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
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