Files
threshold/internal/servers/controller/auth/testing.go
T

27 lines
1.1 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"
authpb "github.com/hashicorp/boundary/internal/gen/controller/auth"
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 {
reqInfo := authpb.RequestInfo{DisableAuthEntirely: true}
2020-07-22 00:14:28 -04:00
opts := getOpts(opt...)
reqInfo.ScopeIdOverride = opts.withScopeId
if reqInfo.ScopeIdOverride == "" {
reqInfo.ScopeIdOverride = scopeId
2021-03-25 03:15:43 -04:00
}
reqInfo.UserIdOverride = opts.withUserId
if reqInfo.UserIdOverride == "" {
reqInfo.UserIdOverride = "u_auth"
2021-05-04 19:57:35 -05:00
}
requestContext := context.WithValue(context.Background(), requests.ContextRequestInformationKey, &requests.RequestContext{})
return NewVerifierContext(requestContext, iamRepoFn, nil, nil, opts.withKms, &reqInfo)
2020-07-22 00:14:28 -04:00
}