Exemplo n.º 1
0
 def test_inject_file_cmd_exception(self):
     test = file_inject.FileInject()
     error, message = test.injectfile_cmd('Unencoded data')
     self.assertEqual(error, "500", "Did not get expected error code")
     self.assertEqual(
         message,
         "Error doing base64 decoding of data",
         "Did not get expected message on error"
     )
Exemplo n.º 2
0
    def test_inject_file_cmd(self):
        test = file_inject.FileInject()
        encode_details = base64.b64encode(
            b'/tmp/tests/test_file_write,Testing the inject'
        )
        error, message = test.injectfile_cmd(encode_details)
        self.assertEqual(error, "0", "Did not get expected error code")
        self.assertEqual(
            message,
            "",
            "Did not get expected message on success"
        )
        files = glob.glob('/tmp/tests/test_file*')
        self.assertEqual(
            len(files),
            1,
            'Did not find any files'
        )
        found_file = False
        temp_contents = None
        for f in files:
            if '/tmp/tests/test_file_write' == f:
                with open(f) as temp_file:
                    temp_contents = temp_file.read()

                found_file = True

        assert found_file, 'Did not find written file in expected path'
        self.assertEqual(
            temp_contents,
            'Testing the inject',
            'Written data in file is not what was expected'
        )
        permissions = os.stat('/tmp/tests/test_file_write')
        try:
            readable_perms = stat.filemode(permissions.st_mode)
        except Exception:
            readable_perms = self.permissions_to_unix_name(permissions)

        self.assertEqual(
            readable_perms,
            '-rw-------',
            'Permissions are not 600 as expected'
        )
    def test_inject_file_cmd(self):
        test = file_inject.FileInject()
        encode_details = base64.b64encode(
            b'/tmp/tests/test_file_write,Testing the inject')
        error, message = test.injectfile_cmd(encode_details)
        self.assertEqual(error, "0", "Did not get expected error code")
        self.assertEqual(message, "",
                         "Did not get expected message on success")
        files = glob.glob('/tmp/tests/test_file*')
        self.assertEqual(len(files), 1, 'Did not find any files')
        found_file = False
        temp_contents = None
        for f in files:
            if '/tmp/tests/test_file_write' == f:
                with open(f) as temp_file:
                    temp_contents = temp_file.read()

                found_file = True

        assert found_file, 'Did not find written file in expected path'
        self.assertEqual(temp_contents, 'Testing the inject',
                         'Written data in file is not what was expected')
Exemplo n.º 4
0
 def test_instantiate_file_inject(self):
     file_inject.FileInject()
     assert True, 'Class did not generate exception'