Files
threshold/internal/auth/testing.go
T

26 lines
1.0 KiB
Go
Raw Normal View History

2020-07-22 00:14:28 -04:00
package auth
2021-03-25 03:15:43 -04:00
import (
"context"
2021-05-04 19:57:35 -05:00
"github.com/hashicorp/boundary/internal/requests"
2021-03-25 03:15:43 -04:00
"github.com/hashicorp/boundary/internal/servers/controller/common"
)
2020-07-22 00:14:28 -04:00
2021-05-04 19:57:35 -05:00
// DisabledAuthTestContext is meant for testing, and uses a context that has
// auth checking entirely disabled. Supported options: WithScopeId an WithUserId
// are used directly; WithKms is passed through into the verifier context.
2021-03-25 03:15:43 -04:00
func DisabledAuthTestContext(iamRepoFn common.IamRepoFactory, scopeId string, opt ...Option) context.Context {
2020-07-22 00:14:28 -04:00
reqInfo := RequestInfo{DisableAuthEntirely: true}
opts := getOpts(opt...)
2020-09-14 12:30:11 -04:00
reqInfo.scopeIdOverride = opts.withScopeId
2021-03-25 03:15:43 -04:00
if reqInfo.scopeIdOverride == "" {
reqInfo.scopeIdOverride = scopeId
}
reqInfo.userIdOverride = opts.withUserId
2021-05-04 19:57:35 -05:00
if reqInfo.userIdOverride == "" {
reqInfo.userIdOverride = "u_auth"
}
requestContext := context.WithValue(context.Background(), requests.ContextRequestInformationKey, &requests.RequestContext{})
return NewVerifierContext(requestContext, nil, iamRepoFn, nil, nil, opts.withKms, reqInfo)
2020-07-22 00:14:28 -04:00
}