-
Notifications
You must be signed in to change notification settings - Fork 2
/
guard_mock.go
78 lines (55 loc) · 1.72 KB
/
guard_mock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright © 2014-2023 Thomas Rabaix <thomas.rabaix@gmail.com>.
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file.
package guard
import (
"net/http"
"github.com/stretchr/testify/mock"
)
type MockedAuthenticator struct {
mock.Mock
}
func (m *MockedAuthenticator) GetCredentials(req *http.Request) (interface{}, error) {
args := m.Mock.Called(req)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(interface{}), args.Error(1)
}
func (m *MockedAuthenticator) GetUser(credentials interface{}) (GuardUser, error) {
args := m.Mock.Called(credentials)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(GuardUser), args.Error(1)
}
func (m *MockedAuthenticator) CheckCredentials(credentials interface{}, user GuardUser) error {
args := m.Mock.Called(credentials, user)
return args.Error(0)
}
func (m *MockedAuthenticator) CreateAuthenticatedToken(u GuardUser) (GuardToken, error) {
args := m.Mock.Called(u)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(GuardToken), args.Error(1)
}
func (m *MockedAuthenticator) OnAuthenticationFailure(req *http.Request, res http.ResponseWriter, err error) bool {
args := m.Mock.Called(req, res, err)
return args.Bool(0)
}
func (m *MockedAuthenticator) OnAuthenticationSuccess(req *http.Request, res http.ResponseWriter, token GuardToken) bool {
args := m.Mock.Called(req, res, token)
return args.Bool(0)
}
type MockedManager struct {
mock.Mock
}
func (m *MockedManager) GetUser(username string) (GuardUser, error) {
args := m.Mock.Called(username)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(GuardUser), args.Error(1)
}