From 975ab0dff7e42aaff5dc5bedeeb8eb5cd2ad5c96 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Wed, 26 May 2021 20:18:42 +0300 Subject: [PATCH] [#561] acl: Add tests for request meta header traverser Signed-off-by: Alex Vanin --- pkg/services/object/acl/acl_test.go | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 pkg/services/object/acl/acl_test.go diff --git a/pkg/services/object/acl/acl_test.go b/pkg/services/object/acl/acl_test.go new file mode 100644 index 000000000..468fbccdb --- /dev/null +++ b/pkg/services/object/acl/acl_test.go @@ -0,0 +1,36 @@ +package acl + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/v2/acl" + acltest "github.com/nspcc-dev/neofs-api-go/v2/acl/test" + "github.com/nspcc-dev/neofs-api-go/v2/session" + sessiontest "github.com/nspcc-dev/neofs-api-go/v2/session/test" + "github.com/stretchr/testify/require" +) + +func TestOriginalTokens(t *testing.T) { + sToken := sessiontest.GenerateSessionToken(false) + bToken := acltest.GenerateBearerToken(false) + + for i := 0; i < 10; i++ { + metaHeaders := testGenerateMetaHeader(uint32(i), bToken, sToken) + require.Equal(t, sToken, originalSessionToken(metaHeaders), i) + require.Equal(t, bToken, originalBearerToken(metaHeaders), i) + } +} + +func testGenerateMetaHeader(depth uint32, b *acl.BearerToken, s *session.SessionToken) *session.RequestMetaHeader { + metaHeader := new(session.RequestMetaHeader) + metaHeader.SetBearerToken(b) + metaHeader.SetSessionToken(s) + + for i := uint32(0); i < depth; i++ { + link := metaHeader + metaHeader = new(session.RequestMetaHeader) + metaHeader.SetOrigin(link) + } + + return metaHeader +}