feat: rename method

This commit is contained in:
Urko 2023-03-06 17:53:29 +01:00
parent d94d5ec27c
commit d79f43f6a4
2 changed files with 13 additions and 10 deletions

View File

@ -12,7 +12,10 @@ import (
"google.golang.org/grpc/credentials"
)
func CredentialsFromKeyWithPasswd(certFile, certKey, passwd string) (credentials.TransportCredentials, error) {
// FromRSAKeyWithPassword receives a certificate .pem file which was
// requested with .pem key file secured by password. By default go doesn't provide a
// standard packag that is not deprecated:
func FromRSAKeyWithPassword(certFile, certKey, passwd string) (credentials.TransportCredentials, error) {
if certFile == "" {
return nil, errors.New("certFile cannot be empty")
}

View File

@ -83,10 +83,10 @@ func TestCredentialsFromKeyWithPasswd(t *testing.T) {
require.NoError(t, deleteTestDir())
}()
_, err := CredentialsFromKeyWithPasswd(testCert, testCertKey, testKeyPass)
_, err := FromRSAKeyWithPassword(testCert, testCertKey, testKeyPass)
assert.NoError(t, err, "key with password should not fail")
_, err = CredentialsFromKeyWithPasswd(testCert, testCertKey, "wrong-pass")
_, err = FromRSAKeyWithPassword(testCert, testCertKey, "wrong-pass")
assert.Error(t, err, "key with wrong pass password should not fail")
}
@ -98,30 +98,30 @@ func TestCredentialsFromKeyWithPasswdError(t *testing.T) {
require.NoError(t, deleteTestDir())
}()
_, err := CredentialsFromKeyWithPasswd("", "", "")
_, err := FromRSAKeyWithPassword("", "", "")
assert.Error(t, err)
_, err = CredentialsFromKeyWithPasswd(testCert, "", "")
_, err = FromRSAKeyWithPassword(testCert, "", "")
assert.Error(t, err)
_, err = CredentialsFromKeyWithPasswd(testCert, "not-exists.txt", "")
_, err = FromRSAKeyWithPassword(testCert, "not-exists.txt", "")
assert.Error(t, err)
require.NoError(t, os.WriteFile(testKeyError, []byte(""), os.ModeAppend))
_, err = CredentialsFromKeyWithPasswd(testCert, testKeyError, testKeyPass)
_, err = FromRSAKeyWithPassword(testCert, testKeyError, testKeyPass)
require.Error(t, err)
require.NoError(t, os.WriteFile(testCertKeyError, []byte(certKeyError), os.ModeAppend))
_, err = CredentialsFromKeyWithPasswd(testCert, testCertKeyError, testKeyPass)
_, err = FromRSAKeyWithPassword(testCert, testCertKeyError, testKeyPass)
assert.Error(t, err)
require.NoError(t, os.Remove(testCertKeyError))
assert.NoError(t, os.WriteFile(testCertKeyError, []byte(certKeyOk), os.ModeAppend))
_, err = CredentialsFromKeyWithPasswd(testCert, testCertKeyError, testKeyPass)
_, err = FromRSAKeyWithPassword(testCert, testCertKeyError, testKeyPass)
assert.Error(t, err, "key without password should fail")
require.NoError(t, createEncryptedKeyFile())
_, err = CredentialsFromKeyWithPasswd(testCert, testCertKey, testKeyPass)
_, err = FromRSAKeyWithPassword(testCert, testCertKey, testKeyPass)
assert.Error(t, err, "key without password should fail")
}