@@ -40,7 +40,7 @@ def test_user_admin(self):
40
40
organisation = Organisation (name = '123' , gdrive_id = '1' )
41
41
organisation .files = []
42
42
organisation .id = 2
43
- user = User (
username = 'test' ,
password = 'test ' ,
email = '[email protected] ' ,
role = 'admin' )
43
+ user = User (
username = 'test' ,
password = '!Str0?nkPassw0rd ' ,
email = '[email protected] ' ,
role = 'admin' )
44
44
user .organisation = organisation
45
45
self .assertEqual (user .role , 'admin' )
46
46
self .assertEqual (dict (user )['files' ], [])
@@ -52,7 +52,7 @@ def test_user_with_organisation(self, mock_send_mail, mock_create_access_token):
52
52
user_input : dict = {
53
53
'username' : 'rw1' ,
54
54
'organisation_id' : organisation .organisation_id ,
55
- 'password' : 'test ' ,
55
+ 'password' : '!Str0?nkPassw0rd ' ,
56
56
57
57
}
58
58
user = User (** user_input )
@@ -63,15 +63,15 @@ def test_user_with_organisation(self, mock_send_mail, mock_create_access_token):
63
63
@patch ('ptmd.database.models.user.session' )
64
64
@patch ('ptmd.database.models.token.send_confirmation_mail' , return_value = True )
65
65
def test_set_role_success (self , mock_send_confirmation_mail , mock_session ):
66
- user = User ('test' , 'test ' , 'test' , 'disabled' )
66
+ user = User ('test' , '!Str0?nkPassw0rd ' , 'test' , 'disabled' )
67
67
user .set_role ('banned' )
68
68
self .assertEqual (user .role , 'banned' )
69
69
mock_session .commit .assert_called_once ()
70
70
71
71
@patch ('ptmd.database.models.user.session' )
72
72
@patch ('ptmd.database.models.token.send_confirmation_mail' , return_value = True )
73
73
def test_set_role_invalid_role (self , mock_send_confirmation_mail , mock_session ):
74
- user = User ('test' , 'test ' , 'test' , 'disabled' )
74
+ user = User ('test' , '!Str0?nkPassw0rd ' , 'test' , 'disabled' )
75
75
with self .assertRaises (ValueError ) as context :
76
76
user .set_role ('invalid role' )
77
77
self .assertEqual (str (context .exception ), "Invalid role: invalid role" )
@@ -89,7 +89,7 @@ def test_user_serialisation_with_organisation(self, mock_organisation, mock_orga
89
89
organisation = Organisation (name = '123' , gdrive_id = '1' )
90
90
organisation .files = [file_1 , file_2 ]
91
91
organisation .id = 2
92
- user = User (
username = 'test' ,
password = 'test ' ,
email = '[email protected] ' ,
role = 'admin' )
92
+ user = User (
username = 'test' ,
password = '!Str0?nkPassw0rd ' ,
email = '[email protected] ' ,
role = 'admin' )
93
93
user .organisation = organisation
94
94
user .files = [file_1 ]
95
95
files = dict (user )['files' ]
@@ -98,9 +98,17 @@ def test_user_serialisation_with_organisation(self, mock_organisation, mock_orga
98
98
99
99
@patch ('ptmd.database.models.user.session' )
100
100
def test_set_password_policy_failure (self , mock_session ):
101
- user = User (
username = 'test' ,
password = 'test ' ,
email = '[email protected] ' ,
role = 'admin' )
101
+ user = User (
username = 'test' ,
password = '!Str0?nkPassw0rd[]() ' ,
email = '[email protected] ' ,
role = 'admin' )
102
102
with self .assertRaises (PasswordPolicyError ) as context :
103
103
user .set_password ('test' )
104
104
self .assertEqual (str (context .exception ),
105
- "Password must be between 8 and 20 characters long, contain at least one uppercase letter, one "
106
- "lowercase letter, one number and one special character." )
105
+ "Password must be between 8 and 20 characters long, contain at least one uppercase letter, "
106
+ "one lowercase letter, one number and one special character." )
107
+
108
+ def test_create_user_with_invalid_password (self ):
109
+ user = User (
username = 'test' ,
password = ':AStr0nkP3Wd!!' ,
email = '[email protected] ' ,
role = 'admin' )
110
+ with self .assertRaises (PasswordPolicyError ) as context :
111
+ user .set_password ('test' )
112
+ self .assertEqual (str (context .exception ),
113
+ "Password must be between 8 and 20 characters long, contain at least one uppercase letter, one"
114
+ " lowercase letter, one number and one special character." )
0 commit comments