def test_remote_regular_build(self):
        """Test RemoteRegularBuild."""
        self.mock.stub().SetupRegularBuild.return_value = (
            untrusted_runner_pb2.SetupBuildResponse(
                result=True,
                app_path='/release/bin/app',
                app_path_debug='',
                app_dir='/release/bin',
                build_dir='/release',
                build_url='https://build/url.zip'))

        build = build_setup_host.RemoteRegularBuild('/', 1337,
                                                    'https://build/url.zip')
        self.assertTrue(build.setup())
        self.assertEqual(os.environ['APP_PATH'], '/release/bin/app')
        self.assertEqual(os.environ['APP_PATH_DEBUG'], '')
        self.assertEqual(os.environ['APP_DIR'], '/release/bin')
        self.assertEqual(os.environ['BUILD_DIR'], '/release')
        self.assertEqual(os.environ['BUILD_URL'], 'https://build/url.zip')
        self.assertEqual(os.environ['APP_REVISION'], '1337')

        self.mock.stub().SetupRegularBuild.return_value = (
            untrusted_runner_pb2.SetupBuildResponse(result=False))
        self.assertFalse(build.setup())
        self.assertFalse(os.getenv('APP_PATH'))
        self.assertFalse(os.getenv('APP_PATH_DEBUG'))
        self.assertFalse(os.getenv('APP_DIR'))
        self.assertFalse(os.getenv('BUILD_DIR'))
        self.assertFalse(os.getenv('BUILD_URL'))
        self.assertFalse(os.getenv('APP_REVISION'))
    def test_remote_production_build(self):
        """Test RemoteProductionBuild."""
        self.mock.stub().SetupProductionBuild.return_value = (
            untrusted_runner_pb2.SetupBuildResponse(
                result=True,
                app_path='/stable/bin/app',
                app_path_debug='',
                app_dir='/stable/bin',
                build_dir='/stable',
                build_url='https://build/url-stable.zip'))

        build = build_setup_host.RemoteProductionBuild(
            '/', '43.0.0.1', 'https://build/url-stable.zip', 'stable')

        self.assertTrue(build.setup())
        self.assertEqual(os.environ['APP_PATH'], '/stable/bin/app')
        self.assertEqual(os.environ['APP_PATH_DEBUG'], '')
        self.assertEqual(os.environ['APP_DIR'], '/stable/bin')
        self.assertEqual(os.environ['BUILD_DIR'], '/stable')
        self.assertEqual(os.environ['BUILD_URL'],
                         'https://build/url-stable.zip')
        self.assertEqual(os.environ['APP_REVISION'], '43.0.0.1')

        self.mock.stub().SetupProductionBuild.return_value = (
            untrusted_runner_pb2.SetupBuildResponse(result=False))
        self.assertFalse(build.setup())
        self.assertFalse(os.getenv('APP_PATH'))
        self.assertFalse(os.getenv('APP_PATH_DEBUG'))
        self.assertFalse(os.getenv('APP_DIR'))
        self.assertFalse(os.getenv('BUILD_DIR'))
        self.assertFalse(os.getenv('BUILD_URL'))
        self.assertFalse(os.getenv('APP_REVISION'))
Example #3
0
def _build_response(result):
    if not result:
        return untrusted_runner_pb2.SetupBuildResponse(result=False)

    return untrusted_runner_pb2.SetupBuildResponse(
        result=True,
        app_path=environment.get_value('APP_PATH'),
        app_path_debug=environment.get_value('APP_PATH_DEBUG'),
        app_dir=environment.get_value('APP_DIR'),
        build_dir=environment.get_value('BUILD_DIR'),
        build_url=environment.get_value('BUILD_URL'),
        fuzz_target=environment.get_value('FUZZ_TARGET'))
    def test_set_env_vars_from_fuzzer(self):
        """Test setting APP_PATH etc from FUZZER_DIR as a fallback."""
        os.environ['FUZZER_DIR'] = '/fuzzer_dir'

        self.mock.stub().SetupRegularBuild.return_value = (
            untrusted_runner_pb2.SetupBuildResponse(
                result=True,
                app_path='',
                app_path_debug='',
                app_dir='',
                build_dir='/release',
                build_url='https://build/url.zip'))
        self.mock.set_environment_vars.side_effect = _mock_set_environment_vars

        build = build_setup_host.RemoteRegularBuild('/', 1337,
                                                    'https://build/url.zip')
        self.assertTrue(build.setup())
        self.assertEqual(os.getenv('APP_PATH'), '')
        self.assertEqual(os.getenv('APP_DIR'), '')
        self.assertEqual(os.getenv('BUILD_DIR'), '/release')
        self.assertEqual(os.getenv('BUILD_URL'), 'https://build/url.zip')
        self.assertEqual(os.getenv('APP_REVISION'), '1337')