1717import pytest
1818
1919from distutils .version import LooseVersion
20+ from f5 .sdk_exception import MissingRequiredCreationParameter
2021from requests .exceptions import HTTPError
2122
23+
2224pytestmark = pytest .mark .skipif (
2325 LooseVersion (pytest .config .getoption ('--release' ))
2426 < LooseVersion ('12.0.0' ),
@@ -45,6 +47,14 @@ def token(mgmt_root, users_link):
4547 resource .delete ()
4648
4749
50+ @pytest .fixture (scope = 'function' )
51+ def user (mgmt_root ):
52+ collection = mgmt_root .shared .authz .users_s
53+ resource = collection .user .create (name = 'user12345' , password = 'f5pass12345' )
54+ yield resource
55+ resource .delete ()
56+
57+
4858class TestAuthz (object ):
4959 def test_create (self , token ):
5060 assert token .kind == 'shared:authz:tokens:authtokenitemstate'
@@ -73,3 +83,28 @@ def test_package_mgmt_tasks_collection(self, mgmt_root, token):
7383 col = mgmt_root .shared .authz .tokens_s .get_collection ()
7484 assert isinstance (col , list )
7585 assert len (col ) > 0
86+
87+ def test_user_create (self , user ):
88+ assert user .kind == 'shared:authz:users:usersworkerstate'
89+
90+ def test_user_modify_password (self , mgmt_root , user ):
91+ collection = mgmt_root .shared .authz .users_s
92+ resource = collection .user .load (name = 'user12345' )
93+ if LooseVersion (pytest .config .getoption ('--release' )) > LooseVersion ('12.1.0' ):
94+ # In 12.x.x there were no 'encryptedPassword' parameter
95+ # on the response to shared/authz/users/user
96+ oldPasswd = resource .encryptedPassword
97+ resource .modify (name = 'user12345' , password = 'f5site02' )
98+ newPasswd = resource .encryptedPassword
99+ assert oldPasswd != newPasswd
100+ else :
101+ # In case of 12.x.x versions just make sure modify is not raising
102+ # any exceptions and the user still exists after modification
103+ resource .modify (name = 'user12345' , password = 'f5site02' )
104+ exists = collection .user .exists (name = 'user12345' )
105+ assert exists is True
106+
107+ def test_user_create_no_password (self , mgmt_root ):
108+ with pytest .raises (MissingRequiredCreationParameter ):
109+ collection = mgmt_root .shared .authz .users_s
110+ collection .user .create (name = 'user12345' )
0 commit comments