getBucketPolicy() is called and the result is validated.
(t *testing.T)
| 1358 | |
| 1359 | // getBucketPolicy() is called and the result is validated. |
| 1360 | func TestGetBucketPolicy(t *testing.T) { |
| 1361 | helloCondMap := make(ConditionMap) |
| 1362 | helloCondKeyMap := make(ConditionKeyMap) |
| 1363 | helloCondKeyMap.Add("s3:prefix", set.CreateStringSet("hello")) |
| 1364 | helloCondMap.Add("StringEquals", helloCondKeyMap) |
| 1365 | |
| 1366 | worldCondMap := make(ConditionMap) |
| 1367 | worldCondKeyMap := make(ConditionKeyMap) |
| 1368 | worldCondKeyMap.Add("s3:prefix", set.CreateStringSet("world")) |
| 1369 | worldCondMap.Add("StringEquals", worldCondKeyMap) |
| 1370 | |
| 1371 | notHelloCondMap := make(ConditionMap) |
| 1372 | notHelloCondMap.Add("StringNotEquals", worldCondKeyMap) |
| 1373 | |
| 1374 | // StringLike condition map for "hello*" |
| 1375 | stringLikeHelloCondMap := make(ConditionMap) |
| 1376 | stringLikeHelloCondKeyMap := make(ConditionKeyMap) |
| 1377 | stringLikeHelloCondKeyMap.Add("s3:prefix", set.CreateStringSet("hello*")) |
| 1378 | stringLikeHelloCondMap.Add("StringLike", stringLikeHelloCondKeyMap) |
| 1379 | |
| 1380 | // StringLike condition map for "world*" |
| 1381 | stringLikeWorldCondMap := make(ConditionMap) |
| 1382 | stringLikeWorldCondKeyMap := make(ConditionKeyMap) |
| 1383 | stringLikeWorldCondKeyMap.Add("s3:prefix", set.CreateStringSet("world*")) |
| 1384 | stringLikeWorldCondMap.Add("StringLike", stringLikeWorldCondKeyMap) |
| 1385 | |
| 1386 | // StringNotLike condition map for "hello*" |
| 1387 | stringNotLikeHelloCondMap := make(ConditionMap) |
| 1388 | stringNotLikeHelloCondKeyMap := make(ConditionKeyMap) |
| 1389 | stringNotLikeHelloCondKeyMap.Add("s3:prefix", set.CreateStringSet("hello*")) |
| 1390 | stringNotLikeHelloCondMap.Add("StringNotLike", stringNotLikeHelloCondKeyMap) |
| 1391 | |
| 1392 | // StringNotLike condition map for "world*" |
| 1393 | stringNotLikeWorldCondMap := make(ConditionMap) |
| 1394 | stringNotLikeWorldCondKeyMap := make(ConditionKeyMap) |
| 1395 | stringNotLikeWorldCondKeyMap.Add("s3:prefix", set.CreateStringSet("world*")) |
| 1396 | stringNotLikeWorldCondMap.Add("StringNotLike", stringNotLikeWorldCondKeyMap) |
| 1397 | |
| 1398 | testCases := []struct { |
| 1399 | statement Statement |
| 1400 | prefix string |
| 1401 | expectedResult1 bool |
| 1402 | expectedResult2 bool |
| 1403 | expectedResult3 bool |
| 1404 | }{ |
| 1405 | // Statement with invalid Effect. |
| 1406 | {Statement{ |
| 1407 | Actions: readOnlyBucketActions, |
| 1408 | Effect: "Deny", |
| 1409 | Principal: User{AWS: set.CreateStringSet("*")}, |
| 1410 | Resources: set.CreateStringSet("arn:aws:s3:::mybucket"), |
| 1411 | }, "", false, false, false}, |
| 1412 | // Statement with invalid Effect with prefix. |
| 1413 | {Statement{ |
| 1414 | Actions: readOnlyBucketActions, |
| 1415 | Effect: "Deny", |
| 1416 | Principal: User{AWS: set.CreateStringSet("*")}, |
| 1417 | Resources: set.CreateStringSet("arn:aws:s3:::mybucket"), |
nothing calls this directly
no test coverage detected