def test_raises_error_when_return_code_is_not_0(self):
        with patch("subprocess.run") as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 1

            with self.assertRaises(SignatureError):
                jarsigner.verify(self.context, {"certificate_alias": "nightly"}, "/path/to/apk")
示例#2
0
async def async_main(context):
    android_product = task.extract_android_product_from_scopes(context)
    product_config = _get_product_config(context, android_product)
    publish_config = get_publish_config(product_config, context.task['payload'], android_product)
    contact_server = not bool(context.config.get('do_not_contact_server'))

    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(contact_server, publish_config['dry_run'], publish_config['target_store'])

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(context)

    all_apks_paths = [
        artifact
        for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list
        if artifact.endswith('.apk')
    ]

    if not publish_config.get('skip_check_signature', True):
        log.info('Verifying APKs\' signatures...')
        for apk_path in all_apks_paths:
            jarsigner.verify(context, publish_config, apk_path)
            manifest.verify(product_config, apk_path)
    else:
        log.info('This product is configured with "skip_check_signature", so the signing of the '
                 'APK will not be verified.')

    log.info('Delegating publication to mozapkpublisher...')
    with contextlib.ExitStack() as stack:
        files = [stack.enter_context(open(apk_file_name)) for apk_file_name in all_apks_paths]
        publish.publish(product_config, publish_config, files, contact_server)

    log.info('Done!')
    def test_raises_error_when_return_code_is_not_0(self):
        with patch('subprocess.run') as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 1

            with self.assertRaises(SignatureError):
                jarsigner.verify(self.context, '/path/to/apk')
示例#4
0
    def test_raises_error_when_no_digest_algo_is_returned_by_jarsigner(self):
        with patch('subprocess.run') as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 0
            run.return_value.stdout = 'Some random output'

            with self.assertRaises(SignatureError):
                jarsigner.verify(self.context, '/path/to/apk')
示例#5
0
    def test_raises_error_when_digest_is_not_sha1(self):
        with patch('subprocess.run') as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 0
            run.return_value.stdout = 'Digest algorithm: SHA256'

            with self.assertRaises(SignatureError):
                jarsigner.verify(self.context, '/path/to/apk')
    def test_verify_should_call_executable_with_defaults_arguments(self):
        with patch("subprocess.run") as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 0
            run.return_value.stdout = "Digest algorithm: SHA1"
            jarsigner.verify(self.minimal_context, {"certificate_alias": "nightly"}, "/path/to/apk")

            run.assert_called_with(
                ["jarsigner", "-verify", "-strict", "-verbose", "-keystore", "/path/to/keystore", "/path/to/apk", "nightly"],
                stdout=subprocess.PIPE,
                stderr=subprocess.STDOUT,
                universal_newlines=True,
            )
    def test_verify_should_call_executable_with_defaults_arguments(self):
        with patch('subprocess.run') as run:
            run.return_value = MagicMock()
            run.return_value.returncode = 0
            run.return_value.stdout = 'Digest algorithm: SHA1'
            jarsigner.verify(self.minimal_context, '/path/to/apk')

            run.assert_called_with([
                'jarsigner', '-verify', '-strict', '-verbose', '-keystore',
                '/path/to/keystore', '/path/to/apk', 'nightly'
            ],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.STDOUT,
                                   universal_newlines=True)
示例#8
0
async def async_main(context):
    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(context)

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = get_upstream_artifacts_full_paths_per_task_id(context)

    all_apks_paths = [
        artifact
        for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list
        if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    [jarsigner.verify(context, apk_path) for apk_path in all_apks_paths]

    log.info('Finding whether Google Play strings can be updated...')
    google_play_strings_path = googleplay.get_google_play_strings_path(
        artifacts_per_task_id, failed_artifacts_per_task_id
    )

    log.info('Delegating publication to mozapkpublisher...')
    googleplay.publish_to_googleplay(
        context, all_apks_paths, google_play_strings_path,
    )

    log.info('Done!')
示例#9
0
async def async_main(context):
    android_product = task.extract_android_product_from_scopes(context)
    product_config = _get_product_config(context, android_product)
    contact_google_play = not bool(
        context.config.get('do_not_contact_google_play'))

    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(contact_google_play, context.task['payload'])

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_apks_paths = [
        artifact for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    for apk_path in all_apks_paths:
        jarsigner.verify(context, apk_path)
        manifest.verify(product_config, apk_path)

    if product_config['update_google_play_strings']:
        log.info('Finding whether Google Play strings can be updated...')
        strings_path = googleplay.get_google_play_strings_path(
            artifacts_per_task_id, failed_artifacts_per_task_id)
    else:
        log.warning(
            'This product does not upload strings automatically. Skipping Google Play strings search.'
        )
        strings_path = None

    log.info('Delegating publication to mozapkpublisher...')
    with contextlib.ExitStack() as stack:
        files = [
            stack.enter_context(open(apk_file_name))
            for apk_file_name in all_apks_paths
        ]
        strings_file = stack.enter_context(
            open(strings_path)) if strings_path is not None else None
        googleplay.publish_to_googleplay(context.task['payload'],
                                         product_config, files,
                                         contact_google_play, strings_file)

    log.info('Done!')
    def test_verify_should_call_executable_with_right_arguments(self):
        for android_product, alias in (("aurora", "nightly"), ("focus", "focus"), ("fenix", "fenix-beta")):
            self.context.task["scopes"] = ["project:releng:googleplay:{}".format(android_product)]
            with patch("subprocess.run") as run:
                run.return_value = MagicMock()
                run.return_value.returncode = 0
                run.return_value.stdout = """
                    smk      632 Mon Feb 01 12:54:21 CET 2016 application.ini
                        Digest algorithm: SHA1
                """
                jarsigner.verify(self.context, {"certificate_alias": alias}, "/path/to/apk")

                run.assert_called_with(
                    ["/path/to/jarsigner", "-verify", "-strict", "-verbose", "-keystore", "/path/to/keystore", "/path/to/apk", alias],
                    stdout=subprocess.PIPE,
                    stderr=subprocess.STDOUT,
                    universal_newlines=True,
                )
示例#11
0
    def test_verify_should_call_executable_with_right_arguments(self):
        for android_product, alias in self.context.config[
                'jarsigner_certificate_aliases'].items():
            self.context.task['scopes'] = [
                'project:releng:googleplay:{}'.format(android_product)
            ]
            with patch('subprocess.run') as run:
                run.return_value = MagicMock()
                run.return_value.returncode = 0
                run.return_value.stdout = '''
                    smk      632 Mon Feb 01 12:54:21 CET 2016 application.ini
                        Digest algorithm: SHA1
                '''
                jarsigner.verify(self.context, '/path/to/apk')

                run.assert_called_with([
                    '/path/to/jarsigner', '-verify', '-strict', '-verbose',
                    '-keystore', '/path/to/keystore', '/path/to/apk', alias
                ],
                                       stdout=subprocess.PIPE,
                                       stderr=subprocess.STDOUT,
                                       universal_newlines=True)
示例#12
0
async def async_main(context):
    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(context)

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_apks_paths = [
        artifact for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    for apk_path in all_apks_paths:
        jarsigner.verify(context, apk_path)
        manifest.verify(context, apk_path)

    if task.extract_android_product_from_scopes(context) in [
            'focus', 'reference-browser'
    ]:
        log.warning(
            'This product does not upload strings automatically. Skipping Google Play strings search.'
        )
        google_play_strings_path = None
    else:
        log.info('Finding whether Google Play strings can be updated...')
        google_play_strings_path = googleplay.get_google_play_strings_path(
            artifacts_per_task_id, failed_artifacts_per_task_id)

    log.info('Delegating publication to mozapkpublisher...')
    googleplay.publish_to_googleplay(
        context,
        all_apks_paths,
        google_play_strings_path,
    )

    log.info('Done!')