2014-11-30 12:38:45 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
2015-03-11 21:01:07 +01:00
|
|
|
"github.com/hashicorp/aws-sdk-go/aws"
|
|
|
|
"github.com/hashicorp/aws-sdk-go/gen/ec2"
|
2014-11-30 12:38:45 +01:00
|
|
|
)
|
|
|
|
|
2015-03-11 21:01:07 +01:00
|
|
|
func Test_expandNetworkACLEntry(t *testing.T) {
|
2014-11-30 12:38:45 +01:00
|
|
|
input := []interface{}{
|
|
|
|
map[string]interface{}{
|
2014-12-01 09:49:05 +01:00
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": 22,
|
|
|
|
"to_port": 22,
|
2014-11-30 12:38:45 +01:00
|
|
|
"cidr_block": "0.0.0.0/0",
|
2014-12-01 09:49:05 +01:00
|
|
|
"action": "deny",
|
|
|
|
"rule_no": 1,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
map[string]interface{}{
|
2014-12-01 09:49:05 +01:00
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": 443,
|
|
|
|
"to_port": 443,
|
2014-11-30 12:38:45 +01:00
|
|
|
"cidr_block": "0.0.0.0/0",
|
2014-12-01 09:49:05 +01:00
|
|
|
"action": "deny",
|
|
|
|
"rule_no": 2,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
}
|
2014-12-08 11:48:39 +01:00
|
|
|
expanded, _ := expandNetworkAclEntries(input, "egress")
|
2014-11-30 12:38:45 +01:00
|
|
|
|
2015-03-11 21:01:07 +01:00
|
|
|
expected := []ec2.NetworkACLEntry{
|
|
|
|
ec2.NetworkACLEntry{
|
2015-03-11 22:21:22 +01:00
|
|
|
Protocol: aws.String("6"),
|
2015-03-11 21:01:07 +01:00
|
|
|
PortRange: &ec2.PortRange{
|
|
|
|
From: aws.Integer(22),
|
|
|
|
To: aws.Integer(22),
|
|
|
|
},
|
|
|
|
RuleAction: aws.String("deny"),
|
|
|
|
RuleNumber: aws.Integer(1),
|
|
|
|
CIDRBlock: aws.String("0.0.0.0/0"),
|
|
|
|
Egress: aws.Boolean(true),
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
2015-03-11 21:01:07 +01:00
|
|
|
ec2.NetworkACLEntry{
|
2015-03-11 22:21:22 +01:00
|
|
|
Protocol: aws.String("6"),
|
2015-03-11 21:01:07 +01:00
|
|
|
PortRange: &ec2.PortRange{
|
|
|
|
From: aws.Integer(443),
|
|
|
|
To: aws.Integer(443),
|
|
|
|
},
|
|
|
|
RuleAction: aws.String("deny"),
|
|
|
|
RuleNumber: aws.Integer(2),
|
|
|
|
CIDRBlock: aws.String("0.0.0.0/0"),
|
|
|
|
Egress: aws.Boolean(true),
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
2014-12-01 09:49:05 +01:00
|
|
|
}
|
2014-11-30 12:38:45 +01:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(expanded, expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2014-12-01 09:49:05 +01:00
|
|
|
expanded,
|
2014-11-30 12:38:45 +01:00
|
|
|
expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-11 21:01:07 +01:00
|
|
|
func Test_flattenNetworkACLEntry(t *testing.T) {
|
2014-12-01 09:49:05 +01:00
|
|
|
|
2015-03-11 21:01:07 +01:00
|
|
|
apiInput := []ec2.NetworkACLEntry{
|
|
|
|
ec2.NetworkACLEntry{
|
|
|
|
Protocol: aws.String("tcp"),
|
|
|
|
PortRange: &ec2.PortRange{
|
|
|
|
From: aws.Integer(22),
|
|
|
|
To: aws.Integer(22),
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
2015-03-11 21:01:07 +01:00
|
|
|
RuleAction: aws.String("deny"),
|
|
|
|
RuleNumber: aws.Integer(1),
|
|
|
|
CIDRBlock: aws.String("0.0.0.0/0"),
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
2015-03-11 21:01:07 +01:00
|
|
|
ec2.NetworkACLEntry{
|
|
|
|
Protocol: aws.String("tcp"),
|
|
|
|
PortRange: &ec2.PortRange{
|
|
|
|
From: aws.Integer(443),
|
|
|
|
To: aws.Integer(443),
|
2014-12-01 09:49:05 +01:00
|
|
|
},
|
2015-03-11 21:01:07 +01:00
|
|
|
RuleAction: aws.String("deny"),
|
|
|
|
RuleNumber: aws.Integer(2),
|
|
|
|
CIDRBlock: aws.String("0.0.0.0/0"),
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
flattened := flattenNetworkAclEntries(apiInput)
|
|
|
|
|
|
|
|
expected := []map[string]interface{}{
|
2014-12-01 09:49:05 +01:00
|
|
|
map[string]interface{}{
|
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": 22,
|
|
|
|
"to_port": 22,
|
2014-11-30 12:38:45 +01:00
|
|
|
"cidr_block": "0.0.0.0/0",
|
2014-12-01 09:49:05 +01:00
|
|
|
"action": "deny",
|
|
|
|
"rule_no": 1,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
map[string]interface{}{
|
2014-12-01 09:49:05 +01:00
|
|
|
"protocol": "tcp",
|
|
|
|
"from_port": 443,
|
|
|
|
"to_port": 443,
|
2014-11-30 12:38:45 +01:00
|
|
|
"cidr_block": "0.0.0.0/0",
|
2014-12-01 09:49:05 +01:00
|
|
|
"action": "deny",
|
|
|
|
"rule_no": 2,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(flattened, expected) {
|
|
|
|
t.Fatalf(
|
|
|
|
"Got:\n\n%#v\n\nExpected:\n\n%#v\n",
|
2014-12-01 09:49:05 +01:00
|
|
|
flattened[0],
|
2014-11-30 12:38:45 +01:00
|
|
|
expected)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|