forked from msgboxio/ike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init_test.go
75 lines (64 loc) · 1.99 KB
/
init_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package ike
import (
"net"
"testing"
"github.com/msgboxio/ike/crypto"
"github.com/msgboxio/ike/platform"
"github.com/msgboxio/ike/protocol"
"github.com/pkg/errors"
)
// simple initiator & responder
func TestInit(t *testing.T) {
var cfg = testConfig()
cfg.LocalID = pskTestID
cfg.PeerID = pskTestID
_, net, _ := net.ParseCIDR("192.0.2.0/24")
cfg.AddNetworkSelectors(net, net, true)
chi := make(chan []byte, 1)
chr := make(chan []byte, 1)
sa := make(chan *platform.SaParams, 1)
cerr := make(chan error, 1)
go runTestResponder(cfg, &testcb{chi, sa, cerr}, chr, logger)
go runTestInitiator(cfg, &testcb{chr, sa, cerr}, chi, logger)
if err := waitFor2Sa(t, sa, cerr); err != nil {
t.Fail()
}
}
// test with COOKIE
func TestInit1(t *testing.T) {
var cfg = testConfig()
cfg.ThrottleInitRequests = true
cfg.LocalID = pskTestID
cfg.PeerID = pskTestID
_, net, _ := net.ParseCIDR("192.0.2.0/24")
cfg.AddNetworkSelectors(net, net, true)
chi := make(chan []byte, 1)
chr := make(chan []byte, 1)
sa := make(chan *platform.SaParams, 1)
cerr := make(chan error, 1)
go runTestResponder(cfg, &testcb{chi, sa, cerr}, chr, logger)
go runTestInitiator(cfg, &testcb{chr, sa, cerr}, chi, logger)
if err := waitFor2Sa(t, sa, cerr); err != nil {
t.Fail()
}
}
// Initiator cannot handle INVALID_KE_PAYLOAD, responder can generate one
func TestInit2(t *testing.T) {
var cfg1 = testConfig()
cfg1.ProposalIke = crypto.Aes128Sha256Ecp256
cfg1.LocalID = pskTestID
cfg1.PeerID = pskTestID
_, net, _ := net.ParseCIDR("192.0.2.0/24")
cfg1.AddNetworkSelectors(net, net, true)
chi := make(chan []byte, 1)
chr := make(chan []byte, 1)
sa := make(chan *platform.SaParams, 1)
cerr := make(chan error, 1)
go runTestInitiator(cfg1, &testcb{chr, sa, cerr}, chi, logger)
var cfg2 = *cfg1
cfg2.ProposalIke = crypto.Aes128Sha256Modp3072
go runTestResponder(&cfg2, &testcb{chi, sa, cerr}, chr, logger)
if err := waitFor2Sa(t, sa, cerr); errors.Cause(err) != protocol.ERR_INVALID_KE_PAYLOAD {
t.Error("wrong Error", err)
}
}