| 1 |
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package sctp |
| 5 |
|
| 6 |
import ( |
| 7 |
"testing" |
| 8 |
|
| 9 |
"github.com/stretchr/testify/assert" |
| 10 |
) |
| 11 |
|
| 12 |
func TestChunkReconfig_Success(t *testing.T) { |
| 13 |
tt := []struct { |
| 14 |
binary []byte |
| 15 |
}{ |
| 16 |
{ |
| 17 |
// Note: chunk trailing padding is added in packet.marshal |
| 18 |
append( |
| 19 |
[]byte{0x82, 0x0, 0x0, 0x1a}, testChunkReconfigParamA()..., |
| 20 |
), |
| 21 |
}, |
| 22 |
{append([]byte{0x82, 0x0, 0x0, 0x14}, testChunkReconfigParamB()...)}, |
| 23 |
{append([]byte{0x82, 0x0, 0x0, 0x10}, testChunkReconfigResponce()...)}, |
| 24 |
{ |
| 25 |
append( |
| 26 |
append([]byte{0x82, 0x0, 0x0, 0x2c}, padByte(testChunkReconfigParamA(), 2)...), |
| 27 |
testChunkReconfigParamB()...), |
| 28 |
}, |
| 29 |
{ |
| 30 |
// Note: chunk trailing padding is added in packet.marshal |
| 31 |
append( |
| 32 |
append([]byte{0x82, 0x0, 0x0, 0x2a}, |
| 33 |
testChunkReconfigParamB()...), |
| 34 |
testChunkReconfigParamA()..., |
| 35 |
), |
| 36 |
}, |
| 37 |
} |
| 38 |
|
| 39 |
for i, tc := range tt { |
| 40 |
actual := &chunkReconfig{} |
| 41 |
err := actual.unmarshal(tc.binary) |
| 42 |
assert.NoErrorf(t, err, "failed to unmarshal #%d: %v", i) |
| 43 |
|
| 44 |
b, err := actual.marshal() |
| 45 |
assert.NoError(t, err) |
| 46 |
assert.Equalf(t, tc.binary, b, "test %d not equal", i) |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
func TestChunkReconfigUnmarshal_Failure(t *testing.T) { |
| 51 |
tt := []struct { |
| 52 |
name string |
| 53 |
binary []byte |
| 54 |
}{ |
| 55 |
{"chunk header to short", []byte{0x82}}, |
| 56 |
{"missing parse param type (A)", []byte{0x82, 0x0, 0x0, 0x4}}, |
| 57 |
{"wrong param (A)", []byte{0x82, 0x0, 0x0, 0x8, 0x0, 0xd, 0x0, 0x0}}, |
| 58 |
{ |
| 59 |
"wrong param (B)", |
| 60 |
append(append([]byte{0x82, 0x0, 0x0, 0x18}, |
| 61 |
testChunkReconfigParamB()...), |
| 62 |
[]byte{0x0, 0xd, 0x0, 0x0}...), |
| 63 |
}, |
| 64 |
} |
| 65 |
|
| 66 |
for i, tc := range tt { |
| 67 |
actual := &chunkReconfig{} |
| 68 |
err := actual.unmarshal(tc.binary) |
| 69 |
assert.Errorf(t, err, "expected unmarshal #%d: '%s' to fail.", i, tc.name) |
| 70 |
} |
| 71 |
} |