Skip to content

Commit aad1c4f

Browse files
committed
Fix conversion of caveat debug context
1 parent 383a05f commit aad1c4f

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

internal/caveats/debug.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func BuildDebugInformation(exprResult ExpressionResult) (string, *structpb.Struc
5050
}
5151

5252
// Convert the context map to a struct.
53-
contextStruct, err := structpb.NewStruct(contextMap)
53+
contextStruct, err := caveats.ConvertContextToStruct(contextMap)
5454
if err != nil {
5555
return "", nil, err
5656
}

internal/caveats/debug_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package caveats
22

33
import (
44
"testing"
5+
"time"
56

67
"github.com/stretchr/testify/require"
78

@@ -10,6 +11,8 @@ import (
1011
core "github.com/authzed/spicedb/pkg/proto/core/v1"
1112
)
1213

14+
var testTime = time.Date(2021, 1, 1, 0, 0, 0, 0, time.UTC)
15+
1316
func TestBuildDebugInformation(t *testing.T) {
1417
tcs := []struct {
1518
name string
@@ -165,6 +168,26 @@ func TestBuildDebugInformation(t *testing.T) {
165168
},
166169
expectedExprString: "(a__0 + b__0 + c == 5) && (a__1 - b__1 - d == 64)",
167170
},
171+
{
172+
name: "name reuse around times",
173+
result: and(
174+
eval("expires_at < now", map[string]any{
175+
"expires_at": testTime,
176+
"now": testTime.Add(1 * time.Hour),
177+
}),
178+
eval("expires_at < now", map[string]any{
179+
"expires_at": testTime,
180+
"now": testTime.Add(1 * time.Hour),
181+
}),
182+
),
183+
expectedContext: map[string]any{
184+
"expires_at__0": "2021-01-01T00:00:00Z",
185+
"expires_at__1": "2021-01-01T00:00:00Z",
186+
"now__0": "2021-01-01T01:00:00Z",
187+
"now__1": "2021-01-01T01:00:00Z",
188+
},
189+
expectedExprString: "(expires_at__0 < now__0) && (expires_at__1 < now__1)",
190+
},
168191
}
169192

170193
for _, tc := range tcs {

0 commit comments

Comments
 (0)