def test_build_filelist_dict(context, task_defn, formats, raises):
    full_path = os.path.join(
        context.config['work_dir'], 'cot', 'VALID_TASK_ID',
        'public/build/firefox-52.0a1.en-US.win64.installer.exe',
    )
    expected = {
        'public/build/firefox-52.0a1.en-US.win64.installer.exe': {
            'full_path': full_path,
            'formats': ['gpg'],
        }
    }
    context.task = task_defn

    # first, the file is missing...
    with pytest.raises(TaskVerificationError):
        stask.build_filelist_dict(context, formats)

    mkdir(os.path.dirname(full_path))
    with open(full_path, "w") as fh:
        fh.write("foo")

    if raises:
        # illegal format
        with pytest.raises(TaskVerificationError):
            stask.build_filelist_dict(context, formats)
    else:
        assert stask.build_filelist_dict(context, formats) == expected
def test_mkdir_does_make_dirs():
    with tempfile.TemporaryDirectory() as test_dir:
        end_dir = os.path.join(test_dir, 'dir_in_the_middle', 'leaf_dir')
        mkdir(end_dir)

        middle_dirs = list(os.scandir(test_dir))
        assertDirIsUniqueAndNamed(middle_dirs, 'dir_in_the_middle')

        leaf_dirs = list(os.scandir(middle_dirs[0].path))
        assertDirIsUniqueAndNamed(leaf_dirs, 'leaf_dir')
Exemple #3
0
def context(tmpdir):
    context = Context()
    context.config = get_default_config()
    context.config["signing_server_config"] = SERVER_CONFIG_PATH
    context.config["work_dir"] = os.path.join(tmpdir, "work")
    context.config["artifact_dir"] = os.path.join(tmpdir, "artifact")
    context.config["taskcluster_scope_prefixes"] = [DEFAULT_SCOPE_PREFIX]
    context.signing_servers = load_signing_server_config(context)
    mkdir(context.config["work_dir"])
    mkdir(context.config["artifact_dir"])
    yield context
Exemple #4
0
def context(tmpdir):
    context = Context()
    context.config = get_default_config()
    context.config['signing_server_config'] = SERVER_CONFIG_PATH
    context.config['work_dir'] = os.path.join(tmpdir, 'work')
    context.config['artifact_dir'] = os.path.join(tmpdir, 'artifact')
    context.config['taskcluster_scope_prefixes'] = [DEFAULT_SCOPE_PREFIX]
    context.signing_servers = load_signing_server_config(context)
    mkdir(context.config['work_dir'])
    mkdir(context.config['artifact_dir'])
    yield context
def context(tmpdir):
    context = Context()
    context.config = get_default_config()
    context.config["autograph_configs"] = SERVER_CONFIG_PATH
    context.config["work_dir"] = os.path.join(tmpdir, "work")
    context.config["artifact_dir"] = os.path.join(tmpdir, "artifact")
    context.config["taskcluster_scope_prefixes"] = [DEFAULT_SCOPE_PREFIX]
    context.autograph_configs = load_autograph_configs(SERVER_CONFIG_PATH)
    mkdir(context.config["work_dir"])
    mkdir(context.config["artifact_dir"])
    yield context
def test_mkdir_does_make_dirs(tmpdir):
    def assertDirIsUniqueAndNamed(dirs, name):
        assert len(dirs) == 1
        assert dirs[0].is_dir()
        assert dirs[0].name == name

    end_dir = os.path.join(tmpdir, "dir_in_the_middle", "leaf_dir")
    utils.mkdir(end_dir)

    middle_dirs = list(os.scandir(tmpdir))
    assertDirIsUniqueAndNamed(middle_dirs, "dir_in_the_middle")

    leaf_dirs = list(os.scandir(middle_dirs[0].path))
    assertDirIsUniqueAndNamed(leaf_dirs, "leaf_dir")
Exemple #7
0
def test_build_filelist_dict(context, task_defn):
    full_path = os.path.join(context.config["work_dir"], "cot", "VALID_TASK_ID", "public/build/firefox-52.0a1.en-US.win64.installer.exe")
    expected = {"public/build/firefox-52.0a1.en-US.win64.installer.exe": {"full_path": full_path, "formats": ["gpg"]}}
    context.task = task_defn

    # first, the file is missing...
    with pytest.raises(TaskVerificationError):
        stask.build_filelist_dict(context)

    mkdir(os.path.dirname(full_path))
    with open(full_path, "w") as fh:
        fh.write("foo")

    assert stask.build_filelist_dict(context) == expected
Exemple #8
0
async def _extract_tarfile(context, from_, compression, tmp_dir=None):
    work_dir = context.config["work_dir"]
    tmp_dir = tmp_dir or os.path.join(work_dir, "untarred")
    compression = _get_tarfile_compression(compression)
    try:
        files = []
        rm(tmp_dir)
        utils.mkdir(tmp_dir)
        with tarfile.open(from_, mode="r:{}".format(compression)) as t:
            t.extractall(path=tmp_dir)
            for name in t.getnames():
                path = os.path.join(tmp_dir, name)
                os.path.isfile(path) and files.append(path)
        return files
    except Exception as e:
        raise SigningScriptError(e)
def test_build_filelist_dict_comment(context, task_defn_authenticode_comment):
    full_path = os.path.join(
        context.config["work_dir"],
        "cot",
        "VALID_TASK_ID",
        "public/build/firefox-52.0a1.en-US.win64.installer.msi",
    )
    expected = {
        "public/build/firefox-52.0a1.en-US.win64.installer.msi": {
            "full_path": full_path,
            "formats": ["autograph_authenticode"],
            "comment": "Foo Installer"
        }
    }
    context.task = task_defn_authenticode_comment

    # first, format is wrong...
    with pytest.raises(TaskVerificationError) as error:
        stask.build_filelist_dict(context)
    assert "without an authenticode" in str(error.value)

    # coerce to authenticode
    context.task["payload"]["upstreamArtifacts"][0]["formats"] = [
        "autograph_authenticode"
    ]

    # Still raises due to no msi
    with pytest.raises(TaskVerificationError) as error:
        stask.build_filelist_dict(context)
    assert "outside of msi" in str(error.value)

    # coerce to msi
    context.task["payload"]["upstreamArtifacts"][0]["paths"] = [
        "public/build/firefox-52.0a1.en-US.win64.installer.msi",
    ]

    # the file is missing...
    with pytest.raises(TaskVerificationError):
        stask.build_filelist_dict(context)

    mkdir(os.path.dirname(full_path))
    with open(full_path, "w") as fh:
        fh.write("foo")

    # Now ok
    assert stask.build_filelist_dict(context) == expected
Exemple #10
0
async def _extract_zipfile(context, from_, files=None, tmp_dir=None):
    work_dir = context.config["work_dir"]
    tmp_dir = tmp_dir or os.path.join(work_dir, "unzipped")
    log.debug("Extracting {} from {} to {}...".format(files or "all files", from_, tmp_dir))
    try:
        extracted_files = []
        rm(tmp_dir)
        utils.mkdir(tmp_dir)
        with zipfile.ZipFile(from_, mode="r") as z:
            if files is not None:
                for name in files:
                    z.extract(name, path=tmp_dir)
                    extracted_files.append(os.path.join(tmp_dir, name))
            else:
                for name in z.namelist():
                    extracted_files.append(os.path.join(tmp_dir, name))
                z.extractall(path=tmp_dir)
        return extracted_files
    except Exception as e:
        raise SigningScriptError(e)
Exemple #11
0
async def _convert_dmg_to_tar_gz(context, from_):
    """Explode a dmg and tar up its contents. Return the relative tarball path."""
    work_dir = context.config["work_dir"]
    abs_from = os.path.join(work_dir, from_)
    # replace .dmg suffix with .tar.gz (case insensitive)
    to = re.sub(r"\.dmg$", ".tar.gz", from_, flags=re.I)
    abs_to = os.path.join(work_dir, to)
    dmg_executable_location = context.config["dmg"]
    hfsplus_executable_location = context.config["hfsplus"]

    with tempfile.TemporaryDirectory() as temp_dir:
        app_dir = os.path.join(temp_dir, "app")
        utils.mkdir(app_dir)
        undmg_cmd = [dmg_executable_location, "extract", abs_from, "tmp.hfs"]
        await utils.execute_subprocess(undmg_cmd, cwd=temp_dir, log_level=logging.DEBUG)
        hfsplus_cmd = [hfsplus_executable_location, "tmp.hfs", "extractall", "/", app_dir]
        await utils.execute_subprocess(hfsplus_cmd, cwd=temp_dir, log_level=logging.DEBUG)
        tar_cmd = ["tar", "czf", abs_to, "."]
        await utils.execute_subprocess(tar_cmd, cwd=app_dir)

    return to
async def _convert_dmg_to_tar_gz(context, from_):
    """Explode a dmg and tar up its contents. Return the relative tarball path."""
    work_dir = context.config['work_dir']
    abs_from = os.path.join(work_dir, from_)
    # replace .dmg suffix with .tar.gz (case insensitive)
    to = re.sub(r'\.dmg$', '.tar.gz', from_, flags=re.I)
    abs_to = os.path.join(work_dir, to)
    dmg_executable_location = context.config['dmg']
    hfsplus_executable_location = context.config['hfsplus']

    with tempfile.TemporaryDirectory() as temp_dir:
        app_dir = os.path.join(temp_dir, "app")
        utils.mkdir(app_dir)
        undmg_cmd = [dmg_executable_location, "extract", abs_from, "tmp.hfs"]
        await utils.execute_subprocess(undmg_cmd, cwd=temp_dir)
        hfsplus_cmd = [
            hfsplus_executable_location, "tmp.hfs", "extractall", "/", app_dir
        ]
        await utils.execute_subprocess(hfsplus_cmd, cwd=temp_dir)
        tar_cmd = ['tar', 'czvf', abs_to, '.']
        await utils.execute_subprocess(tar_cmd, cwd=app_dir)

    return to
def test_mkdir_mutes_os_errors(mocker):
    m = mocker.patch.object(os, "makedirs")
    m.side_effect = OSError
    utils.mkdir("/dummy/dir")
    m.assert_called_with("/dummy/dir")
def test_mkdir_mutes_os_errors(makedirs):
    makedirs.side_effect = OSError
    mkdir('/dummy/dir')
    makedirs.assert_called_with('/dummy/dir')