Skip to content

Commit

Permalink
Fix virtual document cache invalidation
Browse files Browse the repository at this point in the history
The virtual document cache was not being invalidated. As a result, if
the same rule was evaluated twice where the first expression included a
with modifier, the result on the second evaluation may be incorrect.

Fixes #736

Signed-off-by: Torin Sandall <[email protected]>
  • Loading branch information
tsandall committed May 11, 2018
1 parent 54ae645 commit 8accf73
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion topdown/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *virtualCache) Push() {
}

func (c *virtualCache) Pop() {
c.stack = c.stack[:len(c.stack)]
c.stack = c.stack[:len(c.stack)-1]
}

func (c *virtualCache) Get(ref ast.Ref) *ast.Term {
Expand Down
22 changes: 22 additions & 0 deletions topdown/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 The OPA Authors. All rights reserved.
// Use of this source code is governed by an Apache2
// license that can be found in the LICENSE file.

package topdown

import (
"testing"

"github.com/open-policy-agent/opa/ast"
)

func TestVirtualCacheInvalidate(t *testing.T) {
cache := newVirtualCache()
cache.Push()
cache.Put(ast.MustParseRef("data.x.p"), ast.BooleanTerm(true))
cache.Pop()
result := cache.Get(ast.MustParseRef("data.x.p"))
if result != nil {
t.Fatal("Expected nil result but got:", result)
}
}

0 comments on commit 8accf73

Please sign in to comment.