Skip to content

Commit d78a7cd

Browse files
build: fix mocks (#181)
1 parent 6bcd25c commit d78a7cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+667
-704
lines changed

.github/workflows/format.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
2525
with:
26-
go-version: 1.21
26+
go-version: 1.23
2727
- run: make format
2828
- name: Indicate formatting issues
2929
run: git diff HEAD --exit-code --color

.github/workflows/generate.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
2525
with:
26-
go-version: 1.21
26+
go-version: 1.23
2727
- run: make generate
2828
- name: Indicate generation issues
2929
run: git diff HEAD --exit-code --color

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ jobs:
2323
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2424
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
2525
with:
26-
go-version: 1.22
26+
go-version: 1.23
2727
- run: make test

access_request_handler_test.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestNewAccessRequest(t *testing.T) {
2626
name string
2727
header http.Header
2828
form url.Values
29-
mock func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient)
29+
mock func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient)
3030
method string
3131
expectErr error
3232
expectStrErr string
@@ -49,7 +49,7 @@ func TestNewAccessRequest(t *testing.T) {
4949
consts.FormParameterClientID: {"bar"},
5050
consts.FormParameterGrantType: {"foo"},
5151
},
52-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
52+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
5353
store.EXPECT().GetClient(ctx, gomock.Eq("bar")).Return(&DefaultClient{ID: "bar"}, nil)
5454
},
5555
expectErr: ErrInvalidRequest,
@@ -77,7 +77,7 @@ func TestNewAccessRequest(t *testing.T) {
7777
},
7878
expectErr: ErrInvalidClient,
7979
expectStrErr: "Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method).",
80-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
80+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
8181
store.EXPECT().GetClient(gomock.Any(), gomock.Eq("foo")).Return(nil, errors.New(""))
8282
},
8383
handlers: func(handler *mock.MockTokenEndpointHandler) TokenEndpointHandlers {
@@ -107,7 +107,7 @@ func TestNewAccessRequest(t *testing.T) {
107107
},
108108
expectErr: ErrInvalidClient,
109109
expectStrErr: "Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). crypto/bcrypt: hashedPassword is not the hash of the given password",
110-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
110+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
111111
store.EXPECT().GetClient(gomock.Any(), gomock.Eq("foo")).Return(client, nil)
112112
client.Public = false
113113
client.ClientSecret = testClientSecretFoo
@@ -127,7 +127,7 @@ func TestNewAccessRequest(t *testing.T) {
127127
},
128128
expectErr: ErrServerError,
129129
expectStrErr: "The authorization server encountered an unexpected condition that prevented it from fulfilling the request.",
130-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
130+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
131131
store.EXPECT().GetClient(gomock.Any(), gomock.Eq("foo")).Return(client, nil)
132132
client.Public = false
133133
client.ClientSecret = testClientSecretFoo
@@ -146,7 +146,7 @@ func TestNewAccessRequest(t *testing.T) {
146146
form: url.Values{
147147
consts.FormParameterGrantType: {"foo"},
148148
},
149-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
149+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
150150
store.EXPECT().GetClient(gomock.Any(), gomock.Eq("foo")).Return(client, nil)
151151
client.Public = false
152152
client.ClientSecret = testClientSecretFoo
@@ -173,7 +173,7 @@ func TestNewAccessRequest(t *testing.T) {
173173
form: url.Values{
174174
consts.FormParameterGrantType: {"foo"},
175175
},
176-
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, hasher *mock.MockHasher, client *DefaultClient) {
176+
mock: func(ctx gomock.Matcher, handler *mock.MockTokenEndpointHandler, store *mock.MockStorage, client *DefaultClient) {
177177
store.EXPECT().GetClient(gomock.Any(), gomock.Eq("foo")).Return(client, nil)
178178
client.Public = true
179179
handler.EXPECT().HandleTokenEndpointRequest(gomock.Any(), gomock.Any()).Return(nil)
@@ -200,7 +200,6 @@ func TestNewAccessRequest(t *testing.T) {
200200
handler := mock.NewMockTokenEndpointHandler(ctrl)
201201
handler.EXPECT().CanHandleTokenEndpointRequest(gomock.Any(), gomock.Any()).Return(true).AnyTimes()
202202
handler.EXPECT().CanSkipClientAuth(gomock.Any(), gomock.Any()).Return(false).AnyTimes()
203-
hasher := mock.NewMockHasher(ctrl)
204203
defer ctrl.Finish()
205204

206205
ctx := gomock.AssignableToTypeOf(context.WithValue(context.TODO(), ContextKey("test"), nil))
@@ -217,7 +216,7 @@ func TestNewAccessRequest(t *testing.T) {
217216
}
218217

219218
if tc.mock != nil {
220-
tc.mock(ctx, handler, store, hasher, client)
219+
tc.mock(ctx, handler, store, client)
221220
}
222221

223222
if tc.handlers != nil {

generate-mocks.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
${MOCKGEN:-mockgen} -package mock -destination testing/mock/rw.go net/http ResponseWriter
44

5-
${MOCKGEN:-mockgen} -package mock -destination testing/mock/hash.go authelia.com/provider/oauth2 Hasher
65
${MOCKGEN:-mockgen} -package mock -destination testing/mock/introspector.go authelia.com/provider/oauth2 TokenIntrospector
76
${MOCKGEN:-mockgen} -package mock -destination testing/mock/client.go authelia.com/provider/oauth2 Client
87
${MOCKGEN:-mockgen} -package mock -destination testing/mock/client_secret.go authelia.com/provider/oauth2 ClientSecret
@@ -18,7 +17,7 @@ ${MOCKGEN:-mockgen} -package mock -destination testing/mock/transactional.go aut
1817
${MOCKGEN:-mockgen} -package mock -destination testing/mock/oauth2_storage.go authelia.com/provider/oauth2/handler/oauth2 CoreStorage
1918
${MOCKGEN:-mockgen} -package mock -destination testing/mock/oauth2_device_auth_storage.go -mock_names Storage=MockRFC8628Storage authelia.com/provider/oauth2/handler/rfc8628 Storage
2019
${MOCKGEN:-mockgen} -package mock -destination testing/mock/openid_id_token_storage.go authelia.com/provider/oauth2/handler/openid OpenIDConnectRequestStorage
21-
${MOCKGEN:-mockgen} -package mock -destination testing/mock/pkce_storage.go authelia.com/provider/oauth2/handler/pkce PKCERequestStorage
20+
${MOCKGEN:-mockgen} -package mock -destination testing/mock/pkce_storage.go -mock_names Storage=MockPKCERequestStorage authelia.com/provider/oauth2/handler/pkce Storage
2221
${MOCKGEN:-mockgen} -package mock -destination testing/mock/authorize_code_storage.go authelia.com/provider/oauth2/handler/oauth2 AuthorizeCodeStorage
2322
${MOCKGEN:-mockgen} -package mock -destination testing/mock/oauth2_auth_jwt_storage.go authelia.com/provider/oauth2/handler/rfc7523 RFC7523KeyStorage
2423
${MOCKGEN:-mockgen} -package mock -destination testing/mock/access_token_storage.go authelia.com/provider/oauth2/handler/oauth2 AccessTokenStorage

generate.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
package oauth2
55

6-
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/hash.go authelia.com/provider/oauth2 Hasher
76
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/storage.go authelia.com/provider/oauth2 Storage
87
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/transactional.go authelia.com/provider/oauth2/storage Transactional
98
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/oauth2_storage.go authelia.com/provider/oauth2/handler/oauth2 CoreStorage
@@ -20,7 +19,7 @@ package oauth2
2019
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/refresh_token_strategy.go authelia.com/provider/oauth2/handler/oauth2 ReyfreshTokenStrategy
2120
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/authorize_code_strategy.go authelia.com/provider/oauth2/handler/oauth2 AuthorizeCodeStrategy
2221
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/id_token_strategy.go authelia.com/provider/oauth2/handler/openid OpenIDConnectTokenStrategy
23-
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/pkce_storage_strategy.go authelia.com/provider/oauth2/handler/pkce PKCERequestStorage
22+
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/pkce_storage_strategy.go -mock_names Storage=MockPKCERequestStorage authelia.com/provider/oauth2/handler/pkce Storage
2423
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/authorize_handler.go authelia.com/provider/oauth2 AuthorizeEndpointHandler
2524
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/revoke_handler.go authelia.com/provider/oauth2 RevocationHandler
2625
//go:generate go run go.uber.org/mock/mockgen -package internal -destination internal/token_handler.go authelia.com/provider/oauth2 TokenEndpointHandler

testing/mock/access_request.go

+37-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)