|
|
@ -17,7 +17,6 @@ limitations under the License.
|
|
|
|
package sourcesecret
|
|
|
|
package sourcesecret
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
@ -43,8 +42,8 @@ func Test_passwordLoadKeyPair(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
pk, _ := ioutil.ReadFile(tt.privateKeyPath)
|
|
|
|
pk, _ := os.ReadFile(tt.privateKeyPath)
|
|
|
|
ppk, _ := ioutil.ReadFile(tt.publicKeyPath)
|
|
|
|
ppk, _ := os.ReadFile(tt.publicKeyPath)
|
|
|
|
|
|
|
|
|
|
|
|
got, err := loadKeyPair(tt.privateKeyPath, tt.password)
|
|
|
|
got, err := loadKeyPair(tt.privateKeyPath, tt.password)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -65,7 +64,7 @@ func Test_passwordLoadKeyPair(t *testing.T) {
|
|
|
|
func Test_PasswordlessLoadKeyPair(t *testing.T) {
|
|
|
|
func Test_PasswordlessLoadKeyPair(t *testing.T) {
|
|
|
|
for algo, privateKey := range testdata.PEMBytes {
|
|
|
|
for algo, privateKey := range testdata.PEMBytes {
|
|
|
|
t.Run(algo, func(t *testing.T) {
|
|
|
|
t.Run(algo, func(t *testing.T) {
|
|
|
|
f, err := ioutil.TempFile("", "test-private-key-")
|
|
|
|
f, err := os.CreateTemp("", "test-private-key-")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("unable to create temporary file. err: %s", err)
|
|
|
|
t.Fatalf("unable to create temporary file. err: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -81,7 +80,7 @@ func Test_PasswordlessLoadKeyPair(t *testing.T) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pk, _ := ioutil.ReadFile(f.Name())
|
|
|
|
pk, _ := os.ReadFile(f.Name())
|
|
|
|
if !reflect.DeepEqual(got.PrivateKey, pk) {
|
|
|
|
if !reflect.DeepEqual(got.PrivateKey, pk) {
|
|
|
|
t.Errorf("PrivateKey %s != %s", got.PrivateKey, string(privateKey))
|
|
|
|
t.Errorf("PrivateKey %s != %s", got.PrivateKey, string(privateKey))
|
|
|
|
}
|
|
|
|
}
|
|
|
|