2014-11-30 12:38:45 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/mitchellh/goamz/ec2"
|
|
|
|
)
|
|
|
|
|
2014-12-03 08:34:28 +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-01 09:49:05 +01:00
|
|
|
expanded := expandNetworkAclEntries(input, "egress")
|
2014-11-30 12:38:45 +01:00
|
|
|
|
|
|
|
expected := []ec2.NetworkAclEntry{
|
|
|
|
ec2.NetworkAclEntry{
|
2014-12-01 09:49:05 +01:00
|
|
|
Protocol: 6,
|
2014-11-30 12:38:45 +01:00
|
|
|
PortRange: ec2.PortRange{
|
2014-12-01 09:49:05 +01:00
|
|
|
From: 22,
|
|
|
|
To: 22,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
RuleAction: "deny",
|
|
|
|
RuleNumber: 1,
|
2014-12-01 09:49:05 +01:00
|
|
|
CidrBlock: "0.0.0.0/0",
|
|
|
|
Egress: true,
|
|
|
|
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
ec2.NetworkAclEntry{
|
2014-12-01 09:49:05 +01:00
|
|
|
Protocol: 6,
|
2014-11-30 12:38:45 +01:00
|
|
|
PortRange: ec2.PortRange{
|
2014-12-01 09:49:05 +01:00
|
|
|
From: 443,
|
|
|
|
To: 443,
|
|
|
|
},
|
2014-11-30 12:38:45 +01:00
|
|
|
RuleAction: "deny",
|
|
|
|
RuleNumber: 2,
|
2014-12-01 09:49:05 +01:00
|
|
|
CidrBlock: "0.0.0.0/0",
|
|
|
|
Egress: true,
|
|
|
|
IcmpCode: ec2.IcmpCode{Code: 0, Type: 0},
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-03 08:34:28 +01:00
|
|
|
func Test_flattenNetworkAclEntry(t *testing.T) {
|
2014-12-01 09:49:05 +01:00
|
|
|
|
2014-11-30 12:38:45 +01:00
|
|
|
apiInput := []ec2.NetworkAclEntry{
|
|
|
|
ec2.NetworkAclEntry{
|
2014-12-01 09:49:05 +01:00
|
|
|
Protocol: 6,
|
2014-11-30 12:38:45 +01:00
|
|
|
PortRange: ec2.PortRange{
|
2014-12-01 09:49:05 +01:00
|
|
|
From: 22,
|
|
|
|
To: 22,
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
RuleAction: "deny",
|
|
|
|
RuleNumber: 1,
|
2014-12-01 09:49:05 +01:00
|
|
|
CidrBlock: "0.0.0.0/0",
|
2014-11-30 12:38:45 +01:00
|
|
|
},
|
|
|
|
ec2.NetworkAclEntry{
|
2014-12-01 09:49:05 +01:00
|
|
|
Protocol: 6,
|
2014-11-30 12:38:45 +01:00
|
|
|
PortRange: ec2.PortRange{
|
2014-12-01 09:49:05 +01:00
|
|
|
From: 443,
|
|
|
|
To: 443,
|
|
|
|
},
|
2014-11-30 12:38:45 +01:00
|
|
|
RuleAction: "deny",
|
|
|
|
RuleNumber: 2,
|
2014-12-01 09:49:05 +01:00
|
|
|
CidrBlock: "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)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|