|
|
@ -273,18 +273,73 @@ func TestFunctionsUnmarshalJSON(t *testing.T) { |
|
|
|
"DateEquals": { "aws:CurrentTime": "2013-06-30T00:00:00Z" } |
|
|
|
"DateEquals": { "aws:CurrentTime": "2013-06-30T00:00:00Z" } |
|
|
|
}`) |
|
|
|
}`) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case5Data := []byte(`{ |
|
|
|
|
|
|
|
"StringLike": { |
|
|
|
|
|
|
|
"s3:x-amz-metadata-directive": "REPL*" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"StringEquals": { |
|
|
|
|
|
|
|
"s3:x-amz-copy-source": "mybucket/myobject", |
|
|
|
|
|
|
|
"s3:prefix": [ |
|
|
|
|
|
|
|
"", |
|
|
|
|
|
|
|
"home/" |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"s3:delimiter": [ |
|
|
|
|
|
|
|
"/" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"StringNotEquals": { |
|
|
|
|
|
|
|
"s3:x-amz-server-side-encryption": "AES256" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"NotIpAddress": { |
|
|
|
|
|
|
|
"aws:SourceIp": [ |
|
|
|
|
|
|
|
"10.1.10.0/24", |
|
|
|
|
|
|
|
"10.10.1.0/24" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"StringNotLike": { |
|
|
|
|
|
|
|
"s3:x-amz-storage-class": "STANDARD" |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"Null": { |
|
|
|
|
|
|
|
"s3:x-amz-server-side-encryption-customer-algorithm": true |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"IpAddress": { |
|
|
|
|
|
|
|
"aws:SourceIp": [ |
|
|
|
|
|
|
|
"192.168.1.0/24", |
|
|
|
|
|
|
|
"192.168.2.0/24" |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}`) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func2_1, err := newStringEqualsFunc(S3XAmzCopySource, NewValueSet(NewStringValue("mybucket/myobject"))) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("unexpected error. %v\n", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func2_2, err := newStringEqualsFunc(S3Prefix, NewValueSet(NewStringValue(""), NewStringValue("home/"))) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("unexpected error. %v\n", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func2_3, err := newStringEqualsFunc(S3Delimiter, NewValueSet(NewStringValue("/"))) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
t.Fatalf("unexpected error. %v\n", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testCases := []struct { |
|
|
|
testCases := []struct { |
|
|
|
data []byte |
|
|
|
data []byte |
|
|
|
expectedResult Functions |
|
|
|
expectedResult Functions |
|
|
|
expectErr bool |
|
|
|
expectErr bool |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
|
|
|
|
// Success case, basic conditions.
|
|
|
|
{case1Data, NewFunctions(func1, func2, func3, func4, func5, func6, func7), false}, |
|
|
|
{case1Data, NewFunctions(func1, func2, func3, func4, func5, func6, func7), false}, |
|
|
|
// duplicate condition error.
|
|
|
|
// Duplicate conditions, success case only one value is preserved.
|
|
|
|
{case2Data, NewFunctions(func6), false}, |
|
|
|
{case2Data, NewFunctions(func6), false}, |
|
|
|
// empty condition error.
|
|
|
|
// empty condition error.
|
|
|
|
{case3Data, nil, true}, |
|
|
|
{case3Data, nil, true}, |
|
|
|
// unsupported condition error.
|
|
|
|
// unsupported condition error.
|
|
|
|
{case4Data, nil, true}, |
|
|
|
{case4Data, nil, true}, |
|
|
|
|
|
|
|
// Success case multiple keys, same condition.
|
|
|
|
|
|
|
|
{case5Data, NewFunctions(func1, func2_1, func2_2, func2_3, func3, func4, func5, func6, func7), false}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for i, testCase := range testCases { |
|
|
|
for i, testCase := range testCases { |
|
|
|