golang.org/x/net@v0.25.1-0.20240516223405-c87a5b62e243/quic/path_test.go (about) 1 // Copyright 2023 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build go1.21 6 7 package quic 8 9 import ( 10 "testing" 11 ) 12 13 func TestPathChallengeReceived(t *testing.T) { 14 for _, test := range []struct { 15 name string 16 padTo int 17 wantPadding int 18 }{{ 19 name: "unexpanded", 20 padTo: 0, 21 wantPadding: 0, 22 }, { 23 name: "expanded", 24 padTo: 1200, 25 wantPadding: 1200, 26 }} { 27 // "The recipient of [a PATH_CHALLENGE] frame MUST generate 28 // a PATH_RESPONSE frame [...] containing the same Data value." 29 // https://www.rfc-editor.org/rfc/rfc9000.html#section-19.17-7 30 tc := newTestConn(t, clientSide) 31 tc.handshake() 32 tc.ignoreFrame(frameTypeAck) 33 data := pathChallengeData{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef} 34 tc.writeFrames(packetType1RTT, debugFramePathChallenge{ 35 data: data, 36 }, debugFramePadding{ 37 to: test.padTo, 38 }) 39 tc.wantFrame("response to PATH_CHALLENGE", 40 packetType1RTT, debugFramePathResponse{ 41 data: data, 42 }) 43 if got, want := tc.lastDatagram.paddedSize, test.wantPadding; got != want { 44 t.Errorf("PATH_RESPONSE expanded to %v bytes, want %v", got, want) 45 } 46 tc.wantIdle("connection is idle") 47 } 48 } 49 50 func TestPathResponseMismatchReceived(t *testing.T) { 51 // "If the content of a PATH_RESPONSE frame does not match the content of 52 // a PATH_CHALLENGE frame previously sent by the endpoint, 53 // the endpoint MAY generate a connection error of type PROTOCOL_VIOLATION." 54 // https://www.rfc-editor.org/rfc/rfc9000.html#section-19.18-4 55 tc := newTestConn(t, clientSide) 56 tc.handshake() 57 tc.ignoreFrame(frameTypeAck) 58 tc.writeFrames(packetType1RTT, debugFramePathResponse{ 59 data: pathChallengeData{}, 60 }) 61 tc.wantFrame("invalid PATH_RESPONSE causes the connection to close", 62 packetType1RTT, debugFrameConnectionCloseTransport{ 63 code: errProtocolViolation, 64 }, 65 ) 66 }