2021-06-01 14:12:34 -05:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-06-01 14:12:34 -05:00
|
|
|
package oidc
|
|
|
|
|
|
|
|
|
|
import (
|
2021-07-29 18:52:56 -06:00
|
|
|
"context"
|
2021-06-01 14:12:34 -05:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func Test_ManagedGroups_RepoValidate(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
2021-07-29 18:52:56 -06:00
|
|
|
ctx := context.TODO()
|
2021-06-01 14:12:34 -05:00
|
|
|
assert := assert.New(t)
|
|
|
|
|
const op = "test"
|
|
|
|
|
mg := AllocManagedGroup()
|
|
|
|
|
t.Run("empty auth method", func(t *testing.T) {
|
2021-07-29 18:52:56 -06:00
|
|
|
assert.Contains(mg.validate(ctx, op).Error(), errors.New(ctx, errors.InvalidParameter, op, "missing auth method id").Error(), errors.WithoutEvent())
|
2021-06-01 14:12:34 -05:00
|
|
|
})
|
|
|
|
|
t.Run("empty filter", func(t *testing.T) {
|
|
|
|
|
mg.AuthMethodId = "amoidc_1234567890"
|
2021-07-29 18:52:56 -06:00
|
|
|
assert.Contains(mg.validate(ctx, op).Error(), errors.New(ctx, errors.InvalidParameter, op, "missing filter").Error(), errors.WithoutEvent())
|
2021-06-01 14:12:34 -05:00
|
|
|
})
|
|
|
|
|
t.Run("bad filter", func(t *testing.T) {
|
|
|
|
|
mg.AuthMethodId = "amoidc_1234567890"
|
|
|
|
|
mg.Filter = "foobar"
|
2021-07-29 18:52:56 -06:00
|
|
|
assert.Contains(mg.validate(ctx, op).Error(), errors.New(ctx, errors.InvalidParameter, op, "error evaluating filter expression").Error(), errors.WithoutEvent())
|
2021-06-01 14:12:34 -05:00
|
|
|
})
|
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
|
|
|
mg.AuthMethodId = "amoidc_1234567890"
|
2021-06-04 09:44:57 -05:00
|
|
|
mg.Filter = TestFakeManagedGroupFilter
|
2021-07-29 18:52:56 -06:00
|
|
|
assert.NoError(mg.validate(ctx, op))
|
2021-06-01 14:12:34 -05:00
|
|
|
})
|
|
|
|
|
}
|