Exemple #1
0
 def test_verbose(self):
     payload_script = 'echo hello123'
     archive = archive_builder_docker.build_archive(
         payload_script=payload_script,
         verbose=True,
         docker_image='python:3')
     output, errors = archive_builder_docker.run_archive(archive, timeout=5)
     output = output.strip()
     self.assertEqual(output, 'hello123')
Exemple #2
0
 def test_cli_args(self):
     payload_script = 'echo hi'
     archive = archive_builder_docker.build_archive(
         payload_script=payload_script,
         verbose=True,
         docker_image='python:3')
     output, errors = archive_builder_docker.run_archive(archive,
                                                         cli_args='--help',
                                                         timeout=5)
     output = output.strip()
     self.assertEqual(output, 'hi --help')
Exemple #3
0
 def test_local_output(self):
     mnts = []
     try:
         shutil.rmtree(TESTING_OUTPUT_DIR)
     except OSError:
         pass
     temp_dir = TESTING_OUTPUT_DIR
     os.makedirs(TESTING_OUTPUT_DIR)
     mnts.append(
         mount.MountLocal(local_dir=temp_dir,
                          mount_point='/mymount',
                          output=True))
     payload_script = 'echo hello123 > /mymount/secret.txt'
     archive = archive_builder_docker.build_archive(
         payload_script=payload_script,
         verbose=False,
         docker_image='python:3',
         mounts=mnts)
     archive_builder_docker.run_archive(archive,
                                        timeout=5,
                                        get_output=False)
     with open(path.join(temp_dir, 'secret.txt'), 'r') as f:
         output = f.read()
     self.assertEqual(output, 'hello123\n')
Exemple #4
0
    def test_local_repo(self):
        mnts = []
        mnts.append(
            mount.MountLocal(local_dir=TESTING_DIR,
                             mount_point='./mymount',
                             output=False))
        payload_script = 'cat ./mymount/secret.txt'

        archive = archive_builder_docker.build_archive(
            payload_script=payload_script,
            verbose=False,
            docker_image='python:3',
            mounts=mnts)
        output, errors = archive_builder_docker.run_archive(archive, timeout=5)
        output = output.strip()
        self.assertEqual(output, 'apple')
Exemple #5
0
    def test_git_repo(self):
        mnts = []
        mnts.append(
            mount.MountGit(git_url='https://github.com/justinjfu/doodad.git',
                           branch='archive_builder_test',
                           mount_point='./code/doodad'))

        payload_script = 'python3 ./code/doodad/test/hello_world.py'
        archive = archive_builder_docker.build_archive(
            payload_script=payload_script,
            verbose=False,
            docker_image='python:3',
            mounts=mnts)
        output, errors = archive_builder_docker.run_archive(archive, timeout=5)
        output = output.strip()
        self.assertEqual(output, 'hello world!')
Exemple #6
0
    def test_git_repo_pythonpath(self):
        mnts = []
        mnts.append(
            mount.MountGit(git_url='https://github.com/justinjfu/doodad.git',
                           branch='archive_builder_test',
                           ssh_identity='~/.ssh/github',
                           mount_point='./code/doodad',
                           pythonpath=True))

        payload_script = 'python3 ./code/doodad/test/test_import.py'
        archive = archive_builder_docker.build_archive(
            payload_script=payload_script,
            verbose=False,
            docker_image='python:3',
            mounts=mnts)
        output, errors = archive_builder_docker.run_archive(archive, timeout=5)
        output = output.strip()
        self.assertEqual(output, 'apple')