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 (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -20,6 +21,10 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"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
|
// PayloadManager is the interface for PayloadManagers and wraps the basic functions for fulfilling payload management
|
||||||
type PayloadManager interface {
|
type PayloadManager interface {
|
||||||
// Mount Loads the payload into the PayloadManager's state
|
// Mount Loads the payload into the PayloadManager's state
|
||||||
|
@ -475,10 +480,16 @@ func (apr *AccountPayloadRepository) storeKeys(keyStorePath string) error {
|
||||||
return fmt.Errorf("no known Key UID")
|
return fmt.Errorf("no known Key UID")
|
||||||
}
|
}
|
||||||
keyStorePath = filepath.Join(keyStorePath, apr.multiaccount.KeyUID)
|
keyStorePath = filepath.Join(keyStorePath, apr.multiaccount.KeyUID)
|
||||||
|
_, err := os.Stat(keyStorePath)
|
||||||
err := os.MkdirAll(keyStorePath, 0777)
|
if os.IsNotExist(err) {
|
||||||
if err != nil {
|
err := os.MkdirAll(keyStorePath, 0777)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
|
} else {
|
||||||
|
return ErrKeyFileAlreadyExists
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ func makeKeystores(t *testing.T) (string, string, func()) {
|
||||||
|
|
||||||
keyStoreDir = filepath.Join(keyStoreDir, "keystore", keyUID)
|
keyStoreDir = filepath.Join(keyStoreDir, "keystore", keyUID)
|
||||||
// TODO test case where the keystore dir does not yet exist because the device is new
|
// 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)
|
err = os.MkdirAll(keyStoreDir, 0777)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -301,7 +301,7 @@ func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_StorePayloads() {
|
||||||
pms.Require().NoError(err)
|
pms.Require().NoError(err)
|
||||||
|
|
||||||
// TEST PairingPayloadRepository 2 StoreToSource()
|
// 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, 2)
|
||||||
pms.Require().Len(keys[utils.GetAccount1PKFile()], 489)
|
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.Name, acc.Name)
|
||||||
pms.Require().Exactly(expected.Timestamp, acc.Timestamp)
|
pms.Require().Exactly(expected.Timestamp, acc.Timestamp)
|
||||||
pms.Require().Len(acc.Images, 2)
|
pms.Require().Len(acc.Images, 2)
|
||||||
|
|
||||||
|
err = ppr2.StoreToSource()
|
||||||
|
pms.Require().ErrorIs(err, ErrKeyFileAlreadyExists)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_LockPayload() {
|
func (pms *PayloadMarshallerSuite) TestPayloadMarshaller_LockPayload() {
|
||||||
|
|
Loading…
Reference in New Issue