Refactor auth tests to allow setting customization
This commit is contained in:
@@ -56,8 +56,6 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
|
||||
@@ -67,7 +65,7 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "primary", Text: "Password successfully changed.", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
changePassword: func(ctx context.Context, userID uint64, oldPassword, newPassword string) (err error) {
|
||||
return nil
|
||||
@@ -79,7 +77,7 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
name: "provided password is not secure",
|
||||
payload: map[string]string{"error": "provided password is not secure; use longer password with more non-alphanumeric character"},
|
||||
link: GetLinks().ChangePassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
changePassword: func(ctx context.Context, userID uint64, oldPassword, newPassword string) (err error) {
|
||||
return service.AuthErrPasswordNotSecure()
|
||||
@@ -91,7 +89,7 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
name: "internal login is not enabled",
|
||||
payload: map[string]string{"error": "internal login (username/password) is disabled"},
|
||||
link: GetLinks().ChangePassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
changePassword: func(ctx context.Context, userID uint64, oldPassword, newPassword string) (err error) {
|
||||
return service.AuthErrInternalLoginDisabledByConfig()
|
||||
@@ -103,7 +101,7 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
name: "password change failed old password does not match",
|
||||
payload: map[string]string{"error": "failed to change password, old password does not match"},
|
||||
link: GetLinks().ChangePassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
changePassword: func(ctx context.Context, userID uint64, oldPassword, newPassword string) (err error) {
|
||||
return service.AuthErrPasswodResetFailedOldPasswordCheckFailed()
|
||||
@@ -115,7 +113,7 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
name: "password change failed for unknown user",
|
||||
payload: map[string]string{"error": "failed to change password for the unknown user"},
|
||||
link: GetLinks().ChangePassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
changePassword: func(ctx context.Context, userID uint64, oldPassword, newPassword string) (err error) {
|
||||
return service.AuthErrPasswordChangeFailedForUnknownUser()
|
||||
@@ -131,7 +129,9 @@ func Test_changePasswordProc(t *testing.T) {
|
||||
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -67,8 +67,6 @@ func Test_loginProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
@@ -79,7 +77,7 @@ func Test_loginProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "primary", Text: "You are now logged-in", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalLogin: func(ctx context.Context, email, password string) (u *types.User, err error) {
|
||||
u = &types.User{Meta: &types.UserMeta{}}
|
||||
@@ -97,7 +95,7 @@ func Test_loginProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Local accounts disabled", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalLogin: func(ctx context.Context, email, password string) (u *types.User, err error) {
|
||||
err = service.AuthErrInternalLoginDisabledByConfig()
|
||||
@@ -111,7 +109,7 @@ func Test_loginProc(t *testing.T) {
|
||||
payload: map[string]string{"email": "email@", "error": "invalid email"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Login,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("email", "email@")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -127,7 +125,7 @@ func Test_loginProc(t *testing.T) {
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "invalid username and password combination"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Login,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("email", "mockuser@example.tld")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -143,7 +141,7 @@ func Test_loginProc(t *testing.T) {
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "credentials {credentials.kind} linked to disabled or deleted user {user}"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Login,
|
||||
fn: func() {
|
||||
fn: func(*settings.Settings) {
|
||||
req.PostForm.Add("email", "mockuser@example.tld")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -165,7 +163,9 @@ func Test_loginProc(t *testing.T) {
|
||||
req.PostForm = url.Values{}
|
||||
user.Meta = &types.UserMeta{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -29,7 +29,6 @@ func Test_logoutProc(t *testing.T) {
|
||||
rq = require.New(t)
|
||||
)
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
service.CurrentSettings.Auth.Internal.Enabled = true
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@ func Test_mfaProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
service.CurrentSettings = &types.AppSettings{}
|
||||
@@ -35,7 +33,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "primary", Text: "Email OTP valid"}},
|
||||
link: GetLinks().Profile,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyEmailOtp")
|
||||
req.PostForm.Add("code", "123456")
|
||||
|
||||
@@ -51,7 +49,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "primary", Text: "TOTP valid"}},
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyTotp")
|
||||
req.PostForm.Add("code", "123456")
|
||||
|
||||
@@ -67,7 +65,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"emailOtpError": "multi factor authentication with email OTP is disabled"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyEmailOtp")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -82,7 +80,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"emailOtpError": "invalid username and password combination"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyEmailOtp")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -97,7 +95,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"emailOtpError": "invalid code"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyEmailOtp")
|
||||
req.PostForm.Add("code", "token_TOO_LONG")
|
||||
|
||||
@@ -113,7 +111,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"emailOtpError": "invalid code"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyEmailOtp")
|
||||
req.PostForm.Add("code", "123456")
|
||||
|
||||
@@ -129,7 +127,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"totpError": "multi factor authentication with TOTP is disabled"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyTotp")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -144,7 +142,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"totpError": "invalid username and password combination"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyTotp")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -159,7 +157,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"totpError": "invalid code"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyTotp")
|
||||
req.PostForm.Add("code", "token_TOO_LONG")
|
||||
|
||||
@@ -175,7 +173,7 @@ func Test_mfaProc(t *testing.T) {
|
||||
payload: map[string]string{"totpError": "invalid code"},
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Mfa,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "verifyTotp")
|
||||
req.PostForm.Add("code", "123456")
|
||||
|
||||
@@ -197,7 +195,9 @@ func Test_mfaProc(t *testing.T) {
|
||||
req.PostForm = url.Values{}
|
||||
user.Meta = &types.UserMeta{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -27,8 +27,6 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -37,7 +35,7 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
payload: -1,
|
||||
err: "",
|
||||
template: "",
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
oauthService = &oauth2ServiceMocked{
|
||||
handleAuthorizeRequest: func(w http.ResponseWriter, r *http.Request) error {
|
||||
return nil
|
||||
@@ -50,7 +48,7 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
payload: http.StatusInternalServerError,
|
||||
err: "not authorized",
|
||||
template: TmplInternalError,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
oauthService = &oauth2ServiceMocked{
|
||||
handleAuthorizeRequest: func(w http.ResponseWriter, r *http.Request) error {
|
||||
return errors.New("not authorized")
|
||||
@@ -64,7 +62,9 @@ func Test_oauth2AuthorizeSuccess(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = &AuthHandlers{
|
||||
|
||||
@@ -55,8 +55,6 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -66,7 +64,7 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().ResetPassword,
|
||||
template: TmplResetPassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.URL = &url.URL{RawQuery: "token=NOT_EMPTY"}
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -85,7 +83,7 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "warning", Text: "Invalid or expired password reset token, please repeat password reset request."}},
|
||||
link: GetLinks().RequestPasswordReset,
|
||||
template: TmplResetPassword,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.URL = &url.URL{RawQuery: "token=NOT_EMPTY"}
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -105,7 +103,9 @@ func Test_resetPasswordForm(t *testing.T) {
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, nil)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
@@ -134,8 +134,6 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -144,7 +142,7 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().PasswordResetRequested,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
sendPasswordResetToken: func(ctx context.Context, email string) (err error) {
|
||||
return nil
|
||||
@@ -157,7 +155,7 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Password reset disabled"}},
|
||||
link: GetLinks().Login,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
sendPasswordResetToken: func(ctx context.Context, email string) (err error) {
|
||||
return service.AuthErrPasswordResetDisabledByConfig()
|
||||
@@ -176,7 +174,9 @@ func Test_requestPasswordReset(t *testing.T) {
|
||||
req.PostForm = url.Values{}
|
||||
user.Meta = &types.UserMeta{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
@@ -201,8 +201,6 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -211,7 +209,7 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "primary", Text: "Password successfully reset.", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
setPassword: func(ctx context.Context, userID uint64, password string) (err error) {
|
||||
return nil
|
||||
@@ -224,7 +222,7 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
payload: map[string]string(nil),
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Password reset disabled", Html: ""}},
|
||||
link: GetLinks().Login,
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
setPassword: func(ctx context.Context, userID uint64, password string) (err error) {
|
||||
return service.AuthErrPasswordResetDisabledByConfig()
|
||||
@@ -238,7 +236,9 @@ func Test_requestPasswordProc(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
rq := require.New(t)
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -65,8 +65,6 @@ func Test_profileFormProc(t *testing.T) {
|
||||
userService userService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -76,7 +74,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "primary", Text: "Profile successfully updated.", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string(nil),
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -96,7 +94,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Could not update profile due to input errors", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "invalid ID", "handle": "handle", "name": "name"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -113,7 +111,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Could not update profile due to input errors", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "invalid handle", "handle": "handle", "name": "name"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -130,7 +128,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Could not update profile due to input errors", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "invalid email", "handle": "handle", "name": "name"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -147,7 +145,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Could not update profile due to input errors", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "handle not unique", "handle": "handle", "name": "name"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -164,7 +162,7 @@ func Test_profileFormProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Could not update profile due to input errors", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string{"email": "mockuser@example.tld", "error": "not allowed to update this user", "handle": "handle", "name": "name"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.PostForm.Add("handle", "handle")
|
||||
req.PostForm.Add("name", "name")
|
||||
|
||||
@@ -185,7 +183,9 @@ func Test_profileFormProc(t *testing.T) {
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -54,8 +54,6 @@ func Test_securityProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -63,7 +61,7 @@ func Test_securityProc(t *testing.T) {
|
||||
name: "reconfigureTOTP",
|
||||
link: GetLinks().MfaTotpNewSecret,
|
||||
payload: map[interface{}]interface{}{},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "reconfigureTOTP")
|
||||
},
|
||||
},
|
||||
@@ -71,7 +69,7 @@ func Test_securityProc(t *testing.T) {
|
||||
name: "disableTOTP",
|
||||
link: GetLinks().MfaTotpDisable,
|
||||
payload: map[interface{}]interface{}{"totpSecret": "SECRET_VALUE"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "disableTOTP")
|
||||
},
|
||||
},
|
||||
@@ -80,7 +78,7 @@ func Test_securityProc(t *testing.T) {
|
||||
err: "custom error",
|
||||
link: GetLinks().Security,
|
||||
payload: map[interface{}]interface{}{"totpSecret": "SECRET_VALUE"},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
req.Form.Set("action", "disableEmailOTP")
|
||||
|
||||
authService = &authServiceMocked{
|
||||
@@ -100,7 +98,9 @@ func Test_securityProc(t *testing.T) {
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -61,8 +61,6 @@ func Test_signupProc(t *testing.T) {
|
||||
authService authService
|
||||
authHandlers *AuthHandlers
|
||||
authReq *request.AuthReq
|
||||
|
||||
authSettings = &settings.Settings{}
|
||||
)
|
||||
|
||||
tcc := []testingExpect{
|
||||
@@ -72,7 +70,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "primary", Text: "Sign-up successful.", Html: ""}},
|
||||
link: GetLinks().Profile,
|
||||
payload: map[string]string(nil),
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
u = &types.User{
|
||||
@@ -96,7 +94,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().PendingEmailConfirmation,
|
||||
payload: map[string]string(nil),
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return &types.User{EmailConfirmed: false}, nil
|
||||
@@ -110,7 +108,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert{{Type: "danger", Text: "Signup disabled", Html: ""}},
|
||||
link: GetLinks().Login,
|
||||
payload: map[string]string(nil),
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return nil, service.AuthErrInternalSignupDisabledByConfig()
|
||||
@@ -124,7 +122,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Signup,
|
||||
payload: map[string]string{"email": "", "error": "invalid email", "handle": "", "name": ""},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return nil, service.AuthErrInvalidEmailFormat()
|
||||
@@ -138,7 +136,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Signup,
|
||||
payload: map[string]string{"email": "", "error": "invalid handle", "handle": "", "name": ""},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return nil, service.AuthErrInvalidHandle()
|
||||
@@ -152,7 +150,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Signup,
|
||||
payload: map[string]string{"email": "", "error": "provided password is not secure; use longer password with more non-alphanumeric character", "handle": "", "name": ""},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return nil, service.AuthErrPasswordNotSecure()
|
||||
@@ -166,7 +164,7 @@ func Test_signupProc(t *testing.T) {
|
||||
alerts: []request.Alert(nil),
|
||||
link: GetLinks().Signup,
|
||||
payload: map[string]string{"email": "", "error": "invalid username and password combination", "handle": "", "name": ""},
|
||||
fn: func() {
|
||||
fn: func(_ *settings.Settings) {
|
||||
authService = &authServiceMocked{
|
||||
internalSignUp: func(c context.Context, user *types.User, s string) (u *types.User, err error) {
|
||||
return nil, service.AuthErrInvalidCredentials()
|
||||
@@ -184,7 +182,9 @@ func Test_signupProc(t *testing.T) {
|
||||
req.Form = url.Values{}
|
||||
req.PostForm = url.Values{}
|
||||
|
||||
tc.fn()
|
||||
authSettings := &settings.Settings{}
|
||||
|
||||
tc.fn(authSettings)
|
||||
|
||||
authReq = prepareClientAuthReq(ctx, req, user)
|
||||
authHandlers = prepareClientAuthHandlers(ctx, authService, authSettings)
|
||||
|
||||
@@ -72,7 +72,7 @@ type (
|
||||
template string
|
||||
alerts []request.Alert
|
||||
userService userService
|
||||
fn func()
|
||||
fn func(*settings.Settings)
|
||||
}
|
||||
|
||||
userServiceMocked struct {
|
||||
@@ -89,6 +89,7 @@ type (
|
||||
validatePasswordResetToken func(context.Context, string) (user *types.User, err error)
|
||||
sendEmailAddressConfirmationToken func(context.Context, *types.User) (err error)
|
||||
sendPasswordResetToken func(context.Context, string) (err error)
|
||||
passwordSet func(context.Context, string) bool
|
||||
getProviders func() types.ExternalAuthProviderSet
|
||||
validateTOTP func(context.Context, string) (err error)
|
||||
configureTOTP func(context.Context, string, string) (u *types.User, err error)
|
||||
@@ -137,6 +138,10 @@ func (s authServiceMocked) ValidatePasswordResetToken(ctx context.Context, token
|
||||
return s.validatePasswordResetToken(ctx, token)
|
||||
}
|
||||
|
||||
func (s authServiceMocked) PasswordSet(ctx context.Context, email string) (is bool) {
|
||||
return s.passwordSet(ctx, email)
|
||||
}
|
||||
|
||||
func (s authServiceMocked) SendEmailAddressConfirmationToken(ctx context.Context, u *types.User) (err error) {
|
||||
return s.sendEmailAddressConfirmationToken(ctx, u)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user