From 4c81ac778ebfb84ee52883974eba90ef6c228364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Thu, 23 Jan 2025 12:21:42 +0100 Subject: [PATCH] policy: fix tests now that selector evaluation is clearer https://github.com/ucan-wg/delegation/pull/15 https://github.com/ucan-wg/delegation/pull/16 --- Readme.md | 2 +- pkg/policy/match_test.go | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Readme.md b/Readme.md index 8944775..8d3ac91 100644 --- a/Readme.md +++ b/Readme.md @@ -57,7 +57,7 @@ Not implemented yet: Besides that, `go-ucan` also includes: - a simplified [DID](https://www.w3.org/TR/did-core/) and [did-key](https://w3c-ccg.github.io/did-method-key/) implementation -- a [token container](https://github.com/ucan-wg/go-ucan/tree/v1/pkg/container) with CBOR and CAR format, to package and carry tokens together +- a [token container](https://github.com/ucan-wg/go-ucan/tree/v1/pkg/container) with CBOR and CAR format, to package and carry tokens together, see [SPEC](pkg/container/SPEC.md) - support for encrypted values in token's metadata ## Getting Help diff --git a/pkg/policy/match_test.go b/pkg/policy/match_test.go index a8ad842..cf63c1d 100644 --- a/pkg/policy/match_test.go +++ b/pkg/policy/match_test.go @@ -135,8 +135,6 @@ func TestMatch(t *testing.T) { require.Equal(t, pol[0], leaf) }) - // ------------ - t.Run("neq string", func(t *testing.T) { nd := literal.String("test") @@ -236,11 +234,11 @@ func TestMatch(t *testing.T) { require.True(t, ok) require.Nil(t, leaf) - // TODO: clarify how it behave when the data is missing + // missing data will fail, as not optional pol = MustConstruct(NotEqual(".foobar", literal.String("bar"))) ok, leaf = pol.Match(nd) - require.True(t, ok) - require.Nil(t, leaf) + require.False(t, ok) + require.Equal(t, pol[0], leaf) }) t.Run("neq string in list", func(t *testing.T) { @@ -251,11 +249,16 @@ func TestMatch(t *testing.T) { require.False(t, ok) require.Equal(t, pol[0], leaf) - // TODO: clarify how it behave when the data is missing - pol = MustConstruct(NotEqual(".[1]", literal.String("foo"))) + pol = MustConstruct(NotEqual(".[0]", literal.String("bar"))) ok, leaf = pol.Match(nd) require.True(t, ok) require.Nil(t, leaf) + + // missing data will fail, as not optional + pol = MustConstruct(NotEqual(".[1]", literal.String("foo"))) + ok, leaf = pol.Match(nd) + require.False(t, ok) + require.Equal(t, pol[0], leaf) }) }) @@ -418,11 +421,11 @@ func TestMatch(t *testing.T) { require.False(t, ok) require.Equal(t, pol[0], leaf) - // TODO: clarify how it works on missing data + // missing data will fail, as not optional pol = MustConstruct(Not(Equal(".foobar", literal.Bool(true)))) ok, leaf = pol.Match(nd) - require.True(t, ok) - require.Nil(t, leaf) + require.False(t, ok) + require.Equal(t, MustConstruct(Equal(".foobar", literal.Bool(true)))[0], leaf) }) t.Run("conjunction", func(t *testing.T) {