summaryrefslogtreecommitdiff
path: root/internal/mocks
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2023-01-07 11:19:41 +1100
committerGitHub <noreply@github.com>2023-01-07 11:19:41 +1100
commitfc5ea5b4857452bacd39f3b12c8a87ec69b4e76a (patch)
treec67cb9ee005d4929fa5a58a05f28291451985d4e /internal/mocks
parentf223975e7973077ce7d9e37240fd0ef80308ecd6 (diff)
refactor(random): add random provider (#4712)
This adds a random provider which makes usage of random operations mockable, and may allow us in the future to swap out the Cryptographical CPU random generator with dedicated hardware random generators.
Diffstat (limited to 'internal/mocks')
-rw-r--r--internal/mocks/authelia_ctx.go6
-rw-r--r--internal/mocks/gen.go1
-rw-r--r--internal/mocks/random.go195
3 files changed, 202 insertions, 0 deletions
diff --git a/internal/mocks/authelia_ctx.go b/internal/mocks/authelia_ctx.go
index 26a4a876f..b7fef421c 100644
--- a/internal/mocks/authelia_ctx.go
+++ b/internal/mocks/authelia_ctx.go
@@ -16,6 +16,7 @@ import (
"github.com/authelia/authelia/v4/internal/authorization"
"github.com/authelia/authelia/v4/internal/configuration/schema"
"github.com/authelia/authelia/v4/internal/middlewares"
+ "github.com/authelia/authelia/v4/internal/random"
"github.com/authelia/authelia/v4/internal/regulation"
"github.com/authelia/authelia/v4/internal/session"
"github.com/authelia/authelia/v4/internal/templates"
@@ -34,6 +35,7 @@ type MockAutheliaCtx struct {
StorageMock *MockStorage
NotifierMock *MockNotifier
TOTPMock *MockTOTP
+ RandomMock *MockRandom
UserSession *session.UserSession
@@ -98,6 +100,10 @@ func NewMockAutheliaCtx(t *testing.T) *MockAutheliaCtx {
mockAuthelia.TOTPMock = NewMockTOTP(mockAuthelia.Ctrl)
providers.TOTP = mockAuthelia.TOTPMock
+ mockAuthelia.RandomMock = NewMockRandom(mockAuthelia.Ctrl)
+
+ providers.Random = random.NewMathematical()
+
var err error
if providers.Templates, err = templates.New(templates.Config{}); err != nil {
diff --git a/internal/mocks/gen.go b/internal/mocks/gen.go
index 4ec2697f3..3c54c9612 100644
--- a/internal/mocks/gen.go
+++ b/internal/mocks/gen.go
@@ -8,3 +8,4 @@ package mocks
//go:generate mockgen -package mocks -destination totp.go -mock_names Provider=MockTOTP github.com/authelia/authelia/v4/internal/totp Provider
//go:generate mockgen -package mocks -destination storage.go -mock_names Provider=MockStorage github.com/authelia/authelia/v4/internal/storage Provider
//go:generate mockgen -package mocks -destination duo_api.go -mock_names API=MockAPI github.com/authelia/authelia/v4/internal/duo API
+//go:generate mockgen -package mocks -destination random.go -mock_names Provider=MockRandom github.com/authelia/authelia/v4/internal/random Provider
diff --git a/internal/mocks/random.go b/internal/mocks/random.go
new file mode 100644
index 000000000..9bab56ddd
--- /dev/null
+++ b/internal/mocks/random.go
@@ -0,0 +1,195 @@
+// Code generated by MockGen. DO NOT EDIT.
+// Source: github.com/authelia/authelia/v4/internal/random (interfaces: Provider)
+
+// Package mocks is a generated GoMock package.
+package mocks
+
+import (
+ big "math/big"
+ reflect "reflect"
+
+ gomock "github.com/golang/mock/gomock"
+)
+
+// MockRandom is a mock of Provider interface.
+type MockRandom struct {
+ ctrl *gomock.Controller
+ recorder *MockRandomMockRecorder
+}
+
+// MockRandomMockRecorder is the mock recorder for MockRandom.
+type MockRandomMockRecorder struct {
+ mock *MockRandom
+}
+
+// NewMockRandom creates a new mock instance.
+func NewMockRandom(ctrl *gomock.Controller) *MockRandom {
+ mock := &MockRandom{ctrl: ctrl}
+ mock.recorder = &MockRandomMockRecorder{mock}
+ return mock
+}
+
+// EXPECT returns an object that allows the caller to indicate expected use.
+func (m *MockRandom) EXPECT() *MockRandomMockRecorder {
+ return m.recorder
+}
+
+// Bytes mocks base method.
+func (m *MockRandom) Bytes() []byte {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "Bytes")
+ ret0, _ := ret[0].([]byte)
+ return ret0
+}
+
+// Bytes indicates an expected call of Bytes.
+func (mr *MockRandomMockRecorder) Bytes() *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Bytes", reflect.TypeOf((*MockRandom)(nil).Bytes))
+}
+
+// BytesCustom mocks base method.
+func (m *MockRandom) BytesCustom(arg0 int, arg1 []byte) []byte {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "BytesCustom", arg0, arg1)
+ ret0, _ := ret[0].([]byte)
+ return ret0
+}
+
+// BytesCustom indicates an expected call of BytesCustom.
+func (mr *MockRandomMockRecorder) BytesCustom(arg0, arg1 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesCustom", reflect.TypeOf((*MockRandom)(nil).BytesCustom), arg0, arg1)
+}
+
+// BytesCustomErr mocks base method.
+func (m *MockRandom) BytesCustomErr(arg0 int, arg1 []byte) ([]byte, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "BytesCustomErr", arg0, arg1)
+ ret0, _ := ret[0].([]byte)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// BytesCustomErr indicates an expected call of BytesCustomErr.
+func (mr *MockRandomMockRecorder) BytesCustomErr(arg0, arg1 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesCustomErr", reflect.TypeOf((*MockRandom)(nil).BytesCustomErr), arg0, arg1)
+}
+
+// BytesErr mocks base method.
+func (m *MockRandom) BytesErr() ([]byte, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "BytesErr")
+ ret0, _ := ret[0].([]byte)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// BytesErr indicates an expected call of BytesErr.
+func (mr *MockRandomMockRecorder) BytesErr() *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "BytesErr", reflect.TypeOf((*MockRandom)(nil).BytesErr))
+}
+
+// Int mocks base method.
+func (m *MockRandom) Int(arg0 *big.Int) *big.Int {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "Int", arg0)
+ ret0, _ := ret[0].(*big.Int)
+ return ret0
+}
+
+// Int indicates an expected call of Int.
+func (mr *MockRandomMockRecorder) Int(arg0 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Int", reflect.TypeOf((*MockRandom)(nil).Int), arg0)
+}
+
+// IntErr mocks base method.
+func (m *MockRandom) IntErr(arg0 *big.Int) (*big.Int, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "IntErr", arg0)
+ ret0, _ := ret[0].(*big.Int)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// IntErr indicates an expected call of IntErr.
+func (mr *MockRandomMockRecorder) IntErr(arg0 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IntErr", reflect.TypeOf((*MockRandom)(nil).IntErr), arg0)
+}
+
+// Integer mocks base method.
+func (m *MockRandom) Integer(arg0 int) int {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "Integer", arg0)
+ ret0, _ := ret[0].(int)
+ return ret0
+}
+
+// Integer indicates an expected call of Integer.
+func (mr *MockRandomMockRecorder) Integer(arg0 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Integer", reflect.TypeOf((*MockRandom)(nil).Integer), arg0)
+}
+
+// IntegerErr mocks base method.
+func (m *MockRandom) IntegerErr(arg0 int) (int, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "IntegerErr", arg0)
+ ret0, _ := ret[0].(int)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// IntegerErr indicates an expected call of IntegerErr.
+func (mr *MockRandomMockRecorder) IntegerErr(arg0 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IntegerErr", reflect.TypeOf((*MockRandom)(nil).IntegerErr), arg0)
+}
+
+// Read mocks base method.
+func (m *MockRandom) Read(arg0 []byte) (int, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "Read", arg0)
+ ret0, _ := ret[0].(int)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// Read indicates an expected call of Read.
+func (mr *MockRandomMockRecorder) Read(arg0 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Read", reflect.TypeOf((*MockRandom)(nil).Read), arg0)
+}
+
+// StringCustom mocks base method.
+func (m *MockRandom) StringCustom(arg0 int, arg1 string) string {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "StringCustom", arg0, arg1)
+ ret0, _ := ret[0].(string)
+ return ret0
+}
+
+// StringCustom indicates an expected call of StringCustom.
+func (mr *MockRandomMockRecorder) StringCustom(arg0, arg1 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringCustom", reflect.TypeOf((*MockRandom)(nil).StringCustom), arg0, arg1)
+}
+
+// StringCustomErr mocks base method.
+func (m *MockRandom) StringCustomErr(arg0 int, arg1 string) (string, error) {
+ m.ctrl.T.Helper()
+ ret := m.ctrl.Call(m, "StringCustomErr", arg0, arg1)
+ ret0, _ := ret[0].(string)
+ ret1, _ := ret[1].(error)
+ return ret0, ret1
+}
+
+// StringCustomErr indicates an expected call of StringCustomErr.
+func (mr *MockRandomMockRecorder) StringCustomErr(arg0, arg1 interface{}) *gomock.Call {
+ mr.mock.ctrl.T.Helper()
+ return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "StringCustomErr", reflect.TypeOf((*MockRandom)(nil).StringCustomErr), arg0, arg1)
+}