mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-24 20:37:17 +00:00
Disallows empty string as validator password (#6201)
* allows empty string as validator password * disallow empty pass on validator creation * reset
This commit is contained in:
parent
89e1b0f6bb
commit
1ffd13c4f5
@ -65,6 +65,9 @@ func VerifyAccountNotExists(directory string, password string) error {
|
||||
// generates a BLS private and public key, and then logs the serialized deposit input hex string
|
||||
// to be used in an ETH1.0 transaction by the validator.
|
||||
func NewValidatorAccount(directory string, password string) error {
|
||||
if password == "" {
|
||||
return errors.New("empty passphrase is not allowed")
|
||||
}
|
||||
shardWithdrawalKeyFile := directory + params.BeaconConfig().WithdrawalPrivkeyFileName
|
||||
validatorKeyFile := directory + params.BeaconConfig().ValidatorPrivkeyFileName
|
||||
ks := keystore.NewKeystore(directory)
|
||||
|
@ -46,7 +46,7 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
||||
if err := ks.StoreKey(directory+params.BeaconConfig().ValidatorPrivkeyFileName, validatorKey, ""); err != nil {
|
||||
t.Fatalf("Unable to store key %v", err)
|
||||
}
|
||||
if err := NewValidatorAccount(directory, ""); err != nil {
|
||||
if err := NewValidatorAccount(directory, "passsword123"); err != nil {
|
||||
t.Errorf("Should support multiple keys: %v", err)
|
||||
}
|
||||
files, err := ioutil.ReadDir(directory)
|
||||
@ -62,26 +62,48 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewValidatorAccount_CreateValidatorAccount(t *testing.T) {
|
||||
directory := testutil.TempDir() + "/testkeystore"
|
||||
defer func() {
|
||||
if err := os.RemoveAll(directory); err != nil {
|
||||
t.Logf("Could not remove directory: %v", err)
|
||||
t.Run("custom non-existent path", func(t *testing.T) {
|
||||
_, _, err := CreateValidatorAccount("foobar", "foobar")
|
||||
wantErrString := fmt.Sprintf("path %q does not exist", "foobar")
|
||||
if err == nil || err.Error() != wantErrString {
|
||||
t.Errorf("expected error not thrown, want: %v, got: %v", wantErrString, err)
|
||||
}
|
||||
}()
|
||||
_, _, err := CreateValidatorAccount("foobar", "foobar")
|
||||
wantErrString := fmt.Sprintf("path %q does not exist", "foobar")
|
||||
if err == nil || err.Error() != wantErrString {
|
||||
t.Errorf("expected error not thrown, want: %v, got: %v", wantErrString, err)
|
||||
}
|
||||
})
|
||||
|
||||
// Make sure that empty existing directory doesn't trigger any errors.
|
||||
if err := os.Mkdir(directory, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, err = CreateValidatorAccount(directory, "foobar")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
t.Run("empty existing dir", func(t *testing.T) {
|
||||
directory := testutil.TempDir() + "/testkeystore"
|
||||
defer func() {
|
||||
if err := os.RemoveAll(directory); err != nil {
|
||||
t.Logf("Could not remove directory: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Make sure that empty existing directory doesn't trigger any errors.
|
||||
if err := os.Mkdir(directory, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, err := CreateValidatorAccount(directory, "foobar")
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty string as password", func(t *testing.T) {
|
||||
directory := testutil.TempDir() + "/testkeystore"
|
||||
defer func() {
|
||||
if err := os.RemoveAll(directory); err != nil {
|
||||
t.Logf("Could not remove directory: %v", err)
|
||||
}
|
||||
}()
|
||||
if err := os.Mkdir(directory, 0777); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
_, _, err := CreateValidatorAccount(directory, "")
|
||||
wantErrString := "empty passphrase is not allowed"
|
||||
if err == nil || !strings.Contains(err.Error(), wantErrString) {
|
||||
t.Errorf("expected error not thrown, want: %v, got: %v", wantErrString, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestHandleEmptyFlags_FlagsSet(t *testing.T) {
|
||||
|
@ -126,7 +126,7 @@ contract in order to activate the validator client`,
|
||||
log.WithError(err).Error("Could not list keys")
|
||||
}
|
||||
if _, _, err := accounts.CreateValidatorAccount(keystorePath, passphrase); err != nil {
|
||||
log.WithError(err).Fatalf("Could not create validator at path: %s", keystorePath)
|
||||
log.WithField("err", err.Error()).Fatalf("Could not create validator at path: %s", keystorePath)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
@ -189,7 +189,7 @@ contract in order to activate the validator client`,
|
||||
endpoint := cliCtx.String(flags.BeaconRPCProviderFlag.Name)
|
||||
conn, err := grpc.DialContext(ctx, endpoint, dialOpts...)
|
||||
if err != nil {
|
||||
log.WithError(err).Fatalf("Failed to dial beacon node endpoint at %s", endpoint)
|
||||
log.WithError(err).Errorf("Failed to dial beacon node endpoint at %s", endpoint)
|
||||
return err
|
||||
}
|
||||
err = accounts.RunStatusCommand(pubKeys, ethpb.NewBeaconNodeValidatorClient(conn))
|
||||
|
Loading…
Reference in New Issue
Block a user