aboutsummaryrefslogtreecommitdiff
path: root/crypto/crypto_test.go
diff options
context:
space:
mode:
authorJoseph Richey <joerichey@google.com>2017-07-14 12:07:33 -0700
committerGitHub <noreply@github.com>2017-07-14 12:07:33 -0700
commite5cb8079aea929b1abd8d4279afc55983a5d0764 (patch)
treee35fb083482d26499038ca559fb5e345697d2542 /crypto/crypto_test.go
parent419fd9f24c2805c75a84da1cb52516de25dcecdd (diff)
parent480527993359c477849ccbd2c4d369df54807903 (diff)
Merge pull request #16 from google/fix
Use Description when placing keys in the keyring
Diffstat (limited to 'crypto/crypto_test.go')
-rw-r--r--crypto/crypto_test.go31
1 files changed, 20 insertions, 11 deletions
diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go
index 8b63457..5655fef 100644
--- a/crypto/crypto_test.go
+++ b/crypto/crypto_test.go
@@ -237,27 +237,36 @@ func TestKeyLargeResize(t *testing.T) {
// Adds and removes a key with various services.
func TestAddRemoveKeys(t *testing.T) {
for _, service := range []string{DefaultService, "ext4:", "f2fs:"} {
- if err := InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, service); err != nil {
+ validDescription := service + fakeValidDescriptor
+ if err := InsertPolicyKey(fakeValidPolicyKey, validDescription); err != nil {
t.Error(err)
}
- if err := RemovePolicyKey(fakeValidDescriptor, service); err != nil {
+ if err := RemovePolicyKey(validDescription); err != nil {
t.Error(err)
}
}
}
-// Makes sure a key fails with bad descriptor, policy, or service
+// Adds a key twice (both should succeed)
+func TestAddTwice(t *testing.T) {
+ validDescription := DefaultService + fakeValidDescriptor
+ InsertPolicyKey(fakeValidPolicyKey, validDescription)
+ if InsertPolicyKey(fakeValidPolicyKey, validDescription) != nil {
+ t.Error("InsertPolicyKey should not fail if key already exists")
+ }
+ RemovePolicyKey(validDescription)
+}
+
+// Makes sure a key fails with bad policy or service
func TestBadAddKeys(t *testing.T) {
- if InsertPolicyKey(fakeInvalidPolicyKey, fakeValidDescriptor, DefaultService) == nil {
- RemovePolicyKey(fakeValidDescriptor, DefaultService)
+ validDescription := DefaultService + fakeValidDescriptor
+ if InsertPolicyKey(fakeInvalidPolicyKey, validDescription) == nil {
+ RemovePolicyKey(validDescription)
t.Error("InsertPolicyKey should fail with bad policy key")
}
- if InsertPolicyKey(fakeValidPolicyKey, fakeInvalidDescriptor, DefaultService) == nil {
- RemovePolicyKey(fakeInvalidDescriptor, DefaultService)
- t.Error("InsertPolicyKey should fail with bad descriptor")
- }
- if InsertPolicyKey(fakeValidPolicyKey, fakeValidDescriptor, "ext4") == nil {
- RemovePolicyKey(fakeValidDescriptor, "ext4")
+ invalidDescription := "ext4" + fakeValidDescriptor
+ if InsertPolicyKey(fakeValidPolicyKey, invalidDescription) == nil {
+ RemovePolicyKey(invalidDescription)
t.Error("InsertPolicyKey should fail with bad service")
}
}