Exemplo n.º 1
0
 def test_decrypt_encrypted_text_wrong_private_key(self):
     encrypted_string = load_data("wire/encrypted.enc")
     prv_key = os.path.join(self.tmp_dir, "wrong.pem")
     with open(prv_key, 'w+') as c:
         c.write(load_data("wire/trans_prv"))
     crypto = CryptUtil(conf.get_openssl_cmd())
     self.assertRaises(CryptError, crypto.decrypt_secret, encrypted_string,
                       prv_key)
Exemplo n.º 2
0
 def test_decrypt_encrypted_text(self):
     encrypted_string = load_data("wire/encrypted.enc")
     prv_key = os.path.join(self.tmp_dir, "TransportPrivate.pem")
     with open(prv_key, 'w+') as c:
         c.write(load_data("wire/sample.pem"))
     secret = ']aPPEv}uNg1FPnl?'
     crypto = CryptUtil(conf.get_openssl_cmd())
     decrypted_string = crypto.decrypt_secret(encrypted_string, prv_key)
     self.assertEqual(secret, decrypted_string,
                      "decrypted string does not match expected")
Exemplo n.º 3
0
 def reload(self):
     self.version_info = load_data(self.data_files.get("version_info"))
     self.goal_state = load_data(self.data_files.get("goal_state"))
     self.hosting_env = load_data(self.data_files.get("hosting_env"))
     self.shared_config = load_data(self.data_files.get("shared_config"))
     self.certs = load_data(self.data_files.get("certs"))
     self.ext_conf = load_data(self.data_files.get("ext_conf"))
     self.manifest = load_data(self.data_files.get("manifest"))
     self.ga_manifest = load_data(self.data_files.get("ga_manifest"))
     self.trans_prv = load_data(self.data_files.get("trans_prv"))
     self.trans_cert = load_data(self.data_files.get("trans_cert"))
     self.ext = load_bin_data(self.data_files.get("test_ext"))
Exemplo n.º 4
0
    def test_add_event_should_read_container_id_from_process_environment(self):
        tmp_file = os.path.join(self.tmp_dir, "tmp_file")

        def patch_save_event(json_data):
            fileutil.write_file(tmp_file, json_data)

        with patch("azurelinuxagent.common.event.EventLogger.save_event", side_effect=patch_save_event):
            # No container id is set
            os.environ.pop(event.CONTAINER_ID_ENV_VARIABLE, None)
            event.add_event(name='dummy_name')
            data = fileutil.read_file(tmp_file)
            self.assertTrue('{"name": "ContainerId", "value": "UNINITIALIZED"}' in data or
                            '{"value": "UNINITIALIZED", "name": "ContainerId"}' in data)

            # Container id is set as an environment variable explicitly
            os.environ[event.CONTAINER_ID_ENV_VARIABLE] = '424242'
            event.add_event(name='dummy_name')
            data = fileutil.read_file(tmp_file)
            self.assertTrue('{{"name": "ContainerId", "value": "{0}"}}'.format(
                                os.environ[event.CONTAINER_ID_ENV_VARIABLE]) in data or
                            '{{"value": "{0}", "name": "ContainerId"}}'.format(
                                os.environ[event.CONTAINER_ID_ENV_VARIABLE]) in data)

            # Container id is set as an environment variable when parsing the goal state
            xml_text = load_data("wire/goal_state.xml")
            goal_state = GoalState(xml_text)

            container_id = goal_state.container_id
            event.add_event(name='dummy_name')
            data = fileutil.read_file(tmp_file)
            self.assertTrue('{{"name": "ContainerId", "value": "{0}"}}'.format(container_id) in data or
                            '{{"value": "{0}", "name": "ContainerId"}}'.format(container_id), data)

            # Container id is updated as the goal state changes, both in telemetry event and in environment variables
            new_container_id = "z6d5526c-5ac2-4200-b6e2-56f2b70c5ab2"
            xml_text = load_data("wire/goal_state.xml")
            xml_text_updated = xml_text.replace("c6d5526c-5ac2-4200-b6e2-56f2b70c5ab2", new_container_id)
            goal_state = GoalState(xml_text_updated)

            event.add_event(name='dummy_name')
            data = fileutil.read_file(tmp_file)

            # Assert both the environment variable and telemetry event got updated
            self.assertEquals(os.environ[event.CONTAINER_ID_ENV_VARIABLE], new_container_id)
            self.assertTrue('{{"name": "ContainerId", "value": "{0}"}}'.format(new_container_id) in data or
                            '{{"value": "{0}", "name": "ContainerId"}}'.format(new_container_id), data)

        os.environ.pop(event.CONTAINER_ID_ENV_VARIABLE)
 def test_handle_remote_access_deleted_user_readded(self, _):
     rah = RemoteAccessHandler(Mock())
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_single_account.xml')
     remote_access = RemoteAccess(data_str)
     tstuser = remote_access.user_list.users[0].name
     expiration_date = datetime.utcnow() + timedelta(days=1)
     expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
     remote_access.user_list.users[0].expiration = expiration
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertTrue(tstuser in users,
                     "{0} missing from users".format(tstuser))
     os_util = rah.os_util
     os_util.__class__ = MockOSUtil
     os_util.all_users.clear()
     # refresh users
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertTrue(tstuser not in users)
     rah.handle_remote_access()
     # refresh users
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertTrue(tstuser in users,
                     "{0} missing from users".format(tstuser))
 def test_handle_remote_access_multiple_users_one_removed(self, _):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil",
                return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_10_accounts.xml')
         remote_access = RemoteAccess(data_str)
         count = 0
         for user in remote_access.user_list.users:
             count += 1
             user.name = "tstuser{0}".format(count)
             expiration_date = datetime.utcnow() + timedelta(days=count)
             user.expiration = expiration_date.strftime(
                 "%a, %d %b %Y %H:%M:%S ") + "UTC"
         rah._remote_access = remote_access
         rah._handle_remote_access()
         users = rah._os_util.get_users()
         self.assertEqual(10, len(users))
         # now remove the user from RemoteAccess
         deleted_user = rah._remote_access.user_list.users[3]
         del rah._remote_access.user_list.users[3]
         rah._handle_remote_access()
         users = rah._os_util.get_users()
         self.assertTrue(deleted_user not in users,
                         "{0} still in users".format(deleted_user))
         self.assertEqual(9, len(users))
Exemplo n.º 7
0
    def test_provision_telemetry_fail(self,
                                      mock_util,
                                      distro_name,
                                      distro_version,
                                      distro_full_name, _):
        """
        Assert that the agent issues one telemetry message as part of a
        failed provisioning.

         1. Provision
        """
        ph = get_provision_handler(distro_name, distro_version,
                                   distro_full_name)
        ph.report_event = MagicMock()
        ph.reg_ssh_host_key = MagicMock(side_effect=ProvisionError(
            "--unit-test--"))

        mock_osutil = MagicMock()
        mock_osutil.decode_customdata = Mock(return_value="")

        ph.osutil = mock_osutil
        ph.protocol_util.osutil = mock_osutil
        ph.protocol_util.get_protocol = MagicMock()

        conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
        ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
        ovfenv_data = load_data("ovf-env.xml")
        fileutil.write_file(ovfenv_file, ovfenv_data)

        ph.run()
        positional_args, kw_args = ph.report_event.call_args_list[0]
        self.assertTrue(re.match(r'Provisioning failed: \[ProvisionError\] --unit-test-- \(\d+\.\d+s\)', positional_args[0]) is not None)
Exemplo n.º 8
0
 def test_parse_two_remote_access_accounts(self):
     data_str = load_data('wire/remote_access_two_accounts.xml')
     remote_access = RemoteAccess(data_str)
     self.assertNotEquals(None, remote_access)
     self.assertEquals("1", remote_access.incarnation)
     self.assertEquals(2, len(remote_access.user_list.users),
                       "User count does not match.")
     self.assertEquals("testAccount1",
                       remote_access.user_list.users[0].name,
                       "Account name does not match")
     self.assertEquals("encryptedPasswordString",
                       remote_access.user_list.users[0].encrypted_password,
                       "Encrypted password does not match.")
     self.assertEquals("2019-01-01",
                       remote_access.user_list.users[0].expiration,
                       "Expiration does not match.")
     self.assertEquals("testAccount2",
                       remote_access.user_list.users[1].name,
                       "Account name does not match")
     self.assertEquals("encryptedPasswordString",
                       remote_access.user_list.users[1].encrypted_password,
                       "Encrypted password does not match.")
     self.assertEquals("2019-01-01",
                       remote_access.user_list.users[1].expiration,
                       "Expiration does not match.")
 def test_handle_remote_access_remove_and_add(self, _):
     rah = RemoteAccessHandler(Mock())
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_10_accounts.xml')
     remote_access = RemoteAccess(data_str)
     count = 0
     for user in remote_access.user_list.users:
         count += 1
         user.name = "tstuser{0}".format(count)
         expiration_date = datetime.utcnow() + timedelta(days=count)
         user.expiration = expiration_date.strftime(
             "%a, %d %b %Y %H:%M:%S ") + "UTC"
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = rah.os_util.get_users()
     self.assertEqual(10, len(users))
     # now remove the user from RemoteAccess
     new_user = "******"
     deleted_user = rah.remote_access.user_list.users[3]
     rah.remote_access.user_list.users[3].name = new_user
     rah.handle_remote_access()
     users = rah.os_util.get_users()
     self.assertTrue(deleted_user not in users,
                     "{0} still in users".format(deleted_user))
     self.assertTrue(new_user in [u[0] for u in users],
                     "user {0} not in users".format(new_user))
     self.assertEqual(10, len(users))
Exemplo n.º 10
0
 def test_decrypt_encrypted_text_text_not_encrypted(self):
     encrypted_string = "abc@123"
     prv_key = os.path.join(self.tmp_dir, "TransportPrivate.pem")
     with open(prv_key, 'w+') as c:
         c.write(load_data("wire/sample.pem"))
     crypto = CryptUtil(conf.get_openssl_cmd())
     self.assertRaises(CryptError, crypto.decrypt_secret, encrypted_string,
                       prv_key)
Exemplo n.º 11
0
    def _provision_test(self,
                        distro_name,
                        distro_version,
                        distro_full_name,
                        ovf_file,
                        provisionMessage,
                        expect_success,
                        patch_write_agent_disabled,
                        patch_get_instance_id):
        """
        Assert that the agent issues two telemetry messages as part of a
        successful provisioning.

         1. Provision
         2. GuestState
        """
        ph = get_provision_handler(distro_name,
                                   distro_version,
                                   distro_full_name)
        ph.report_event = MagicMock()
        ph.reg_ssh_host_key = MagicMock(return_value='--thumprint--')

        mock_osutil = MagicMock()
        mock_osutil.decode_customdata = Mock(return_value="")

        ph.osutil = mock_osutil
        ph.protocol_util.osutil = mock_osutil
        ph.protocol_util.get_protocol = MagicMock()

        conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
        ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
        ovfenv_data = load_data(ovf_file)
        fileutil.write_file(ovfenv_file, ovfenv_data)

        ph.run()

        if expect_success:
            self.assertEqual(2, ph.report_event.call_count)
            positional_args, kw_args = ph.report_event.call_args_list[0]
            # [call('Provisioning succeeded (146473.68s)', duration=65, is_success=True)]
            self.assertTrue(re.match(r'Provisioning succeeded \(\d+\.\d+s\)', positional_args[0]) is not None)
            self.assertTrue(isinstance(kw_args['duration'], int))
            self.assertTrue(kw_args['is_success'])

            positional_args, kw_args = ph.report_event.call_args_list[1]
            self.assertTrue(kw_args['operation'] == 'ProvisionGuestAgent')
            self.assertTrue(kw_args['message'] == provisionMessage)
            self.assertTrue(kw_args['is_success'])

            expected_disabled = True if provisionMessage == 'false' else False
            self.assertTrue(patch_write_agent_disabled.call_count == expected_disabled)

        else:
            self.assertEqual(1, ph.report_event.call_count)
            positional_args, kw_args = ph.report_event.call_args_list[0]
            # [call(u'[ProtocolError] Failed to validate OVF: ProvisionGuestAgent not found')]
            self.assertTrue('Failed to validate OVF: ProvisionGuestAgent not found' in positional_args[0])
            self.assertFalse(kw_args['is_success'])
Exemplo n.º 12
0
 def test_handle_remote_access_no_users(self):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_no_accounts.xml')
         remote_access = RemoteAccess(data_str)
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertEqual(0, len(users.keys()))
 def test_handle_remote_access_no_users(self):
     rah = RemoteAccessHandler(Mock())
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_no_accounts.xml')
     remote_access = RemoteAccess(data_str)
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertEqual(0, len(users.keys()))
Exemplo n.º 14
0
 def __init__(self, data_files):
     self.identity = load_data(data_files.get("identity"))
     self.certificates = load_data(data_files.get("certificates"))
     self.certificates_data = load_data(data_files.get("certificates_data"))
     self.ext_handlers = load_data(data_files.get("ext_handlers"))
     self.ext_handler_pkgs = load_data(data_files.get("ext_handler_pkgs"))
     self.trans_prv = load_data(data_files.get("trans_prv"))
     self.trans_cert = load_data(data_files.get("trans_cert"))
Exemplo n.º 15
0
 def test_dhcp_lease_custom_dns(self):
     """
     Validate that the wireserver address is coming from option 245
     (on default configurations the address is also available in the domain-name-servers option, but users
      may set up a custom dns server on their vnet)
     """
     with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
         with patch(open_patch(), mock.mock_open(read_data=load_data("dhcp.leases.custom.dns"))):
             endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()  # pylint: disable=assignment-from-none
             self.assertEqual(endpoint, "168.63.129.16")
Exemplo n.º 16
0
 def test_do_not_add_expired_user(self):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_single_account.xml')
         remote_access = RemoteAccess(data_str)
         expiration = (datetime.utcnow() - timedelta(days=2)).strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
         remote_access.user_list.users[0].expiration = expiration
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertFalse("testAccount" in users)
 def test_do_not_add_expired_user(self):
     rah = RemoteAccessHandler()
     rah.os_util = MockOSUtil()      
     data_str = load_data('wire/remote_access_single_account.xml')
     remote_access = RemoteAccess(data_str)
     expiration = (datetime.utcnow() - timedelta(days=2)).strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
     remote_access.user_list.users[0].expiration = expiration
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertFalse("testAccount" in users)
Exemplo n.º 18
0
    def test_dhcp_lease_ubuntu(self):
        with patch.object(glob, "glob", return_value=['/var/lib/dhcp/dhclient.eth0.leases']):
            with patch(open_patch(), mock.mock_open(read_data=load_data("dhcp.leases"))):
                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()  # pylint: disable=assignment-from-none
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='12.04').get_dhcp_lease_endpoint()  # pylint: disable=assignment-from-none
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")

                endpoint = get_osutil(distro_name='ubuntu', distro_version='14.04').get_dhcp_lease_endpoint()  # pylint: disable=assignment-from-none
                self.assertTrue(endpoint is not None)
                self.assertEqual(endpoint, "168.63.129.16")
 def test_handle_remote_access_ten_users(self, _):
     rah = RemoteAccessHandler()
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_10_accounts.xml')
     remote_access = RemoteAccess(data_str)
     count = 0
     for user in remote_access.user_list.users:
         count += 1
         user.name = "tstuser{0}".format(count)
         expiration_date = datetime.utcnow() + timedelta(days=count)
         user.expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertEqual(10, len(users.keys()))
Exemplo n.º 20
0
 def test_handle_remote_access_ten_users(self, _):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_10_accounts.xml')
         remote_access = RemoteAccess(data_str)
         count = 0
         for user in remote_access.user_list.users:
             count += 1
             user.name = "tstuser{0}".format(count)
             expiration_date = datetime.utcnow() + timedelta(days=count)
             user.expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertEqual(10, len(users.keys()))
Exemplo n.º 21
0
 def test_provision(self, mock_util, distro_name, distro_version, distro_full_name):
     provision_handler = get_provision_handler(distro_name, distro_version,
                                               distro_full_name)
     mock_osutil = MagicMock()
     mock_osutil.decode_customdata = Mock(return_value="")
     
     provision_handler.osutil = mock_osutil
     provision_handler.protocol_util.osutil = mock_osutil
     provision_handler.protocol_util.get_protocol = MagicMock()
    
     conf.get_dvd_mount_point = Mock(return_value=self.tmp_dir)
     ovfenv_file = os.path.join(self.tmp_dir, OVF_FILE_NAME)
     ovfenv_data = load_data("ovf-env.xml")
     fileutil.write_file(ovfenv_file, ovfenv_data)
      
     provision_handler.run()
Exemplo n.º 22
0
 def test_handle_new_user(self, _):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_single_account.xml')
         remote_access = RemoteAccess(data_str)
         tstuser = remote_access.user_list.users[0].name
         expiration_date = datetime.utcnow() + timedelta(days=1)
         expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
         remote_access.user_list.users[0].expiration = expiration
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertTrue(tstuser in users, "{0} missing from users".format(tstuser))
         actual_user = users[tstuser]
         expected_expiration = (expiration_date + timedelta(days=1)).strftime("%Y-%m-%d")
         self.assertEqual(actual_user[7], expected_expiration)
         self.assertEqual(actual_user[4], "JIT_Account")
 def test_handle_new_user(self, _):
     rah = RemoteAccessHandler()
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_single_account.xml')
     remote_access = RemoteAccess(data_str)
     tstuser = remote_access.user_list.users[0].name
     expiration_date = datetime.utcnow() + timedelta(days=1)
     expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
     remote_access.user_list.users[0].expiration = expiration
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertTrue(tstuser in users, "{0} missing from users".format(tstuser))
     actual_user = users[tstuser]
     expected_expiration = (expiration_date + timedelta(days=1)).strftime("%Y-%m-%d")
     self.assertEqual(actual_user[7], expected_expiration)
     self.assertEqual(actual_user[4], "JIT_Account")
Exemplo n.º 24
0
 def test_handle_remote_access_multiple_users(self, _):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_two_accounts.xml')
         remote_access = RemoteAccess(data_str)
         testusers = []
         count = 0
         while count < 2:
             user = remote_access.user_list.users[count].name
             expiration_date = datetime.utcnow() + timedelta(days=count + 1)
             expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
             remote_access.user_list.users[count].expiration = expiration
             testusers.append(user)
             count += 1
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertTrue(testusers[0] in users, "{0} missing from users".format(testusers[0]))
         self.assertTrue(testusers[1] in users, "{0} missing from users".format(testusers[1]))
 def test_handle_remote_access_multiple_users(self, _):
     rah = RemoteAccessHandler()
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_two_accounts.xml')
     remote_access = RemoteAccess(data_str)
     testusers = []
     count = 0
     while count < 2:
         user = remote_access.user_list.users[count].name
         expiration_date = datetime.utcnow() + timedelta(days=count + 1)
         expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
         remote_access.user_list.users[count].expiration = expiration
         testusers.append(user)
         count += 1
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = get_user_dictionary(rah.os_util.get_users())
     self.assertTrue(testusers[0] in users, "{0} missing from users".format(testusers[0]))
     self.assertTrue(testusers[1] in users, "{0} missing from users".format(testusers[1]))
 def test_handle_remote_access_multiple_users_error_with_null_remote_access(self, _):
     rah = RemoteAccessHandler()
     rah.os_util = MockOSUtil()
     data_str = load_data('wire/remote_access_10_accounts.xml')
     remote_access = RemoteAccess(data_str)
     count = 0
     for user in remote_access.user_list.users:
         count += 1
         user.name = "tstuser{0}".format(count)
         expiration_date = datetime.utcnow() + timedelta(days=count)
         user.expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
     rah.remote_access = remote_access
     rah.handle_remote_access()
     users = rah.os_util.get_users()
     self.assertEqual(10, len(users))
     # now remove the user from RemoteAccess
     rah.remote_access = None
     rah.handle_remote_access()
     users = rah.os_util.get_users()
     self.assertEqual(0, len(users))
Exemplo n.º 27
0
 def test_handle_remote_access_deleted_user_readded(self, _):
     with patch("azurelinuxagent.ga.remoteaccess.get_osutil", return_value=MockOSUtil()):
         rah = RemoteAccessHandler(Mock())
         data_str = load_data('wire/remote_access_single_account.xml')
         remote_access = RemoteAccess(data_str)
         tstuser = remote_access.user_list.users[0].name
         expiration_date = datetime.utcnow() + timedelta(days=1)
         expiration = expiration_date.strftime("%a, %d %b %Y %H:%M:%S ") + "UTC"
         remote_access.user_list.users[0].expiration = expiration
         rah._remote_access = remote_access # pylint: disable=protected-access
         rah._handle_remote_access() # pylint: disable=protected-access
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertTrue(tstuser in users, "{0} missing from users".format(tstuser))
         os_util = rah._os_util # pylint: disable=protected-access
         os_util.__class__ = MockOSUtil
         os_util.all_users.clear() # pylint: disable=no-member
         # refresh users
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertTrue(tstuser not in users)
         rah._handle_remote_access() # pylint: disable=protected-access
         # refresh users
         users = get_user_dictionary(rah._os_util.get_users()) # pylint: disable=protected-access
         self.assertTrue(tstuser in users, "{0} missing from users".format(tstuser))
Exemplo n.º 28
0
 def test_parse_json_event(self, *args):  # pylint: disable=unused-argument
     data_str = load_data('ext/event.json')
     event = parse_json_event(data_str)  # pylint: disable=redefined-outer-name
     self.assertIsNotNone(event)
     self.assertNotEqual(0, event.parameters)
     self.assertTrue(all(param is not None for param in event.parameters))
Exemplo n.º 29
0
 def test_decrypt_encrypted_text_missing_private_key(self):
     encrypted_string = load_data("wire/encrypted.enc")
     prv_key = os.path.join(self.tmp_dir, "TransportPrivate.pem")
     crypto = CryptUtil(conf.get_openssl_cmd())
     self.assertRaises(CryptError, crypto.decrypt_secret, encrypted_string,
                       "abc" + prv_key)
Exemplo n.º 30
0
    def reload(self):
        self.version_info = load_data(self.data_files.get("version_info"))
        self.goal_state = load_data(self.data_files.get("goal_state"))
        self.hosting_env = load_data(self.data_files.get("hosting_env"))
        self.shared_config = load_data(self.data_files.get("shared_config"))
        self.certs = load_data(self.data_files.get("certs"))
        self.ext_conf = load_data(self.data_files.get("ext_conf"))
        self.manifest = load_data(self.data_files.get("manifest"))
        self.ga_manifest = load_data(self.data_files.get("ga_manifest"))
        self.trans_prv = load_data(self.data_files.get("trans_prv"))
        self.trans_cert = load_data(self.data_files.get("trans_cert"))
        self.ext = load_bin_data(self.data_files.get("test_ext"))

        remote_access_data_file = self.data_files.get("remote_access")
        if remote_access_data_file is not None:
            self.remote_access = load_data(remote_access_data_file)

        in_vm_artifacts_profile_file = self.data_files.get("in_vm_artifacts_profile")
        if in_vm_artifacts_profile_file is not None:
            self.in_vm_artifacts_profile = load_data(in_vm_artifacts_profile_file)