コード例 #1
0
    def test_cd_without_shell(self):
        ECHO_CWD_COMMAND = 'python -c "import os; print(os.getcwd())"'
        tmp = tempfile.gettempdir()
        COMMAND = 'cd "{0}" && {1}'.format(tmp, ECHO_CWD_COMMAND)

        with self.assertRaises(ExecuteCommandParseError):
            execute(COMMAND)
コード例 #2
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_cd_without_shell(self):
        ECHO_CWD_COMMAND = 'python -c "import os; print(os.getcwd())"'
        tmp = tempfile.gettempdir()
        COMMAND = 'cd "{0}" && {1}'.format(tmp, ECHO_CWD_COMMAND)

        with self.assertRaises(ExecuteCommandParseError):
            execute(COMMAND)
コード例 #3
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_execute_raise_non_zero_error_by_default(self):
        command = '''python -c "import sys; sys.exit(23);"'''
        with self.assertRaises(ExecuteCommandNonZeroExitStatus):
            z = execute(command)
            self.assertExecuteResult(z, 23, b'', None, None)

        z = execute(command, check_return_code_and_raise_error=False)
        self.assertExecuteResult(z, 23, b'', None, None)
コード例 #4
0
    def test_set_env_variable2(self):
        env_name = 'AKAWKFN'
        command = self.make_print_env_variable_command(env_name)
        z = execute(command)
        self.assertExecuteResult(z, 0, b'None', None, None)

        z = execute(command, env=self.make_python_env({env_name: "SEC!"}))
        self.assertExecuteResult(z, 0, b'SEC!', None, None)
コード例 #5
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_set_env_variable2(self):
        env_name = 'AKAWKFN'
        command = self.make_print_env_variable_command(env_name)
        z = execute(command)
        self.assertExecuteResult(z, 0, b'None', None, None)

        z = execute(command, env=self.make_python_env({env_name: "SEC!"}))
        self.assertExecuteResult(z, 0, b'SEC!', None, None)
コード例 #6
0
    def test_execute_raise_non_zero_error_by_default(self):
        command = '''python -c "import sys; sys.exit(23);"'''
        with self.assertRaises(ExecuteCommandNonZeroExitStatus):
            z = execute(command)
            self.assertExecuteResult(z, 23, b'', None, None)

        z = execute(command, check_return_code_and_raise_error=False)
        self.assertExecuteResult(z, 23, b'', None, None)
コード例 #7
0
ファイル: event.py プロジェクト: pahaz/wflow
def run(command, cwd, do_log=lambda x: log.debug(x.decode().strip())):
    log.debug("run '{0}'".format(command))
    execute(
        command,
        cwd=cwd,
        stderr_to_stdout=True,
        do_on_read_stdout=do_log,
        check_return_code_and_raise_error=False,
    )
コード例 #8
0
def run(command, cwd, do_log=lambda x: log.debug(x.decode().strip())):
    log.debug("run '{0}'".format(command))
    execute(
        command,
        cwd=cwd,
        stderr_to_stdout=True,
        do_on_read_stdout=do_log,
        check_return_code_and_raise_error=False,
    )
コード例 #9
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_exit_1_or_echo_1(self):
        EXIT_1_COMMAND = 'python -c "import sys; sys.exit(1)"'
        ECHO_1_COMMAND = 'python -c "print(1)"'
        COMMAND = "{0} || {1}".format(EXIT_1_COMMAND, ECHO_1_COMMAND)

        with self.assertRaises(ExecuteCommandParseError):
            execute(COMMAND)

        r = execute(COMMAND, shell=True)
        self.assertEqual(r.stdout_text.strip(), "1")
コード例 #10
0
    def test_exit_1_or_echo_1(self):
        EXIT_1_COMMAND = 'python -c "import sys; sys.exit(1)"'
        ECHO_1_COMMAND = 'python -c "print(1)"'
        COMMAND = "{0} || {1}".format(EXIT_1_COMMAND, ECHO_1_COMMAND)

        with self.assertRaises(ExecuteCommandParseError):
            execute(COMMAND)

        r = execute(COMMAND, shell=True)
        self.assertEqual(r.stdout_text.strip(), "1")
コード例 #11
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_set_env_variable(self):
        command = 'python -c "import sys, os; ' \
                  'os.environ.get(\'SSECRET\') == \'SSEC!\' and ' \
                  'sys.exit(24);"'
        z = execute(command)
        self.assertExecuteResult(z, 0, b'', None, None)

        command = 'python -c "import sys, os; ' \
                  'os.environ.get(\'SSECRET\') == \'SSEC!\' or ' \
                  'sys.exit(24);"'
        z = execute(command, env=self.make_python_env({'SSECRET': 'SSEC!'}))
        self.assertExecuteResult(z, 0, b'', None, None)
コード例 #12
0
    def test_set_env_variable(self):
        command = 'python -c "import sys, os; ' \
                  'os.environ.get(\'SSECRET\') == \'SSEC!\' and ' \
                  'sys.exit(24);"'
        z = execute(command)
        self.assertExecuteResult(z, 0, b'', None, None)

        command = 'python -c "import sys, os; ' \
                  'os.environ.get(\'SSECRET\') == \'SSEC!\' or ' \
                  'sys.exit(24);"'
        z = execute(command, env=self.make_python_env({'SSECRET': 'SSEC!'}))
        self.assertExecuteResult(z, 0, b'', None, None)
コード例 #13
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_cd(self):
        ECHO_CWD_COMMAND = 'python -c "import os; print(os.getcwd())"'
        tmp = tempfile.gettempdir()
        COMMAND = 'cd "{0}" && {1}'.format(tmp, ECHO_CWD_COMMAND)

        r = execute(COMMAND, shell=True)
        self.assertEqual(r.stdout_text.strip(), tmp)
コード例 #14
0
    def test_cd(self):
        ECHO_CWD_COMMAND = 'python -c "import os; print(os.getcwd())"'
        tmp = tempfile.gettempdir()
        COMMAND = 'cd "{0}" && {1}'.format(tmp, ECHO_CWD_COMMAND)

        r = execute(COMMAND, shell=True)
        self.assertEqual(r.stdout_text.strip(), tmp)
コード例 #15
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
    def test_insecurity_execute_with_shell_true(self):
        command = '"{0}" -c "import sys; ' \
                  'print(\\\"SSS! $SSS %SSS%\\\")"' \
            .format(self.get_python_command_path())
        z = execute(command, env=self.make_python_env({"SSS": "+"}),
                    shell=True)

        self.assertEqual(z.returncode, 0)
        self.assertNotEqual(z.stdout, b'SSS! $SSS %SSS%')
コード例 #16
0
    def test_insecurity_execute_with_shell_true(self):
        command = '"{0}" -c "import sys; ' \
                  'print(\\\"SSS! $SSS %SSS%\\\")"' \
            .format(self.get_python_command_path())
        z = execute(command,
                    env=self.make_python_env({"SSS": "+"}),
                    shell=True)

        self.assertEqual(z.returncode, 0)
        self.assertNotEqual(z.stdout, b'SSS! $SSS %SSS%')
コード例 #17
0
ファイル: command.py プロジェクト: pahaz/wflow
    def take_action(self, parsed_args):
        env = self.env
        context = get_git_context(parsed_args.git_url, self.log)
        data_path = env[PLATFORM_DATA_PATH_KEY]
        secure_repo_dir_name = context[REPO_DIR_NAME_KEY]
        dns_name = context[DNS_NAME_KEY]

        repo_local_path = os.path.join(data_path, secure_repo_dir_name)

        self.log.debug('init new repo {0}'.format(repo_local_path))

        self.write_message_for_user("receive {0} project".format(dns_name))

        execute(
            "git init --bare '{name}'".format(name=secure_repo_dir_name),
            cwd=data_path,
            stderr_to_stdout=True,
            do_on_read_stdout=lambda x: self.log.debug(x.decode()),
        )

        self.log.debug('start git-receive-pack')

        try:
            subprocess.check_call(
                'cd {0} && git-receive-pack {name}'
                .format(data_path, name=secure_repo_dir_name),
                shell=True
            )
        except subprocess.CalledProcessError as e:
            self.log.error("git-receive-pack problem #{0}"
                           .format(e.returncode))
            return
        except OSError as e:
            self.log.exception(e)
            raise

        self.trigger_event('git-receive-pack', env, context)

        self.log.debug('finish git-receive-pack')
コード例 #18
0
ファイル: command.py プロジェクト: marciopocebon/wflow
    def take_action(self, parsed_args):
        env = self.env
        context = get_git_context(parsed_args.git_url, self.log)
        data_path = env[PLATFORM_DATA_PATH_KEY]
        secure_repo_dir_name = context[REPO_DIR_NAME_KEY]
        dns_name = context[DNS_NAME_KEY]

        repo_local_path = os.path.join(data_path, secure_repo_dir_name)

        self.log.debug('init new repo {0}'.format(repo_local_path))

        self.write_message_for_user("receive {0} project".format(dns_name))

        execute(
            "git init --bare '{name}'".format(name=secure_repo_dir_name),
            cwd=data_path,
            stderr_to_stdout=True,
            do_on_read_stdout=lambda x: self.log.debug(x.decode()),
        )

        self.log.debug('start git-receive-pack')

        try:
            subprocess.check_call('cd {0} && git-receive-pack {name}'.format(
                data_path, name=secure_repo_dir_name),
                                  shell=True)
        except subprocess.CalledProcessError as e:
            self.log.error("git-receive-pack problem #{0}".format(
                e.returncode))
            return
        except OSError as e:
            self.log.exception(e)
            raise

        self.trigger_event('git-receive-pack', env, context)

        self.log.debug('finish git-receive-pack')
コード例 #19
0
ファイル: test_docker.py プロジェクト: marciopocebon/wflow
 def tearDownClass(cls):
     execute('rm -r "{0}"'.format(cls.TEST_DIR))
コード例 #20
0
ファイル: test_docker.py プロジェクト: marciopocebon/wflow
 def setUpClass(cls):
     TEST_PROJECTS = ['tests/apps/python-simple']
     cls.TEST_DIR = TEST_DIR = tempfile.mkdtemp(prefix='wflow-docker-')
     cls.TEST_PROJECTS = [os.path.basename(p) for p in TEST_PROJECTS]
     print('TEST_DIR = {0}; TEST_PROJECTS = {1}'.format(
         TEST_DIR, cls.TEST_PROJECTS))
     for t_project in TEST_PROJECTS:
         name = os.path.basename(t_project)
         t_project = os.path.abspath(t_project)
         t_project_path = os.path.abspath(os.path.join(TEST_DIR, name))
         t_project_path_source = os.path.join(t_project_path, 'SOURCE')
         execute('mkdir {path}'.format(path=t_project_path))
         # execute('mkdir {path}'.format(path=t_project_path_source))
         execute('cp -r "{0}" "{1}"'.format(t_project,
                                            t_project_path_source))
         execute('git init --bare', cwd=t_project_path)
         execute('git init', cwd=t_project_path_source)
         execute('git add *', cwd=t_project_path_source)
         execute('git commit -am "init"',
                 cwd=t_project_path_source,
                 check_return_code_and_raise_error=False)
         execute('git push "{0}" master'.format(t_project_path),
                 cwd=t_project_path_source)
コード例 #21
0
ファイル: interactive.py プロジェクト: 8iq/wflow
 def do_run(self, line):
     try:
         execute(line)
     except (BaseExecuteCommandError, OSError) as e:
         print(e)
コード例 #22
0
ファイル: test_container.py プロジェクト: marciopocebon/wflow
 def test_puling_image(self):
     execute('docker rmi busybox')
     self.make_container(image='busybox')
コード例 #23
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
 def test_security_execute_with_shell_false(self):
     command = '"{0}" -c "import sys; ' \
               'print(\\\"SSS! $SSS %SSS%\\\")"' \
         .format(self.get_python_command_path())
     z = execute(command)
     self.assertExecuteResult(z, 0, b'SSS! $SSS %SSS%', None, None)
コード例 #24
0
 def test_execute_result(self):
     command = '''python -c "print('hi!')"'''
     z = execute(command)
     self.assertExecuteResult(z, 0, b'hi!', None, None)
     self.assertEqual(z.cmd, command)
コード例 #25
0
 def test_timeout(self):
     command = 'python -c "import time; time.sleep(0.5);"'
     with self.assertRaises(ExecuteCommandTimeoutExpired):
         execute(command, timeout=0.2)
コード例 #26
0
 def test_security_execute_with_shell_false(self):
     command = '"{0}" -c "import sys; ' \
               'print(\\\"SSS! $SSS %SSS%\\\")"' \
         .format(self.get_python_command_path())
     z = execute(command)
     self.assertExecuteResult(z, 0, b'SSS! $SSS %SSS%', None, None)
コード例 #27
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
 def test_timeout(self):
     command = 'python -c "import time; time.sleep(0.5);"'
     with self.assertRaises(ExecuteCommandTimeoutExpired):
         execute(command, timeout=0.2)
コード例 #28
0
ファイル: test_container.py プロジェクト: 8iq/wflow
 def test_puling_image(self):
     execute('docker rmi busybox')
     self.make_container(image='busybox')
コード例 #29
0
ファイル: test_execute3.py プロジェクト: 8iq/wflow
 def test_execute_result(self):
     command = '''python -c "print('hi!')"'''
     z = execute(command)
     self.assertExecuteResult(z, 0, b'hi!', None, None)
     self.assertEqual(z.cmd, command)
コード例 #30
0
ファイル: interactive.py プロジェクト: marciopocebon/wflow
 def do_run(self, line):
     try:
         execute(line)
     except (BaseExecuteCommandError, OSError) as e:
         print(e)