MCPcopy
hub / github.com/minio/minio-go / TestAppendStatement

Function TestAppendStatement

pkg/policy/bucket-policy_test.go:1168–1357  ·  view source on GitHub ↗

appendStatement() is called and the result is validated.

(t *testing.T)

Source from the content-addressed store, hash-verified

1166
1167// appendStatement() is called and the result is validated.
1168func TestAppendStatement(t *testing.T) {
1169 condMap := make(ConditionMap)
1170 condKeyMap := make(ConditionKeyMap)
1171 condKeyMap.Add("s3:prefix", set.CreateStringSet("hello"))
1172 condMap.Add("StringEquals", condKeyMap)
1173
1174 condMap1 := make(ConditionMap)
1175 condKeyMap1 := make(ConditionKeyMap)
1176 condKeyMap1.Add("s3:prefix", set.CreateStringSet("world"))
1177 condMap1.Add("StringEquals", condKeyMap1)
1178
1179 unknownCondMap1 := make(ConditionMap)
1180 unknownCondKeyMap1 := make(ConditionKeyMap)
1181 unknownCondKeyMap1.Add("s3:prefix", set.CreateStringSet("world"))
1182 unknownCondMap1.Add("StringNotEquals", unknownCondKeyMap1)
1183
1184 testCases := []struct {
1185 statements []Statement
1186 statement Statement
1187 expectedResult string
1188 }{
1189 // Empty statements and empty new statement.
1190 {[]Statement{}, Statement{}, `[]`},
1191 // Non-empty statements and empty new statement.
1192 {[]Statement{{
1193 Actions: readOnlyBucketActions,
1194 Effect: "Allow",
1195 Principal: User{AWS: set.CreateStringSet("*")},
1196 Resources: set.CreateStringSet("arn:aws:s3:::mybucket"),
1197 }}, Statement{}, `[{"Action":["s3:ListBucket"],"Effect":"Allow","Principal":{"AWS":["*"]},"Resource":["arn:aws:s3:::mybucket"],"Sid":""}]`},
1198 // Empty statements and non-empty new statement.
1199 {[]Statement{}, Statement{
1200 Actions: readOnlyBucketActions,
1201 Effect: "Allow",
1202 Principal: User{AWS: set.CreateStringSet("*")},
1203 Resources: set.CreateStringSet("arn:aws:s3:::mybucket"),
1204 }, `[{"Action":["s3:ListBucket"],"Effect":"Allow","Principal":{"AWS":["*"]},"Resource":["arn:aws:s3:::mybucket"],"Sid":""}]`},
1205 // Append existing statement.
1206 {[]Statement{{
1207 Actions: readOnlyBucketActions,
1208 Effect: "Allow",
1209 Principal: User{AWS: set.CreateStringSet("*")},
1210 Resources: set.CreateStringSet("arn:aws:s3:::mybucket"),
1211 }}, Statement{
1212 Actions: readOnlyBucketActions,
1213 Effect: "Allow",
1214 Principal: User{AWS: set.CreateStringSet("*")},
1215 Resources: set.CreateStringSet("arn:aws:s3:::mybucket"),
1216 }, `[{"Action":["s3:ListBucket"],"Effect":"Allow","Principal":{"AWS":["*"]},"Resource":["arn:aws:s3:::mybucket"],"Sid":""}]`},
1217 // Append same statement with different resource.
1218 {[]Statement{{
1219 Actions: readOnlyBucketActions,
1220 Effect: "Allow",
1221 Principal: User{AWS: set.CreateStringSet("*")},
1222 Resources: set.CreateStringSet("arn:aws:s3:::mybucket"),
1223 }}, Statement{
1224 Actions: readOnlyBucketActions,
1225 Effect: "Allow",

Callers

nothing calls this directly

Calls 5

CreateStringSetFunction · 0.92
appendStatementFunction · 0.85
MarshalMethod · 0.65
AddMethod · 0.45
UnionMethod · 0.45

Tested by

no test coverage detected