2022-10-25 21:33:31 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-07-07 07:44:49 -07:00
|
|
|
package authtoken
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
2020-11-16 10:39:18 -08:00
|
|
|
"time"
|
2020-07-07 07:44:49 -07:00
|
|
|
|
2022-10-25 21:33:31 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/auth/password"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/iam"
|
2020-07-07 07:44:49 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Test_GetOpts provides unit tests for GetOpts and all the options
|
|
|
|
|
func Test_GetOpts(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
2020-11-16 10:39:18 -08:00
|
|
|
|
2020-07-07 07:44:49 -07:00
|
|
|
t.Run("withTokenValue", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getOpts(withTokenValue())
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withTokenValue = true
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2020-11-16 10:39:18 -08:00
|
|
|
|
|
|
|
|
t.Run("WithTokenTimeToLiveDuration", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getOpts(WithTokenTimeToLiveDuration(1 * time.Hour))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withTokenTimeToLiveDuration = 1 * time.Hour
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("WithTokenTimeToLiveStale", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getOpts(WithTokenTimeToStaleDuration(1 * time.Hour))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withTokenTimeToStaleDuration = 1 * time.Hour
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2021-04-08 20:54:32 -04:00
|
|
|
|
|
|
|
|
t.Run("withStatus", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getOpts(WithStatus(IssuedStatus))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withStatus = IssuedStatus
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("WithPublicId", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getOpts(WithPublicId("test-id"))
|
|
|
|
|
testOpts := getDefaultOptions()
|
|
|
|
|
testOpts.withPublicId = "test-id"
|
|
|
|
|
assert.Equal(opts, testOpts)
|
|
|
|
|
})
|
2022-10-25 21:33:31 -04:00
|
|
|
|
|
|
|
|
t.Run("WithPasswordOptions", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getDefaultOptions()
|
|
|
|
|
assert.Empty(opts.withPasswordOptions)
|
|
|
|
|
opts = getOpts(WithPasswordOptions(password.WithName("foobar")))
|
|
|
|
|
assert.NotEmpty(opts.withPasswordOptions)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
t.Run("WithIamOptions", func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
opts := getDefaultOptions()
|
|
|
|
|
assert.Empty(opts.withIamOptions)
|
|
|
|
|
opts = getOpts(WithIamOptions(iam.WithName("foobar")))
|
|
|
|
|
assert.NotEmpty(opts.withIamOptions)
|
|
|
|
|
})
|
2020-07-07 07:44:49 -07:00
|
|
|
}
|