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

58 lines
1.7 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package iam
import (
"context"
"testing"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/proto"
)
func Test_LookupScope(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
repo := TestRepo(t, conn, wrapper)
t.Run("valid-scope", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
w := db.New(conn)
org, _ := TestScopes(t, repo)
user := TestUser(t, repo, org.PublicId)
foundScope, err := LookupScope(context.Background(), w, user)
require.NoError(err)
assert.Equal(foundScope.PublicId, user.ScopeId)
user2 := AllocUser()
user2.PublicId = user.PublicId
foundScope, err = LookupScope(context.Background(), w, user)
require.NoError(err)
assert.True(proto.Equal(foundScope, org))
})
t.Run("bad-scope", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
w := db.New(conn)
org, _ := TestScopes(t, repo)
user := TestUser(t, repo, org.PublicId)
s, err := LookupScope(context.Background(), nil, user)
require.Error(err)
assert.Nil(s)
assert.Equal("iam.LookupScope: nil reader: parameter violation: error #100", err.Error())
s, err = LookupScope(context.Background(), w, nil)
assert.Nil(s)
assert.Equal("iam.LookupScope: missing resource: parameter violation: error #100", err.Error())
user2 := AllocUser()
s, err = LookupScope(context.Background(), w, &user2)
assert.Nil(s)
assert.Contains(err.Error(), "iam.LookupScope: missing public id: parameter violation: error #100")
})
}