-
Notifications
You must be signed in to change notification settings - Fork 209
Expand file tree
/
Copy pathsupported_groups_test.go
More file actions
74 lines (63 loc) · 2.37 KB
/
Copy pathsupported_groups_test.go
File metadata and controls
74 lines (63 loc) · 2.37 KB
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
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package dtls
import (
"context"
"slices"
"testing"
"time"
dtlsstate "github.com/pion/dtls/v3/internal/state"
cryptosuite "github.com/pion/dtls/v3/pkg/crypto/ciphersuite"
"github.com/pion/dtls/v3/pkg/crypto/elliptic"
dtlsnet "github.com/pion/dtls/v3/pkg/net"
"github.com/pion/dtls/v3/pkg/protocol"
"github.com/pion/transport/v4/dpipe"
"github.com/pion/transport/v4/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// Assert that supported_groups advertises every configured group in order.
func TestSupportedGroups(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()
// Check for leaking routines
report := test.CheckRoutines(t)
defer report()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
supportedGroups := elliptic.Curves()
require.Contains(t, supportedGroups, elliptic.X25519MLKEM768)
expectedGroups := make([]elliptic.Curve, 0, len(supportedGroups))
for group := range supportedGroups {
expectedGroups = append(expectedGroups, group)
}
expectedGroups = effectiveEllipticCurves(expectedGroups)
slices.Sort(expectedGroups)
slices.Reverse(expectedGroups)
type result struct {
conn *Conn
err error
}
clientResult := make(chan result, 1)
ca, cb := dpipe.Pipe()
go func() {
client, err := testClient(ctx, dtlsnet.PacketConnFromConn(ca), ca.RemoteAddr(), []ClientOption{WithCipherSuites(cryptosuite.TLS_AES_128_GCM_SHA256), WithEllipticCurves(expectedGroups...), WithMinVersion(protocol.Version1_3), WithMaxVersion(protocol.Version1_3)}, false)
clientResult <- result{conn: client, err: err}
}()
server, err := testServer(ctx, dtlsnet.PacketConnFromConn(cb), cb.RemoteAddr(), []ServerOption{WithCipherSuites(cryptosuite.TLS_AES_128_GCM_SHA256), WithMinVersion(protocol.Version1_3), WithMaxVersion(protocol.Version1_3)}, true)
client := <-clientResult
defer func() {
if server != nil {
assert.NoError(t, server.Close())
}
if client.conn != nil {
assert.NoError(t, client.conn.Close())
}
}()
require.NoError(t, err)
require.NoError(t, client.err)
serverState, ok := server.state.(*dtlsstate.State13)
require.True(t, ok)
require.Equal(t, expectedGroups, serverState.RemoteGroups, "groups in supported_groups mismatch")
}