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
|
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package extension
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtensionUseSRTP(t *testing.T) {
t.Run("No MasterKeyIdentifier", func(t *testing.T) {
rawUseSRTP := []byte{0x00, 0x0e, 0x00, 0x05, 0x00, 0x02, 0x00, 0x01, 0x00}
parsedUseSRTP := &UseSRTP{
ProtectionProfiles: []SRTPProtectionProfile{SRTP_AES128_CM_HMAC_SHA1_80},
MasterKeyIdentifier: []byte{},
}
marshaled, err := parsedUseSRTP.Marshal()
assert.NoError(t, err)
assert.Equal(t, rawUseSRTP, marshaled)
unmarshaled := &UseSRTP{}
assert.NoError(t, unmarshaled.Unmarshal(rawUseSRTP))
assert.Equal(t, parsedUseSRTP, unmarshaled)
})
t.Run("With MasterKeyIdentifier", func(t *testing.T) {
rawUseSRTP := []byte{0x00, 0x0e, 0x00, 0x0a, 0x00, 0x02, 0x00, 0x01, 0x05, 0xA, 0xB, 0xC, 0xD, 0xE}
parsedUseSRTP := &UseSRTP{
ProtectionProfiles: []SRTPProtectionProfile{SRTP_AES128_CM_HMAC_SHA1_80},
MasterKeyIdentifier: []byte{0xA, 0xB, 0xC, 0xD, 0xE},
}
marshaled, err := parsedUseSRTP.Marshal()
assert.NoError(t, err)
assert.Equal(t, rawUseSRTP, marshaled)
unmarshaled := &UseSRTP{}
assert.NoError(t, unmarshaled.Unmarshal(rawUseSRTP))
assert.Equal(t, parsedUseSRTP, unmarshaled)
})
t.Run("Invalid Lengths", func(t *testing.T) {
unmarshaled := &UseSRTP{}
err := unmarshaled.Unmarshal([]byte{0x00, 0x0e, 0x00, 0x05, 0x00, 0x04, 0x00, 0x01, 0x00})
assert.ErrorIs(t, err, errLengthMismatch)
err = unmarshaled.Unmarshal([]byte{0x00, 0x0e, 0x00, 0x0a, 0x00, 0x02, 0x00, 0x01, 0x01})
assert.ErrorIs(t, err, errLengthMismatch)
_, err = (&UseSRTP{
ProtectionProfiles: []SRTPProtectionProfile{SRTP_AES128_CM_HMAC_SHA1_80},
MasterKeyIdentifier: make([]byte, 500),
}).Marshal()
assert.ErrorIs(t, err, errMasterKeyIdentifierTooLarge)
})
}
|