-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jordan/5840-dkg-initial-delays
- Loading branch information
Showing
33 changed files
with
727 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/onflow/flow-go/cmd/bootstrap/utils" | ||
"github.com/onflow/flow-go/fvm/errors" | ||
"github.com/onflow/flow-go/model/bootstrap" | ||
"github.com/onflow/flow-go/utils/unittest" | ||
) | ||
|
||
// TestLoadSecretsEncryptionKey checks that the key file is read correctly if it exists | ||
// and returns the expected sentinel error if it does not exist. | ||
func TestLoadSecretsEncryptionKey(t *testing.T) { | ||
myID := unittest.IdentifierFixture() | ||
|
||
unittest.RunWithTempDir(t, func(dir string) { | ||
path := filepath.Join(dir, fmt.Sprintf(bootstrap.PathSecretsEncryptionKey, myID)) | ||
|
||
t.Run("should return ErrNotExist if file doesn't exist", func(t *testing.T) { | ||
require.NoFileExists(t, path) | ||
_, err := loadSecretsEncryptionKey(dir, myID) | ||
assert.Error(t, err) | ||
assert.True(t, errors.Is(err, os.ErrNotExist)) | ||
}) | ||
|
||
t.Run("should return key and no error if file exists", func(t *testing.T) { | ||
err := os.MkdirAll(filepath.Join(dir, bootstrap.DirPrivateRoot, fmt.Sprintf("private-node-info_%v", myID)), 0700) | ||
require.NoError(t, err) | ||
key, err := utils.GenerateSecretsDBEncryptionKey() | ||
require.NoError(t, err) | ||
err = ioutil.WriteFile(path, key, 0700) | ||
require.NoError(t, err) | ||
|
||
data, err := loadSecretsEncryptionKey(dir, myID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, key, data) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.