From 6c75ceb8b5bfc223de882f47c11b25bb19436617 Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 29 Nov 2013 22:36:58 +0100 Subject: [PATCH] pkg/index: do not record a keySignerAttrValue on DelAttributeClaim Change-Id: Ib1f81fe4879de2be7d484a5a40cc6bf0449893d5 --- pkg/index/indextest/tests.go | 45 ++++++++++++++++++++++++++++++++---- pkg/index/receive.go | 2 +- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/pkg/index/indextest/tests.go b/pkg/index/indextest/tests.go index d911d9013..158868242 100644 --- a/pkg/index/indextest/tests.go +++ b/pkg/index/indextest/tests.go @@ -275,6 +275,7 @@ Enpn/oOOfYFa5h0AFndZd1blMvruXfdAobjVABEBAAE= func Index(t *testing.T, initIdx func() *index.Index) { id := NewIndexDeps(initIdx()) id.Fataler = t + defer id.DumpIndex(t) pn := id.NewPermanode() t.Logf("uploaded permanode %q", pn) br1 := id.SetAttribute(pn, "tag", "foo1") @@ -341,7 +342,6 @@ func Index(t *testing.T, initIdx func() *index.Index) { ) lastPermanodeMutation := id.lastTime() - id.DumpIndex(t) key := "signerkeyid:sha1-ad87ca5c78bd0ce1195c46f7c98e6025abbaf007" if g, e := id.Get(key), "2931A67C26F5ABDA"; g != e { @@ -409,7 +409,8 @@ func Index(t *testing.T, initIdx func() *index.Index) { req := &camtypes.PermanodeByAttrRequest{ Signer: id.SignerBlobRef, Attribute: "tag", - Query: "foo1"} + Query: "foo1", + } err := id.Index.SearchPermanodesWithAttr(ch, req) if err != nil { t.Fatalf("SearchPermanodesWithAttr = %v", err) @@ -429,7 +430,8 @@ func Index(t *testing.T, initIdx func() *index.Index) { ch := make(chan blob.Ref, 10) req := &camtypes.PermanodeByAttrRequest{ Signer: id.SignerBlobRef, - Attribute: "tag"} + Attribute: "tag", + } err := id.Index.SearchPermanodesWithAttr(ch, req) if err != nil { t.Fatalf("SearchPermanodesWithAttr = %v", err) @@ -457,6 +459,32 @@ func Index(t *testing.T, initIdx func() *index.Index) { } } + // Delete value "pony" of type "title" (which does not actually exist) for pn + br4 := id.DelAttribute(pn, "title", "pony") + br4Time := id.lastTime() + // and verify it is not found when searching by attr + { + ch := make(chan blob.Ref, 10) + req := &camtypes.PermanodeByAttrRequest{ + Signer: id.SignerBlobRef, + Attribute: "title", + Query: "pony", + } + err := id.Index.SearchPermanodesWithAttr(ch, req) + if err != nil { + t.Fatalf("SearchPermanodesWithAttr = %v", err) + } + var got []blob.Ref + for r := range ch { + got = append(got, r) + } + want := []blob.Ref{} + if len(got) != len(want) { + t.Errorf("SearchPermanodesWithAttr results differ.\n got: %q\nwant: %q", + got, want) + } + } + // GetRecentPermanodes { verify := func(prefix string, want []camtypes.RecentPermanode, before time.Time) { @@ -492,7 +520,7 @@ func Index(t *testing.T, initIdx func() *index.Index) { { Permanode: pn, Signer: id.SignerBlobRef, - LastModTime: lastPermanodeMutation, + LastModTime: br4Time, }, { Permanode: pnChild, @@ -601,6 +629,15 @@ func Index(t *testing.T, initIdx func() *index.Index) { Attr: "camliMember", Value: pnChild.String(), }, + { + BlobRef: br4, + Permanode: pn, + Signer: id.SignerBlobRef, + Date: br4Time.UTC(), + Type: "del-attribute", + Attr: "title", + Value: "pony", + }, } if !reflect.DeepEqual(claims, want) { t.Errorf("AppendClaims results differ.\n got: %v\nwant: %v", diff --git a/pkg/index/receive.go b/pkg/index/receive.go index 9a6a53b55..0f2b7ac03 100644 --- a/pkg/index/receive.go +++ b/pkg/index/receive.go @@ -439,7 +439,7 @@ func (ix *Index) populateClaim(b *schema.Blob, mm *mutationMap) error { } } - if IsIndexedAttribute(attr) { + if claim.ClaimType() != string(schema.DelAttributeClaim) && IsIndexedAttribute(attr) { key := keySignerAttrValue.Key(verifiedKeyId, attr, value, claim.ClaimDateString(), br) mm.Set(key, keySignerAttrValue.Val(pnbr)) }