Files
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

153 lines
3.9 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package roles_test
import (
"context"
"encoding/json"
"testing"
"time"
"repo.anhonesthost.net/CyberCoveLLC/threshold/globals"
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api"
pb "repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api/resources/roles"
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api/resources/scopes"
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/wrapper"
"github.com/hashicorp/eventlogger"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
func TestRoles(t *testing.T) {
ctx := context.Background()
now := time.Now()
pbNow := timestamppb.Now()
wrapper := wrapper.TestWrapper(t)
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
tests := []struct {
name string
in *eventlogger.Event
want *eventlogger.Event
}{
{
name: "role",
in: &eventlogger.Event{
Type: "test",
CreatedAt: now,
Payload: &pb.Role{
Id: "id",
ScopeId: "scope-id",
Scope: &scopes.ScopeInfo{
Id: "scope-id",
Type: "scope-type",
Name: "scope-name",
Description: "scope-description",
ParentScopeId: "scope-parent-scope-id",
},
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "description"},
CreatedTime: pbNow,
UpdatedTime: pbNow,
Version: 0,
GrantScopeIds: []string{
globals.GrantScopeThis,
"grant-scope-id",
},
PrincipalIds: []string{
"principal-id",
},
Principals: []*pb.Principal{
{
Id: "principal-id",
Type: "principal-type",
ScopeId: "principal-scope-id",
},
},
GrantStrings: []string{
"grand-string",
},
Grants: []*pb.Grant{
{
Raw: "raw",
Canonical: "canonical",
Json: &pb.GrantJson{
Id: "grant-json-id",
Type: "grant-json-type",
Actions: []string{"action"},
},
},
},
AuthorizedActions: []string{"action-1"},
},
},
want: &eventlogger.Event{
Type: "test",
CreatedAt: now,
Payload: &pb.Role{
Id: "id",
ScopeId: "scope-id",
Scope: &scopes.ScopeInfo{
Id: "scope-id",
Type: "scope-type",
Name: "scope-name",
Description: "scope-description",
ParentScopeId: "scope-parent-scope-id",
},
Name: &wrapperspb.StringValue{Value: "name"},
Description: &wrapperspb.StringValue{Value: "description"},
CreatedTime: pbNow,
UpdatedTime: pbNow,
Version: 0,
GrantScopeIds: []string{
globals.GrantScopeThis,
"grant-scope-id",
},
PrincipalIds: []string{
"principal-id",
},
Principals: []*pb.Principal{
{
Id: "principal-id",
Type: "principal-type",
ScopeId: "principal-scope-id",
},
},
GrantStrings: []string{
"grand-string",
},
Grants: []*pb.Grant{
{
Raw: "raw",
Canonical: "canonical",
Json: &pb.GrantJson{
Id: "grant-json-id",
Type: "grant-json-type",
Actions: []string{"action"},
},
},
},
AuthorizedActions: []string{"action-1"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
got, err := testEncryptingFilter.Process(ctx, tt.in)
require.NoError(err)
require.NotNil(got)
gotJSON, err := json.Marshal(got)
require.NoError(err)
wantJSON, err := json.Marshal(tt.want)
require.NoError(err)
assert.JSONEq(string(wantJSON), string(gotJSON))
})
}
}