@@ -115,13 +115,15 @@ def mock_logininitial_endpoint(requests_mock):
115115 )
116116
117117
118- @fixture
119- def user_utils (mock_v1_secrets , mock_logininitial_endpoint , mock_named_temporary_file , mock_atexit ):
118+ @fixture ( params = [ '9.0' , '9.1' ])
119+ def user_utils (request , mock_v1_secrets , mock_logininitial_endpoint , mock_named_temporary_file , mock_atexit ):
120120 k8s_client = MagicMock () # DynamicClient is mocked out, no methods will be called on the k8s_client
121+ mas_version = request .param
121122 user_utils = MASUserUtils (
122123 MAS_INSTANCE_ID ,
123124 MAS_WORKSPACE_ID ,
124125 k8s_client ,
126+ mas_version = mas_version ,
125127 coreapi_port = COREAPI_PORT ,
126128 admin_dashboard_port = ADMIN_DASHBOARD_PORT ,
127129 manage_api_port = MANAGE_API_PORT
@@ -1652,60 +1654,70 @@ def test_create_initial_user_for_saas_unsupported_type(user_utils):
16521654# Assisted by watsonx Code Assistant
16531655
16541656
1655- @pytest .mark .parametrize ("user_type, user_id, user_email, permissions, entitlement, is_workspace_admin, application_role, manage_role, facilities_role, manage_security_groups " , [
1657+ @pytest .mark .parametrize ("user_type, user_id, user_email, is_workspace_admin, application_role, manage_role, facilities_role, manage_security_groups_90, manage_security_groups_91 " , [
16561658 (
16571659 "PRIMARY" ,
16581660 None ,
16591661 "bill.bob@acme.com" ,
1660- {"systemAdmin" : False , "userAdmin" : True , "apikeyAdmin" : False },
1661- {"application" : "PREMIUM" , "admin" : "ADMIN_BASE" , "alwaysReserveLicense" : True },
16621662 True ,
16631663 "ADMIN" ,
16641664 "MANAGEUSER" ,
16651665 "PREMIUM" ,
1666- ["MAXADMIN" ]
1666+ ["MAXADMIN" ],
1667+ ["USERMANAGEMENT" ]
16671668 ),
16681669 (
16691670 "PRIMARY" ,
16701671 "billbob" ,
16711672 "bill.bob@acme.com" ,
1672- {"systemAdmin" : False , "userAdmin" : True , "apikeyAdmin" : False },
1673- {"application" : "PREMIUM" , "admin" : "ADMIN_BASE" , "alwaysReserveLicense" : True },
16741673 True ,
16751674 "ADMIN" ,
16761675 "MANAGEUSER" ,
16771676 "PREMIUM" ,
1678- ["MAXADMIN" ]
1677+ ["MAXADMIN" ],
1678+ ["USERMANAGEMENT" ]
16791679 ),
16801680 (
16811681 "SECONDARY" ,
16821682 None ,
16831683 "bab.bon@acme.com" ,
1684- {"systemAdmin" : False , "userAdmin" : False , "apikeyAdmin" : False },
1685- {"application" : "BASE" , "admin" : "NONE" , "alwaysReserveLicense" : True },
16861684 False ,
16871685 "USER" ,
16881686 "MANAGEUSER" ,
16891687 "BASE" ,
1688+ [],
16901689 []
16911690 ),
16921691 (
16931692 "SECONDARY" ,
16941693 "babbon" ,
16951694 "bab.bon@acme.com" ,
1696- {"systemAdmin" : False , "userAdmin" : False , "apikeyAdmin" : False },
1697- {"application" : "BASE" , "admin" : "NONE" , "alwaysReserveLicense" : True },
16981695 False ,
16991696 "USER" ,
17001697 "MANAGEUSER" ,
17011698 "BASE" ,
1699+ [],
17021700 []
17031701 )
17041702])
17051703def test_create_initial_user_for_saas (
1706- user_type , user_id , user_email , permissions , entitlement , is_workspace_admin , application_role , manage_role , facilities_role , manage_security_groups ,
1704+ user_type , user_id , user_email , is_workspace_admin , application_role , manage_role , facilities_role , manage_security_groups_90 , manage_security_groups_91 ,
17071705 user_utils , requests_mock
17081706):
1707+ # Determine expected values based on MAS version
1708+ mas_version = user_utils .mas_version
1709+ if mas_version == '9.0' :
1710+ manage_security_groups = manage_security_groups_90
1711+ if user_type == "PRIMARY" :
1712+ permissions = {"systemAdmin" : False , "userAdmin" : True , "apikeyAdmin" : False }
1713+ entitlement = {"application" : "PREMIUM" , "admin" : "ADMIN_BASE" , "alwaysReserveLicense" : True }
1714+ else : # SECONDARY
1715+ permissions = {"systemAdmin" : False , "userAdmin" : False , "apikeyAdmin" : False }
1716+ entitlement = {"application" : "BASE" , "admin" : "NONE" , "alwaysReserveLicense" : True }
1717+ else : # 9.1
1718+ manage_security_groups = manage_security_groups_91
1719+ permissions = None # Not used in 9.1
1720+ entitlement = None # Not used in 9.1
17091721 user_utils .get_or_create_user = MagicMock ()
17101722 user_utils .link_user_to_local_idp = MagicMock ()
17111723 user_utils .add_user_to_workspace = MagicMock ()
@@ -1735,29 +1747,78 @@ def test_create_initial_user_for_saas(
17351747
17361748 username = user_id
17371749
1738- user_utils .create_initial_user_for_saas (initial_users , user_type )
1739-
1740- user_utils .get_or_create_user .assert_called_once_with ({
1741- "id" : user_id ,
1742- "status" : {"active" : True },
1743- "username" : username ,
1744- "owner" : "local" ,
1745- "emails" : [
1746- {
1747- "value" : user_email ,
1748- "type" : "Work" ,
1749- "primary" : True
1750+ # For version 9.1 PRIMARY users, pass groupreassign parameter
1751+ if mas_version == '9.1' and user_type == "PRIMARY" :
1752+ groupreassign = [{"groupname" : "USERMANAGEMENT" }]
1753+ user_utils .create_initial_user_for_saas (initial_users , user_type , groupreassign )
1754+ else :
1755+ user_utils .create_initial_user_for_saas (initial_users , user_type )
1756+
1757+ # Build expected user_def based on version
1758+ if mas_version == '9.0' :
1759+ expected_user_def = {
1760+ "id" : user_id ,
1761+ "status" : {"active" : True },
1762+ "username" : username ,
1763+ "owner" : "local" ,
1764+ "emails" : [
1765+ {
1766+ "value" : user_email ,
1767+ "type" : "Work" ,
1768+ "primary" : True
1769+ }
1770+ ],
1771+ "phoneNumbers" : [],
1772+ "addresses" : [],
1773+ "displayName" : display_name ,
1774+ "issuer" : "local" ,
1775+ "permissions" : permissions ,
1776+ "entitlement" : entitlement ,
1777+ "givenName" : user_given_name ,
1778+ "familyName" : user_family_name
1779+ }
1780+ else : # 9.1
1781+ if user_type == "PRIMARY" :
1782+ maxuser_def = {
1783+ "userid" : user_id ,
1784+ "owner" : "local" ,
1785+ "systemadmin" : False ,
1786+ "apikeyadmin" : True ,
1787+ "isauthorized" : 1 ,
1788+ "idpadmin" : True ,
1789+ "groupuser" : [
1790+ {
1791+ "groupname" : "USERMANAGEMENT"
1792+ }
1793+ ],
1794+ "grpreassignauth" : [
1795+ {
1796+ "groupname" : "USERMANAGEMENT"
1797+ }
1798+ ]
17501799 }
1751- ],
1752- "phoneNumbers" : [],
1753- "addresses" : [],
1754- "displayName" : display_name ,
1755- "issuer" : "local" ,
1756- "permissions" : permissions ,
1757- "entitlement" : entitlement ,
1758- "givenName" : user_given_name ,
1759- "familyName" : user_family_name
1760- })
1800+ else : # SECONDARY
1801+ maxuser_def = {
1802+ "userid" : user_id ,
1803+ "owner" : "local" ,
1804+ "systemadmin" : False ,
1805+ "apikeyadmin" : False ,
1806+ "isauthorized" : 0 ,
1807+ "idpadmin" : False
1808+ }
1809+
1810+ expected_user_def = {
1811+ "id" : user_id ,
1812+ "status" : {"active" : True },
1813+ "primaryemailtype" : "Work" ,
1814+ "primaryemail" : user_email ,
1815+ "primaryphone" : "" ,
1816+ "addressline1" : "" ,
1817+ "displayName" : display_name ,
1818+ "maxuser" : maxuser_def
1819+ }
1820+
1821+ user_utils .get_or_create_user .assert_called_once_with (expected_user_def )
17611822 user_utils .link_user_to_local_idp .assert_called_once_with (user_id , email_password = True )
17621823 user_utils .add_user_to_workspace .assert_called_once_with (user_id , is_workspace_admin = is_workspace_admin )
17631824 user_utils .await_mas_application_availability .assert_has_calls ([call ("manage" ), call ("iot" )])
@@ -1813,9 +1874,10 @@ def test_create_initial_users_for_saas(user_utils):
18131874 mas_workspace_application_ids = ["manage" , "iot" ]
18141875 user_utils .get_mas_applications_in_workspace = MagicMock (return_value = map (lambda x : {"id" : x }, mas_workspace_application_ids ))
18151876 user_utils .await_mas_application_availability = MagicMock ()
1877+ user_utils .get_all_manage_groups = MagicMock (return_value = ["MAXADMIN" , "MAXUSER" ])
18161878 user_utils .create_initial_user_for_saas = MagicMock ()
18171879
1818- def fail_for_users_b_and_e (user , user_type ):
1880+ def fail_for_users_b_and_e (user , user_type , groupreassign = None ):
18191881 if user ["email" ] in ["b" , "e" ]:
18201882 raise Exception (f"{ user ['email' ]} should fail" )
18211883 user_utils .create_initial_user_for_saas .side_effect = fail_for_users_b_and_e
0 commit comments