summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-11-04 15:31:22 (GMT)
committerChristian Pointner <equinox@anytun.org>2017-11-04 15:31:22 (GMT)
commit48dfb520974502f724255b101572c67cdd120d6c (patch)
tree2e3600aaf21bd0306b9d48cadd42d83a6dc6a473
parent99ef9725cd769fc1a46675b594e9114bed734c2c (diff)
some tests for SA
-rw-r--r--satp/security-association.go1
-rw-r--r--satp/security-association_test.go47
2 files changed, 34 insertions, 14 deletions
diff --git a/satp/security-association.go b/satp/security-association.go
index f20e138..c5093de 100644
--- a/satp/security-association.go
+++ b/satp/security-association.go
@@ -95,6 +95,7 @@ func (sa *SecurityAssociation) SequenceNumberCheckAndSet(senderID uint16, sequen
func NewSecurityAssociation(kd KeyDerivation, numEndpoints uint, initialSeqNrOutbound, initialSeqNrInbound uint32) (sa *SecurityAssociation) {
sa = &SecurityAssociation{kd: kd}
+ // panic if numEndpoints == 0?
sa.endpoints = make([]*net.UDPAddr, numEndpoints)
sa.nextSeqNr = initialSeqNrOutbound
sa.initialSeqNrInbound = initialSeqNrInbound
diff --git a/satp/security-association_test.go b/satp/security-association_test.go
index d2bdb35..ab3592e 100644
--- a/satp/security-association_test.go
+++ b/satp/security-association_test.go
@@ -131,18 +131,37 @@ func TestSecurityAssociationEndpointsEqual(t *testing.T) {
}
}
-// func TestSecurityAssociationEndpointUpdate(t *testing.T) {
-// addr4, err := net.ResolveUDPAddr("udp4", "1.2.3.4:444")
-// if err != nil {
-// t.Fatal("unexpected error:", err)
-// }
+func TestSecurityAssociationEndpointUpdate(t *testing.T) {
+ addr4, _ := net.ResolveUDPAddr("udp4", "1.2.3.4:444")
+ addr6, _ := net.ResolveUDPAddr("udp6", "[2a02::1]:666")
-// addr6, err := net.ResolveUDPAddr("udp6", "[2a02::1]:666")
-// if err != nil {
-// t.Fatal("unexpected error:", err)
-// }
-// sa := NewSecurityAssociation(nil, 3, 0, 0)
-// sa.EndpointUpdate(0, addr4)
-// sa.EndpointUpdate(2, addr6)
-// t.Logf("%v", sa.endpoints)
-// }
+ // should this panic??
+ sa := NewSecurityAssociation(nil, 0, 0, 0)
+ sa.EndpointUpdate(0, addr4)
+
+ sa = NewSecurityAssociation(nil, 1, 0, 0)
+ if sa.endpoints[0] != nil {
+ t.Fatalf("endpoints[0] is %v but should be nil", sa.endpoints[0])
+ }
+ sa.EndpointUpdate(0, addr4)
+ if !EndpointsEqual(sa.endpoints[0], addr4) {
+ t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr4)
+ }
+ sa.EndpointUpdate(0, addr6)
+ if !EndpointsEqual(sa.endpoints[0], addr6) {
+ t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr6)
+ }
+
+ sa = NewSecurityAssociation(nil, 3, 0, 0)
+ sa.EndpointUpdate(0, addr4)
+ sa.EndpointUpdate(2, addr6)
+ if !EndpointsEqual(sa.endpoints[0], addr4) {
+ t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr4)
+ }
+ if sa.endpoints[1] != nil {
+ t.Fatalf("endpoints[1] is %v but should be nil", sa.endpoints[0])
+ }
+ if !EndpointsEqual(sa.endpoints[2], addr6) {
+ t.Fatalf("endpoints[2] is %v but should be %v", sa.endpoints[0], addr6)
+ }
+}