Removed session memstore, mocked it in tests
Updated mocked notification service
This commit is contained in:
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_changePasswordForm_setValues(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -34,8 +32,8 @@ func Test_changePasswordForm_setValues(t *testing.T) {
|
||||
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
authService = prepareClientAuthService(ctx, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authService = prepareClientAuthService(ctx, user)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
payload := map[string]string{"key": "value"}
|
||||
@@ -50,9 +48,8 @@ func Test_changePasswordForm_setValues(t *testing.T) {
|
||||
|
||||
func Test_changePasswordProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -60,8 +57,6 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
rq = require.New(t)
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
@@ -132,11 +127,13 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.changePasswordProc(authReq)
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@@ -23,9 +22,8 @@ type (
|
||||
|
||||
func Test_loginForm_setValues(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -41,8 +39,8 @@ func Test_loginForm_setValues(t *testing.T) {
|
||||
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
authService = prepareClientAuthService(ctx, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authService = prepareClientAuthService(ctx, user)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
payload := map[string]string{"key": "value"}
|
||||
@@ -61,9 +59,8 @@ func Test_loginForm_setValues(t *testing.T) {
|
||||
|
||||
func Test_loginProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -72,8 +69,6 @@ func Test_loginProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
@@ -163,6 +158,8 @@ func Test_loginProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
@@ -170,7 +167,7 @@ func Test_loginProc(t *testing.T) {
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.loginProc(authReq)
|
||||
|
||||
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_logoutProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -36,7 +34,7 @@ func Test_logoutProc(t *testing.T) {
|
||||
service.CurrentSettings.Auth.Internal.Enabled = true
|
||||
|
||||
authService = &authServiceMocked{}
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
req.PostForm = url.Values{}
|
||||
@@ -44,7 +42,6 @@ func Test_logoutProc(t *testing.T) {
|
||||
authReq.Session.Values = map[interface{}]interface{}{"key": url.Values{"key": []string{"value"}}}
|
||||
|
||||
err := authHandlers.logoutProc(authReq)
|
||||
|
||||
rq.NoError(err)
|
||||
rq.Empty(authReq.Session.Values)
|
||||
rq.Empty(authReq.AuthUser)
|
||||
|
||||
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_mfaProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -27,8 +25,6 @@ func Test_mfaProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
@@ -194,6 +190,8 @@ func Test_mfaProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
@@ -201,7 +199,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.mfaProc(authReq)
|
||||
|
||||
@@ -9,16 +9,14 @@ import (
|
||||
|
||||
"github.com/cortezaproject/corteza-server/auth/request"
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
Form: url.Values{},
|
||||
@@ -31,8 +29,6 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -66,9 +62,11 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = &AuthHandlers{
|
||||
Log: zap.NewNop(),
|
||||
AuthService: authService,
|
||||
@@ -91,9 +89,8 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
|
||||
func Test_oauth2AuthorizeSuccessSetParams(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
Form: url.Values{},
|
||||
@@ -115,7 +112,7 @@ func Test_oauth2AuthorizeSuccessSetParams(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authReq.Session.Values["oauth2AuthParams"] = url.Values{"foo": []string{"bar"}}
|
||||
|
||||
authHandlers = &AuthHandlers{
|
||||
|
||||
@@ -11,15 +11,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_requestPasswordResetForm(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
URL: &url.URL{},
|
||||
@@ -34,7 +32,7 @@ func Test_requestPasswordResetForm(t *testing.T) {
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
payload := map[string]string{"foo": "bar"}
|
||||
@@ -49,9 +47,8 @@ func Test_requestPasswordResetForm(t *testing.T) {
|
||||
|
||||
func Test_resetPasswordForm(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
URL: &url.URL{},
|
||||
@@ -62,8 +59,6 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -106,13 +101,15 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
// unset so we get to the main functionality
|
||||
@@ -131,9 +128,8 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
|
||||
func Test_requestPasswordReset(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -142,8 +138,6 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -177,6 +171,8 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
@@ -184,7 +180,7 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.requestPasswordResetProc(authReq)
|
||||
@@ -199,9 +195,8 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
|
||||
func Test_requestPasswordProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{}
|
||||
|
||||
@@ -210,8 +205,6 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -245,9 +238,11 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.resetPasswordProc(authReq)
|
||||
|
||||
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_profileForm(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
URL: &url.URL{},
|
||||
@@ -35,7 +33,7 @@ func Test_profileForm(t *testing.T) {
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
userForm := map[string]string{
|
||||
@@ -56,9 +54,8 @@ func Test_profileForm(t *testing.T) {
|
||||
|
||||
func Test_profileFormProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
PostForm: url.Values{},
|
||||
@@ -70,8 +67,6 @@ func Test_profileFormProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -184,13 +179,15 @@ func Test_profileFormProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
authHandlers.UserService = userService
|
||||
|
||||
|
||||
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/request"
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_securityForm(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
URL: &url.URL{},
|
||||
@@ -33,7 +31,7 @@ func Test_securityForm(t *testing.T) {
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.securityForm(authReq)
|
||||
@@ -46,9 +44,8 @@ func Test_securityForm(t *testing.T) {
|
||||
|
||||
func Test_securityProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
PostForm: url.Values{},
|
||||
@@ -59,8 +56,6 @@ func Test_securityProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -99,13 +94,15 @@ func Test_securityProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
authReq.Session.Values = map[interface{}]interface{}{"totpSecret": "SECRET_VALUE"}
|
||||
@@ -128,9 +125,8 @@ func Test_securityProc(t *testing.T) {
|
||||
|
||||
func Test_securityProcDisableEmailOTPSuccess(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
Form: url.Values{},
|
||||
@@ -154,7 +150,7 @@ func Test_securityProcDisableEmailOTPSuccess(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
authReq.Session.Values = map[interface{}]interface{}{"totpSecret": "SECRET_VALUE"}
|
||||
|
||||
@@ -10,15 +10,13 @@ import (
|
||||
"github.com/cortezaproject/corteza-server/auth/settings"
|
||||
"github.com/cortezaproject/corteza-server/system/service"
|
||||
"github.com/cortezaproject/corteza-server/system/types"
|
||||
"github.com/quasoft/memstore"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func Test_signupForm(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
URL: &url.URL{},
|
||||
@@ -33,7 +31,7 @@ func Test_signupForm(t *testing.T) {
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
userForm := map[string]string{
|
||||
@@ -53,9 +51,8 @@ func Test_signupForm(t *testing.T) {
|
||||
|
||||
func Test_signupProc(t *testing.T) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
memStore = memstore.NewMemStore()
|
||||
user = makeMockUser(ctx)
|
||||
ctx = context.Background()
|
||||
user = makeMockUser(ctx)
|
||||
|
||||
req = &http.Request{
|
||||
PostForm: url.Values{},
|
||||
@@ -66,8 +63,6 @@ func Test_signupProc(t *testing.T) {
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -183,13 +178,15 @@ func Test_signupProc(t *testing.T) {
|
||||
|
||||
for _, tc := range tcc {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
// reset from previous
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user, memStore)
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
err := authHandlers.signupProc(authReq)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"github.com/go-oauth2/oauth2/v4/server"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/markbates/goth"
|
||||
"github.com/quasoft/memstore"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
@@ -41,6 +40,13 @@ type (
|
||||
opt options.AuthOpt
|
||||
}
|
||||
|
||||
mockSession struct {
|
||||
Options *sessions.Options
|
||||
get func(r *http.Request, name string) (*sessions.Session, error)
|
||||
new func(r *http.Request, name string) (*sessions.Session, error)
|
||||
save func(r *http.Request, w http.ResponseWriter, s *sessions.Session) error
|
||||
}
|
||||
|
||||
oauth2ServiceMocked struct {
|
||||
getRedirectURI func(req *server.AuthorizeRequest, data map[string]interface{}) (string, error)
|
||||
checkResponseType func(rt oauth2.ResponseType) bool
|
||||
@@ -250,18 +256,31 @@ func (ma mockedAuthService) ValidateTOTP(ctx context.Context, code string) (err
|
||||
//
|
||||
// Mocking notification service
|
||||
//
|
||||
func (m mockNotificationService) EmailConfirmation(ctx context.Context, lang string, emailAddress string, url string) error {
|
||||
func (m mockNotificationService) EmailConfirmation(ctx context.Context, emailAddress string, token string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m mockNotificationService) PasswordReset(ctx context.Context, lang string, emailAddress string, url string) error {
|
||||
func (m mockNotificationService) PasswordReset(ctx context.Context, emailAddress string, token string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m mockNotificationService) EmailOTP(ctx context.Context, lang string, emailAddress string, otp string) error {
|
||||
func (m mockNotificationService) EmailOTP(ctx context.Context, emailAddress string, code string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
// Mocking gorilla session
|
||||
//
|
||||
func (ms mockSession) Get(r *http.Request, name string) (*sessions.Session, error) {
|
||||
return ms.get(r, name)
|
||||
}
|
||||
func (ms mockSession) New(r *http.Request, name string) (*sessions.Session, error) {
|
||||
return ms.new(r, name)
|
||||
}
|
||||
func (ms mockSession) Save(r *http.Request, w http.ResponseWriter, s *sessions.Session) error {
|
||||
return ms.save(r, w, s)
|
||||
}
|
||||
|
||||
//
|
||||
// Helpers
|
||||
//
|
||||
@@ -292,7 +311,7 @@ func makeMockUser(ctx context.Context) *types.User {
|
||||
return u
|
||||
}
|
||||
|
||||
func prepareClientAuthReq(ctx context.Context, req *http.Request, user *types.User, memStore *memstore.MemStore) *request.AuthReq {
|
||||
func prepareClientAuthReq(ctx context.Context, req *http.Request, user *types.User) *request.AuthReq {
|
||||
s := &settings.Settings{}
|
||||
s.MultiFactor.EmailOTP.Enabled = true
|
||||
s.MultiFactor.EmailOTP.Enforced = true
|
||||
@@ -300,16 +319,23 @@ func prepareClientAuthReq(ctx context.Context, req *http.Request, user *types.Us
|
||||
|
||||
authUser := request.NewAuthUser(s, user, true, time.Duration(time.Hour))
|
||||
|
||||
session := sessions.NewSession(&mockSession{
|
||||
save: func(r *http.Request, w http.ResponseWriter, s *sessions.Session) error {
|
||||
s.Values = make(map[interface{}]interface{})
|
||||
return nil
|
||||
},
|
||||
}, "session")
|
||||
|
||||
return &request.AuthReq{
|
||||
Request: req,
|
||||
AuthUser: authUser,
|
||||
Session: sessions.NewSession(memStore, "session"),
|
||||
Session: session,
|
||||
Response: httptest.NewRecorder(),
|
||||
Data: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
func prepareClientAuthService(ctx context.Context, user *types.User, memStore *memstore.MemStore) *mockAuthService {
|
||||
func prepareClientAuthService(ctx context.Context, user *types.User) *mockAuthService {
|
||||
authService := makeMockAuthService(ctx)
|
||||
return authService
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user