File: path_test.go

package info (click to toggle)
golang-golang-x-net 1%3A0.27.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 8,636 kB
  • sloc: asm: 18; makefile: 12; sh: 7
file content (66 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (3)
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
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.21

package quic

import (
	"testing"
)

func TestPathChallengeReceived(t *testing.T) {
	for _, test := range []struct {
		name        string
		padTo       int
		wantPadding int
	}{{
		name:        "unexpanded",
		padTo:       0,
		wantPadding: 0,
	}, {
		name:        "expanded",
		padTo:       1200,
		wantPadding: 1200,
	}} {
		// "The recipient of [a PATH_CHALLENGE] frame MUST generate
		// a PATH_RESPONSE frame [...] containing the same Data value."
		// https://www.rfc-editor.org/rfc/rfc9000.html#section-19.17-7
		tc := newTestConn(t, clientSide)
		tc.handshake()
		tc.ignoreFrame(frameTypeAck)
		data := pathChallengeData{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}
		tc.writeFrames(packetType1RTT, debugFramePathChallenge{
			data: data,
		}, debugFramePadding{
			to: test.padTo,
		})
		tc.wantFrame("response to PATH_CHALLENGE",
			packetType1RTT, debugFramePathResponse{
				data: data,
			})
		if got, want := tc.lastDatagram.paddedSize, test.wantPadding; got != want {
			t.Errorf("PATH_RESPONSE expanded to %v bytes, want %v", got, want)
		}
		tc.wantIdle("connection is idle")
	}
}

func TestPathResponseMismatchReceived(t *testing.T) {
	// "If the content of a PATH_RESPONSE frame does not match the content of
	// a PATH_CHALLENGE frame previously sent by the endpoint,
	// the endpoint MAY generate a connection error of type PROTOCOL_VIOLATION."
	// https://www.rfc-editor.org/rfc/rfc9000.html#section-19.18-4
	tc := newTestConn(t, clientSide)
	tc.handshake()
	tc.ignoreFrame(frameTypeAck)
	tc.writeFrames(packetType1RTT, debugFramePathResponse{
		data: pathChallengeData{},
	})
	tc.wantFrame("invalid PATH_RESPONSE causes the connection to close",
		packetType1RTT, debugFrameConnectionCloseTransport{
			code: errProtocolViolation,
		},
	)
}