Exemplo n.º 1
0
    public void ListBuckets()
    {
        CreateBucketSample createBucketSample = new CreateBucketSample();
        ListBucketsSample  listBucketsSample  = new ListBucketsSample();
        var bucketName = Guid.NewGuid().ToString();

        _bucketFixture.CreateBucket(bucketName);

        var buckets = listBucketsSample.ListBuckets(_bucketFixture.ProjectId);

        Assert.Contains(buckets, c => c.Name == bucketName);
    }
Exemplo n.º 2
0
    public void LockRetentionPolicy()
    {
        SetRetentionPolicySample  setRetentionPolicySample  = new SetRetentionPolicySample();
        LockRetentionPolicySample lockRetentionPolicySample = new LockRetentionPolicySample();

        var bucketName = Guid.NewGuid().ToString();

        _bucketFixture.CreateBucket(bucketName);

        setRetentionPolicySample.SetRetentionPolicy(bucketName, 10);
        var result = lockRetentionPolicySample.LockRetentionPolicy(bucketName);

        Assert.True(result);
    }
Exemplo n.º 3
0
    public void TestSetPublicAccessPreventionUnspecified()
    {
        SetPublicAccessPreventionUnspecifiedSample setPublicAccessPreventionUnspecifiedSample = new SetPublicAccessPreventionUnspecifiedSample();

        var bucketName = Guid.NewGuid().ToString();

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Set public access prevention to unspecified.
        var updatedBucket = setPublicAccessPreventionUnspecifiedSample.SetPublicAccessPreventionUnspecified(bucketName);

        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        Assert.Equal("unspecified", updatedBucket.IamConfiguration.PublicAccessPrevention);
    }
    public void TestEnableUniformBucketLevelAccess()
    {
        EnableUniformBucketLevelAccessSample enableUniformBucketLevelAccessSample = new EnableUniformBucketLevelAccessSample();

        var bucketName = Guid.NewGuid().ToString();

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Enable Uniform bucket level access.
        var updatedBucket = enableUniformBucketLevelAccessSample.EnableUniformBucketLevelAccess(bucketName);

        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        Assert.True(updatedBucket.IamConfiguration.UniformBucketLevelAccess.Enabled);
    }
Exemplo n.º 5
0
    public void TestGetUniformBucketLevelAccess()
    {
        EnableUniformBucketLevelAccessSample enableUniformBucketLevelAccessSample = new EnableUniformBucketLevelAccessSample();
        GetUniformBucketLevelAccessSample    getUniformBucketLevelAccessSample    = new GetUniformBucketLevelAccessSample();

        var bucketName = Guid.NewGuid().ToString();

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Enable Uniform bucket level access.
        enableUniformBucketLevelAccessSample.EnableUniformBucketLevelAccess(bucketName);
        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        var uniformBucketLevelAccess = getUniformBucketLevelAccessSample.GetUniformBucketLevelAccess(bucketName);

        Assert.True(uniformBucketLevelAccess.Enabled);
    }
Exemplo n.º 6
0
    public void TestGetPublicAccessPrevention()
    {
        GetPublicAccessPreventionSample getPublicAccessPreventionSample = new GetPublicAccessPreventionSample();

        var bucketName = Guid.NewGuid().ToString();

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Set public access prevention to enforced.
        SetPublicAccessPreventionEnforcedSample setPublicAccessPreventionEnforcedSample = new SetPublicAccessPreventionEnforcedSample();

        setPublicAccessPreventionEnforcedSample.SetPublicAccessPreventionEnforced(bucketName);
        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        var publicAccessPrevention = getPublicAccessPreventionSample.GetPublicAccessPrevention(bucketName);

        Assert.Equal("enforced", publicAccessPrevention);
    }
    public void TestEnableRequesterPays()
    {
        EnableRequesterPaysSample  enableRequesterPaysSample  = new EnableRequesterPaysSample();
        DisableRequesterPaysSample disableRequesterPaysSample = new DisableRequesterPaysSample();
        var bucketName = Guid.NewGuid().ToString();

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Enable request pay.
        var bucket = enableRequesterPaysSample.EnableRequesterPays(bucketName);

        _bucketFixture.SleepAfterBucketCreateUpdateDelete();
        Assert.True(bucket.Billing?.RequesterPays);

        // Disable request pay.
        disableRequesterPaysSample.DisableRequesterPays(_bucketFixture.ProjectId, bucketName);
        _bucketFixture.SleepAfterBucketCreateUpdateDelete();
    }
Exemplo n.º 8
0
    public void TestAddBucketConditionalIamBinding()
    {
        AddBucketConditionalIamBindingSample addBucketConditionalIamBindingSample = new AddBucketConditionalIamBindingSample();
        EnableUniformBucketLevelAccessSample enableUniformBucketLevelAccessSample = new EnableUniformBucketLevelAccessSample();
        var    bucketName = Guid.NewGuid().ToString();
        string memberType = "serviceAccount";
        string role       = "roles/storage.objectViewer";

        // Create bucket
        _bucketFixture.CreateBucket(bucketName);

        // Enable Uniform bucket level access.
        enableUniformBucketLevelAccessSample.EnableUniformBucketLevelAccess(bucketName);
        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        // Add Conditional Binding.
        var policy = addBucketConditionalIamBindingSample.AddBucketConditionalIamBinding(bucketName,
                                                                                         role, $"{memberType}:{_bucketFixture.ServiceAccountEmail}", "title", "description",
                                                                                         "resource.name.startsWith(\"projects/_/buckets/bucket-name/objects/prefix-a-\")");

        _bucketFixture.SleepAfterBucketCreateUpdateDelete();

        Assert.Contains(policy.Bindings, c => c.Members.Contains($"{memberType}:{_bucketFixture.ServiceAccountEmail}"));
    }