Exemple #1
0
    def test_module_fail_with_invalid_user(self, mock_get, mock_object_id):
        def mock_self_object_id():
            return "VirtualMachine:::e6a7e6f1-6050-1ee33-9ba6-8e284e2801de-vm-38297"

        def mock_internal_user_username():
            return []

        set_module_args({
            'object_name': 'server_1',
            'end_user': '******',
            'object_type': 'vmware',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        mock_object_id.return_value = mock_self_object_id()

        mock_get.return_value = mock_internal_user_username()

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_end_user_authorization.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            'The Rubrik cluster does not contain a End User account named "testuser".'
        )
Exemple #2
0
    def test_module_fail_with_invalid_object(self):

        set_module_args({
            'object_name': 'server_1',
            'end_user': '******',
            'object_type': 'invalid_object_type',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        with self.assertRaises(AnsibleFailJson) as result:
            rubrik_end_user_authorization.main()

        self.assertEqual(result.exception.args[0]['failed'], True)
        self.assertEqual(
            result.exception.args[0]['msg'],
            'value of object_type must be one of: vmware, got: invalid_object_type'
        )
Exemple #3
0
 def test_module_fail_when_required_args_missing(self):
     with self.assertRaises(AnsibleFailJson):
         set_module_args({})
         rubrik_end_user_authorization.main()
Exemple #4
0
    def test_module_configure_user_authorization(self, mock_get, mock_post,
                                                 mock_object_id):
        def mock_self_object_id():
            return "VirtualMachine:::e6a7e6f1-6050-1ee33-9ba6-8e284e2801de-vm-38297"

        def mock_internal_user_username():
            return [{
                "id": "User:::119283ae-22ea-13f3-bfe2-9387cdf1d4a",
                "authDomainId": "string",
                "username": "******",
                "firstName": "string",
                "lastName": "string",
                "emailAddress": "string",
                "contactNumber": "string",
                "mfaServerId": "string"
            }]

        def mock_internal_authorization_role_end_user_principals():
            return {
                "hasMore":
                True,
                "data": [{
                    "principal": "string",
                    "privileges": {
                        "destructiveRestore": ["string"],
                        "restore": [
                            "VirtualMachine:::e6a7e6r3-6050-1ee33-9ba6-8e284e2801de"
                        ],
                        "onDemandSnapshot": ["string"],
                        "restoreWithoutDownload": ["string"],
                        "viewEvent": ["string"],
                        "provisionOnInfra": ["string"],
                        "viewReport": ["string"]
                    },
                    "organizationId": "string"
                }],
                "total":
                1
            }

        def mock_internal_authorization_role_end_user():
            return {
                "hasMore":
                False,
                "data": [{
                    "principal":
                    "User:::119283ae-22ea-13f3-bfe2-9387cdf1d4a",
                    "privileges": {
                        "destructiveRestore": [],
                        "restore": [
                            "VirtualMachine:::e6a7e6f1-6050-1ee33-9ba6-8e284e2801de-vm-38297-not-present"
                        ],
                        "onDemandSnapshot": [],
                        "restoreWithoutDownload": [],
                        "viewEvent": [],
                        "provisionOnInfra": [],
                        "viewReport": []
                    },
                    "organizationId":
                    "Organization:::05e3ee0b-5ec1-e33b-88a5-d916855aff5f"
                }],
                "total":
                1
            }

        set_module_args({
            'object_name': 'server_1',
            'end_user': '******',
            'object_type': 'vmware',
            'node_ip': '1.1.1.1',
            'api_token': 'vkys219gn2jziReqdPJH0asGM3PKEQHP'
        })

        mock_object_id.return_value = mock_self_object_id()

        mock_get.side_effect = [
            mock_internal_user_username(),
            mock_internal_authorization_role_end_user_principals()
        ]

        mock_post.return_value = mock_internal_authorization_role_end_user()

        with self.assertRaises(AnsibleExitJson) as result:
            rubrik_end_user_authorization.main()

        self.assertEqual(result.exception.args[0]['changed'], True)
        self.assertEqual(result.exception.args[0]['response'],
                         mock_internal_authorization_role_end_user())