aboutsummaryrefslogtreecommitdiff
path: root/actions/protector_test.go
diff options
context:
space:
mode:
authorJoe Richey joerichey@google.com <joerichey@google.com>2017-06-21 10:03:44 -0700
committerJoe Richey joerichey@google.com <joerichey@google.com>2017-06-28 15:15:15 -0700
commit93415b198a3ef427c02893b8fdf036aa75ffe50f (patch)
tree419be5fa11e9102597d3409800a3d7df4138b05e /actions/protector_test.go
parent77b226a90ef70b77ca556830528c013a23b01e57 (diff)
actions: error handling and API changed
This commit changes the error handling for the actions package to use the error handling library github.com/pkg/errors. This means replacing "errors" with "github.com/pkg/errors", reworking some of the error values, and wrapping some errors with additional context. This commit also changes the Protector/Policy API, moving most of the package functionality into Protector or Policy methods. These types are now "locked" when they are queried from the filesystem, and Unlock() must be used to get their corresponding keys. Note that only certain operations will require unlocking the keys. Certain unnecessary functions and methods are also removed. This CL also fixes two bugs reported by Tyler Hicks in CreateConfigFile. CPU time is used instead of wall time, and kiB is used instead of kB. Change-Id: I88f45659e9fe4938d148843e3289e7b6d5b698d8
Diffstat (limited to 'actions/protector_test.go')
-rw-r--r--actions/protector_test.go25
1 files changed, 8 insertions, 17 deletions
diff --git a/actions/protector_test.go b/actions/protector_test.go
index 08d9aed..eacba83 100644
--- a/actions/protector_test.go
+++ b/actions/protector_test.go
@@ -21,9 +21,10 @@ package actions
import (
"bytes"
- "errors"
"testing"
+ "github.com/pkg/errors"
+
. "fscrypt/crypto"
)
@@ -42,31 +43,21 @@ func badCallback(info ProtectorInfo, retry bool) (*Key, error) {
// Tests that we can create a valid protector.
func TestCreateProtector(t *testing.T) {
- ctx, err := makeContext()
- defer cleaupContext()
- if err != nil {
- t.Fatal(err)
- }
-
- p, err := CreateProtector(ctx, testProtectorName, goodCallback)
+ p, err := CreateProtector(testContext, testProtectorName, goodCallback)
if err != nil {
t.Error(err)
} else {
- p.Wipe()
+ p.Lock()
+ p.Destroy()
}
}
// Tests that a failure in the callback is relayed back to the caller.
func TestBadCallback(t *testing.T) {
- ctx, err := makeContext()
- defer cleaupContext()
- if err != nil {
- t.Fatal(err)
- }
-
- p, err := CreateProtector(ctx, testProtectorName, badCallback)
+ p, err := CreateProtector(testContext, testProtectorName, badCallback)
if err == nil {
- p.Wipe()
+ p.Lock()
+ p.Destroy()
}
if err != errCallback {
t.Error("callback error was not relayed back to caller")