github.com/verrazzano/verrazzano@v1.7.1/authproxy/internal/testutil/testauth/authenticator.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package testauth 5 6 import ( 7 "context" 8 "net/http" 9 10 "github.com/verrazzano/verrazzano/authproxy/src/auth" 11 ) 12 13 // FakeAuthenticator returns a fake implementation of the Authenticator interface 14 type FakeAuthenticator struct { 15 authenticateTokenFunc func() (bool, error) 16 authenticateRequestFunc func() (bool, error) 17 } 18 19 // NewFakeAuthenticator returns a new FakeAuthenticator object with authentication set to true 20 func NewFakeAuthenticator() *FakeAuthenticator { 21 return &FakeAuthenticator{ 22 authenticateTokenFunc: AuthenticateTrue, 23 authenticateRequestFunc: AuthenticateTrue, 24 } 25 } 26 27 func (f *FakeAuthenticator) AuthenticateToken(_ context.Context, _ string) (bool, error) { 28 return f.authenticateTokenFunc() 29 } 30 func (f *FakeAuthenticator) AuthenticateRequest(_ *http.Request, _ http.ResponseWriter) (bool, error) { 31 return f.authenticateRequestFunc() 32 } 33 func (f *FakeAuthenticator) SetCallbackURL(_ string) {} 34 35 func (f *FakeAuthenticator) SetTokenFunc(fun func() (bool, error)) { 36 f.authenticateTokenFunc = fun 37 } 38 39 func (f *FakeAuthenticator) SetRequestFunc(fun func() (bool, error)) { 40 f.authenticateRequestFunc = fun 41 } 42 43 func AuthenticateTrue() (bool, error) { 44 return true, nil 45 } 46 47 func AuthenticateFalse() (bool, error) { 48 return false, nil 49 } 50 51 var _ auth.Authenticator = &FakeAuthenticator{}