throw error if account already exist when doing local pairing on receiver side (#3091)
This commit is contained in:
parent
d44fa42cbf
commit
4a970683d1
|
@ -3,6 +3,7 @@ package pairing
|
|||
import (
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -20,6 +21,10 @@ import (
|
|||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrKeyFileAlreadyExists = errors.New("key file already exists")
|
||||
)
|
||||
|
||||
// PayloadManager is the interface for PayloadManagers and wraps the basic functions for fulfilling payload management
|
||||
type PayloadManager interface {
|
||||
// Mount Loads the payload into the PayloadManager's state
|
||||
|
@ -475,11 +480,17 @@ func (apr *AccountPayloadRepository) storeKeys(keyStorePath string) error {
|
|||
return fmt.Errorf("no known Key UID")
|
||||
}
|
||||
keyStorePath = filepath.Join(keyStorePath, apr.multiaccount.KeyUID)
|
||||
|
||||
_, err := os.Stat(keyStorePath)
|
||||
if os.IsNotExist(err) {
|
||||
err := os.MkdirAll(keyStorePath, 0777)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if err != nil {
|
||||
return err
|
||||
} else {
|
||||
return ErrKeyFileAlreadyExists
|
||||
}
|
||||
}
|
||||
|
||||
for name, data := range apr.keys {
|
||||
|
|
|
@ -70,7 +70,7 @@ func makeKeystores(t *testing.T) (string, string, func()) {
|
|||
|
||||
keyStoreDir = filepath.Join(keyStoreDir, "keystore", keyUID)
|
||||
// TODO test case where the keystore dir does not yet exist because the device is new
|
||||
emptyKeyStoreDir = filepath.Join(emptyKeyStoreDir, "keystore", keyUID)
|
||||
emptyKeyStoreDir = filepath.Join(emptyKeyStoreDir, "keystore")
|
||||
|
||||
err = os.MkdirAll(keyStoreDir, 0777)
|
||||
require.NoError(t, err)
|
||||
|
@ -301,7 +301,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_StorePayloads() {
|
|||
pms.Require().NoError(err)
|
||||
|
||||
// TEST PairingPayloadRepository 2 StoreToSource()
|
||||
keys := getFiles(pms.T(), pms.config2.KeystorePath)
|
||||
keys := getFiles(pms.T(), filepath.Join(pms.config2.KeystorePath, pms.config2.KeyUID))
|
||||
|
||||
pms.Require().Len(keys, 2)
|
||||
pms.Require().Len(keys[utils.GetAccount1PKFile()], 489)
|
||||
|
@ -326,6 +326,9 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_StorePayloads() {
|
|||
pms.Require().Exactly(expected.Name, acc.Name)
|
||||
pms.Require().Exactly(expected.Timestamp, acc.Timestamp)
|
||||
pms.Require().Len(acc.Images, 2)
|
||||
|
||||
err = ppr2.StoreToSource()
|
||||
pms.Require().ErrorIs(err, ErrKeyFileAlreadyExists)
|
||||
}
|
||||
|
||||
func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_LockPayload() {
|
||||
|
|
Loading…
Reference in New Issue