22
22
import storage_add_bucket_iam_member
23
23
import storage_add_bucket_conditional_iam_binding
24
24
import storage_view_bucket_iam_members
25
+ import storage_remove_bucket_conditional_iam_binding
25
26
26
27
MEMBER = "group:[email protected] "
27
28
ROLE = "roles/storage.legacyBucketReader"
28
29
29
30
CONDITION_TITLE = "match-prefix"
30
31
CONDITION_DESCRIPTION = "Applies to objects matching a prefix"
31
- CONDITION_EXPRESSION = "resource.name.startsWith(\" projects/_/buckets/bucket-name/objects/prefix-a-\" )"
32
+ CONDITION_EXPRESSION = (
33
+ 'resource.name.startsWith("projects/_/buckets/bucket-name/objects/prefix-a-")'
34
+ )
32
35
33
36
34
37
@pytest .fixture
35
38
def bucket ():
36
39
bucket = None
37
40
while bucket is None or bucket .exists ():
41
+ storage_client = storage .Client ()
38
42
bucket_name = "test-iam-{}" .format (uuid .uuid4 ())
39
- bucket = storage .Client ().bucket (bucket_name )
40
- bucket .create ()
41
- bucket .iam_configuration .uniform_bucket_level_access_enabled = True
42
- bucket .patch ()
43
+ bucket = storage_client .bucket (bucket_name )
44
+ bucket .iam_configuration .uniform_bucket_level_access_enabled = True
45
+ storage_client .create_bucket (bucket )
43
46
yield bucket
44
47
time .sleep (3 )
45
48
bucket .delete (force = True )
@@ -66,16 +69,17 @@ def test_add_bucket_conditional_iam_binding(bucket):
66
69
CONDITION_TITLE ,
67
70
CONDITION_DESCRIPTION ,
68
71
CONDITION_EXPRESSION ,
69
- {MEMBER }
72
+ {MEMBER },
70
73
)
71
74
policy = bucket .get_iam_policy (requested_policy_version = 3 )
72
75
assert any (
73
- binding ["role" ] == ROLE and
74
- binding ["members" ] == {MEMBER } and
75
- binding ["condition" ] == {
76
+ binding ["role" ] == ROLE
77
+ and binding ["members" ] == {MEMBER }
78
+ and binding ["condition" ]
79
+ == {
76
80
"title" : CONDITION_TITLE ,
77
81
"description" : CONDITION_DESCRIPTION ,
78
- "expression" : CONDITION_EXPRESSION
82
+ "expression" : CONDITION_EXPRESSION ,
79
83
}
80
84
for binding in policy .bindings
81
85
)
@@ -89,3 +93,20 @@ def test_remove_bucket_iam_member(bucket):
89
93
binding ["role" ] == ROLE and MEMBER in binding ["members" ]
90
94
for binding in policy .bindings
91
95
)
96
+
97
+
98
+ def test_remove_bucket_conditional_iam_binding (bucket ):
99
+ storage_remove_bucket_conditional_iam_binding .remove_bucket_conditional_iam_binding (
100
+ bucket .name , ROLE , CONDITION_TITLE , CONDITION_DESCRIPTION , CONDITION_EXPRESSION
101
+ )
102
+
103
+ policy = bucket .get_iam_policy (requested_policy_version = 3 )
104
+ condition = {
105
+ "title" : CONDITION_TITLE ,
106
+ "description" : CONDITION_DESCRIPTION ,
107
+ "expression" : CONDITION_EXPRESSION ,
108
+ }
109
+ assert not any (
110
+ (binding ["role" ] == ROLE and binding .get ("condition" ) == condition )
111
+ for binding in policy .bindings
112
+ )
0 commit comments