Ejemplo n.º 1
0
def test_set_endpoint(endpoint, test_bucket_name, monkeypatch):
    key, secret, token = fetch_sts_token(STSAccessKeyId, STSAccessKeySecret,
                                         STSArn)
    monkeypatch.delenv("OSS_ENDPOINT")
    ossfs = OSSFileSystem(key=key, secret=secret, token=token, endpoint=None)
    with pytest.raises(ValueError):
        ossfs.ls(test_bucket_name)
    ossfs.set_endpoint(endpoint)
    ossfs.ls(test_bucket_name)
Ejemplo n.º 2
0
def test_sts_login(endpoint, test_bucket_name):
    key, secret, token = fetch_sts_token(STSAccessKeyId, STSAccessKeySecret,
                                         STSArn)
    ossfs = OSSFileSystem(
        key=key,
        secret=secret,
        token=token,
        endpoint=endpoint,
    )
    ossfs.ls(test_bucket_name)
Ejemplo n.º 3
0
def test_anonymous_access(oss):
    oss = OSSFileSystem(anon=True)
    assert oss.ls("") == []
    # TODO: public bucket doesn't work through moto

    with pytest.raises(PermissionError):
        oss.mkdir("newbucket")
Ejemplo n.º 4
0
def test_public_file(oss):
    # works on real oss, not on moto
    test_bucket_name = "ossfs_public_test"
    other_bucket_name = "ossfs_private_test"

    oss.touch(test_bucket_name)
    oss.touch(test_bucket_name + "/afile")
    oss.touch(other_bucket_name, acl="public-read")
    oss.touch(other_bucket_name + "/afile", acl="public-read")

    s = OSSFileSystem(anon=True)
    with pytest.raises(PermissionError):
        s.ls(test_bucket_name)
    s.ls(other_bucket_name)

    oss.chmod(test_bucket_name, acl="public-read")
    oss.chmod(other_bucket_name, acl="private")
    with pytest.raises(PermissionError):
        s.ls(other_bucket_name, refresh=True)
    assert s.ls(test_bucket_name, refresh=True)

    # public file in private bucket
    with oss.open(other_bucket_name + "/see_me", "wb", acl="public-read") as f:
        f.write(b"hello")
    assert s.cat(other_bucket_name + "/see_me") == b"hello"
Ejemplo n.º 5
0
def test_multiple_objects(oss):
    other_oss = OSSFileSystem(key=key, secret=secret, endpoint=endpoint)
    assert oss.ls(f"{test_bucket_name}/test") == other_oss.ls(f"{test_bucket_name}/test")
Ejemplo n.º 6
0
def test_env_endpoint(endpoint, test_bucket_name, monkeypatch):
    key, secret, token = fetch_sts_token(STSAccessKeyId, STSAccessKeySecret,
                                         STSArn)
    monkeypatch.setenv("OSS_ENDPOINT", endpoint)
    ossfs = OSSFileSystem(key=key, secret=secret, token=token, endpoint=None)
    ossfs.ls(test_bucket_name)
Ejemplo n.º 7
0
 def task(num):  # pylint: disable=unused-argument
     ossfs = OSSFileSystem(**init_config)
     ossfs.ls(test_bucket_name)
     time.sleep(5)
     ossfs.ls(test_bucket_name)
     return True