From a4252c721713e1cbb97ea451366d5be8de73b3da Mon Sep 17 00:00:00 2001 From: armfazh Date: Mon, 15 Apr 2024 15:33:19 -0700 Subject: [PATCH] Test functions working with ciphertext. --- abe/cpabe/tkn20/format_test.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/abe/cpabe/tkn20/format_test.go b/abe/cpabe/tkn20/format_test.go index 122bf5e06..f8c464d6b 100644 --- a/abe/cpabe/tkn20/format_test.go +++ b/abe/cpabe/tkn20/format_test.go @@ -46,15 +46,33 @@ func TestCiphertext(t *testing.T) { if err != nil { t.Fatalf("Unable to read ciphertext data") } - policyKey, err := os.ReadFile("testdata/attributeKey") + attributeKey, err := os.ReadFile("testdata/attributeKey") if err != nil { t.Fatalf("Unable to read secret key") } sk := AttributeKey{} - err = sk.UnmarshalBinary(policyKey) + err = sk.UnmarshalBinary(attributeKey) if err != nil { t.Fatalf("unable to parse secret key") } + attrs := Attributes{} + attrs.FromMap(map[string]string{"country": "NL", "EU": "true"}) + if !attrs.CouldDecrypt(ciphertext) { + t.Fatal("these attributes will be unable to decrypt message") + } + policy := Policy{} + err = policy.FromString("EU: true") + if err != nil { + t.Fatal("error creating policy from string") + } + gotPolicy := new(Policy) + err = gotPolicy.ExtractFromCiphertext(ciphertext) + if err != nil { + t.Fatal("error extracting policy from ciphertext") + } + if !policy.Equal(gotPolicy) { + t.Fatal("ciphertext's policy mismatches the original policy") + } msg, err := sk.Decrypt(ciphertext) if err != nil { t.Fatal("unable to decrypt message")