Files
threshold/internal/iam/resource_test.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

57 lines
1.7 KiB
Go
Raw Normal View History

2020-08-10 17:15:02 -04:00
// Copyright (c) HashiCorp, Inc.
2020-12-23 11:00:00 -08:00
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2020-06-04 20:05:08 -04:00
package iam
import (
"context"
"testing"
2020-08-10 17:15:02 -04:00
"github.com/hashicorp/boundary/internal/db"
2020-06-04 20:05:08 -04:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2020-06-04 20:05:08 -04:00
"google.golang.org/protobuf/proto"
)
func Test_LookupScope(t *testing.T) {
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
2020-08-19 16:47:18 -04:00
wrapper := db.TestWrapper(t)
repo := TestRepo(t, conn, wrapper)
2020-06-04 20:05:08 -04:00
t.Run("valid-scope", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
2020-06-04 20:05:08 -04:00
w := db.New(conn)
2020-08-19 16:47:18 -04:00
org, _ := TestScopes(t, repo)
user := TestUser(t, repo, org.PublicId)
2020-06-04 20:05:08 -04:00
foundScope, err := LookupScope(context.Background(), w, user)
require.NoError(err)
2020-06-04 20:05:08 -04:00
assert.Equal(foundScope.PublicId, user.ScopeId)
user2 := AllocUser()
2020-06-04 20:05:08 -04:00
user2.PublicId = user.PublicId
foundScope, err = LookupScope(context.Background(), w, user)
require.NoError(err)
2020-06-04 20:05:08 -04:00
assert.True(proto.Equal(foundScope, org))
})
t.Run("bad-scope", func(t *testing.T) {
assert, require := assert.New(t), require.New(t)
2020-06-04 20:05:08 -04:00
w := db.New(conn)
2020-08-19 16:47:18 -04:00
org, _ := TestScopes(t, repo)
user := TestUser(t, repo, org.PublicId)
2020-06-04 20:05:08 -04:00
s, err := LookupScope(context.Background(), nil, user)
require.Error(err)
2020-06-04 20:05:08 -04:00
assert.Nil(s)
2020-12-23 11:00:00 -08:00
assert.Equal("iam.LookupScope: nil reader: parameter violation: error #100", err.Error())
2020-06-04 20:05:08 -04:00
s, err = LookupScope(context.Background(), w, nil)
assert.Nil(s)
2020-12-23 11:00:00 -08:00
assert.Equal("iam.LookupScope: missing resource: parameter violation: error #100", err.Error())
2020-06-04 20:05:08 -04:00
user2 := AllocUser()
2020-06-04 20:05:08 -04:00
s, err = LookupScope(context.Background(), w, &user2)
assert.Nil(s)
2020-12-23 11:00:00 -08:00
assert.Contains(err.Error(), "iam.LookupScope: missing public id: parameter violation: error #100")
2020-06-04 20:05:08 -04:00
})
}