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)
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)
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")
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"
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")
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)
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