示例#1
0
def test_registry_defaults(tmpdir):
    registry = DockerRegistry(
        docker_config_path=str(tmpdir.join("doesntexist.json")))
    assert registry.url == "https://registry-1.docker.io"
    assert registry.auth_config_url == "https://index.docker.io/v1"
    assert (registry.token_url ==
            "https://auth.docker.io/token?service=registry.docker.io")
    assert registry.username == ""
    assert registry.password == ""
示例#2
0
def test_registry_username_password(tmpdir):
    config_json = tmpdir.join("dockerconfig.json")
    with config_json.open("w") as f:
        json.dump(
            {
                "auths": {
                    "https://index.docker.io/v1": {
                        "auth":
                        base64.encodebytes(b"user:pass").decode("ascii")
                    }
                }
            },
            f,
        )
    registry = DockerRegistry(docker_config_path=str(config_json))
    assert registry.username == "user"
    assert registry.password == "pass"
    assert registry.url == "https://registry-1.docker.io"
示例#3
0
async def test_get_image_manifest(tmpdir, request):
    username = "******"
    password = "******"
    test_handle = {"username": username, "password": password}
    app = Application([
        (r"/token", MockTokenHandler, {
            "test_handle": test_handle
        }),
        (
            r"/v2/([^/]+)/manifests/([^/]+)",
            MockManifestHandler,
            {
                "test_handle": test_handle
            },
        ),
    ])
    ip = "127.0.0.1"
    port = 10504
    url = f"http://{ip}:{port}"
    app.listen(port, ip)
    config_json = tmpdir.join("dockerconfig.json")
    with config_json.open("w") as f:
        json.dump(
            {
                "auths": {
                    url: {
                        "auth":
                        base64.encodebytes(
                            f"{username}:{password}".encode()).decode("ascii")
                    }
                }
            },
            f,
        )
    registry = DockerRegistry(docker_config_path=str(config_json),
                              token_url=url + "/token",
                              url=url)
    assert registry.url == url
    assert registry.auth_config_url == url
    assert registry.token_url == url + "/token"
    assert registry.username == username
    assert registry.password == password
    manifest = await registry.get_image_manifest("myimage", "abc123")
    assert manifest == {"image": "myimage", "tag": "abc123"}
示例#4
0
def test_registry_gcr_defaults(tmpdir):
    config_json = tmpdir.join("dockerconfig.json")
    with config_json.open("w") as f:
        json.dump(
            {
                "auths": {
                    "https://gcr.io": {
                        "auth":
                        base64.encodebytes(b"_json_key:{...}").decode("ascii")
                    }
                }
            },
            f,
        )
    registry = DockerRegistry(docker_config_path=str(config_json))
    assert registry.url == "https://gcr.io"
    assert registry.auth_config_url == "https://gcr.io"
    assert registry.token_url == "https://gcr.io/v2/token?service=gcr.io"
    assert registry.username == "_json_key"
    assert registry.password == "{...}"