-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathidentity_linux_test.go
71 lines (57 loc) · 1.47 KB
/
identity_linux_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
// +build linux
package secureio_test
import (
"context"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
. "github.com/xaionaro-go/secureio"
)
func TestMissedKeySeedMessage(t *testing.T) {
conn0, conn1 := testUDPPair(t)
identity0, identity1, _c0, _c1 := testPair(t)
_c0.Close()
_c1.Close()
opts := &SessionOptions{}
opts.EnableDebug = true
opts.EnableInfo = true
opts.PacketIDStorageSize = -1 // it's UDP :(
opts.KeyExchangerOptions.RetryInterval = time.Millisecond // speed-up the unit test
attachLogsFunc := func(sess *Session) error {
printLogsOfSession(t, false, sess)
return nil
}
ctx, cancelFn := context.WithCancel(context.Background())
defer cancelFn()
go func() {
select {
case <-ctx.Done():
case <-time.After(time.Second):
}
}()
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
keys, err := identity0.MutualConfirmationOfIdentity(ctx, identity1, conn0, &testLogger{t}, opts, attachLogsFunc)
assert.NoError(t, err)
if assert.Equal(t, 4, len(keys)) {
assert.Equal(t, 32, len(keys[0]))
}
}()
// Getting one packet missed
readBuf := make([]byte, 65536)
_, err := conn1.Read(readBuf)
assert.NoError(t, err)
wg.Add(1)
go func() {
defer wg.Done()
keys, err := identity1.MutualConfirmationOfIdentity(ctx, identity0, conn1, &testLogger{t}, opts, attachLogsFunc)
assert.NoError(t, err)
if assert.Equal(t, 4, len(keys)) {
assert.Equal(t, 32, len(keys[0]))
}
}()
wg.Wait()
}