コード例 #1
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"
コード例 #2
0
def test_anonymous_login(file_in_anonymous, endpoint):
    ossfs = OSSFileSystem(endpoint=endpoint)
    ossfs.cat(f"{file_in_anonymous}")