From 33d4c0b3d5332d46fefcb2fe91df9e641f207c60 Mon Sep 17 00:00:00 2001 From: Francis Charette Migneault Date: Wed, 29 Jul 2020 16:24:34 -0400 Subject: [PATCH] user input validation (fix #84, relates #171) + adjust input types + current user view tests --- .../api/management/register/register_views.py | 1 + magpie/api/management/user/user_utils.py | 3 ++ magpie/ui/management/templates/add_user.mako | 2 +- .../ui/management/templates/edit_service.mako | 2 +- tests/interfaces.py | 35 ++++++++++++++--- tests/test_magpie_ui.py | 4 +- tests/test_register.py | 1 + tests/utils.py | 39 ++++++++++++------- 8 files changed, 64 insertions(+), 23 deletions(-) diff --git a/magpie/api/management/register/register_views.py b/magpie/api/management/register/register_views.py index 930bbe54a..021d44012 100644 --- a/magpie/api/management/register/register_views.py +++ b/magpie/api/management/register/register_views.py @@ -15,6 +15,7 @@ from magpie.api.management.group import group_formats as gf from magpie.api.management.register import register_utils as ru from magpie.api.management.user import user_utils as uu +from magpie import models if TYPE_CHECKING: from pyramid.httpexceptions import HTTPException diff --git a/magpie/api/management/user/user_utils.py b/magpie/api/management/user/user_utils.py index 77c610591..a53b03207 100644 --- a/magpie/api/management/user/user_utils.py +++ b/magpie/api/management/user/user_utils.py @@ -332,6 +332,7 @@ def get_user_service_resources_permissions_dict(user, service, request, inherit_ def check_user_info(user_name, email, password, group_name): # type: (Str, Str, Str, Str) -> None + """Validates provided user information to ensure they are adequate for user creation.""" ax.verify_param(user_name, not_none=True, not_empty=True, http_error=HTTPBadRequest, param_name=u"user_name", msg_on_fail=s.Users_CheckInfo_Name_BadRequestResponseSchema.description) @@ -343,6 +344,8 @@ def check_user_info(user_name, email, password, group_name): msg_on_fail=s.Users_CheckInfo_ReservedKeyword_BadRequestResponseSchema.description) ax.verify_param(email, not_none=True, not_empty=True, http_error=HTTPBadRequest, param_name=u"email", msg_on_fail=s.Users_CheckInfo_Email_BadRequestResponseSchema.description) + ax.verify_param(email, regex_match=True, param_compare=r"", http_error=HTTPBadRequest, + param_name=u"email", msg_on_fail=s.Users_CheckInfo_Email_BadRequestResponseSchema.description) ax.verify_param(password, not_none=True, not_empty=True, http_error=HTTPBadRequest, param_name=u"password", msg_on_fail=s.Users_CheckInfo_Password_BadRequestResponseSchema.description) diff --git a/magpie/ui/management/templates/add_user.mako b/magpie/ui/management/templates/add_user.mako index 92ac4c2f0..9fa6106b5 100644 --- a/magpie/ui/management/templates/add_user.mako +++ b/magpie/ui/management/templates/add_user.mako @@ -35,7 +35,7 @@ Email:
diff --git a/magpie/ui/management/templates/edit_service.mako b/magpie/ui/management/templates/edit_service.mako index 013dd7ebb..29cfc7600 100644 --- a/magpie/ui/management/templates/edit_service.mako +++ b/magpie/ui/management/templates/edit_service.mako @@ -129,7 +129,7 @@ Protected URL: %if edit_mode == "edit_url":