diff --git a/pkg/base/request_test.go b/pkg/base/request_test.go index 87dd8e34..8a66176d 100644 --- a/pkg/base/request_test.go +++ b/pkg/base/request_test.go @@ -246,7 +246,7 @@ func TestRequestWriteErrors(t *testing.T) { }, { "body", - 62, + 80, }, } { t.Run(ca.name, func(t *testing.T) { diff --git a/pkg/base/response_test.go b/pkg/base/response_test.go index 4e31b6be..0fc0bb60 100644 --- a/pkg/base/response_test.go +++ b/pkg/base/response_test.go @@ -203,7 +203,7 @@ func TestResponseWriteErrors(t *testing.T) { }, { "body", - 30, + 49, }, } { t.Run(ca.name, func(t *testing.T) { diff --git a/pkg/headers/authenticate.go b/pkg/headers/authenticate.go index 76f882b9..0fe9f124 100644 --- a/pkg/headers/authenticate.go +++ b/pkg/headers/authenticate.go @@ -110,9 +110,6 @@ func (h *Authenticate) Read(v base.HeaderValue) error { case "algorithm": h.Algorithm = &v - - default: - // ignore non-standard keys } } diff --git a/pkg/headers/authenticate_test.go b/pkg/headers/authenticate_test.go index bd3469c7..d1e847e0 100644 --- a/pkg/headers/authenticate_test.go +++ b/pkg/headers/authenticate_test.go @@ -213,6 +213,11 @@ func TestAutenticatehReadError(t *testing.T) { base.HeaderValue{"Basic"}, "unable to split between method and keys (Basic)", }, + { + "invalid keys", + base.HeaderValue{`Basic key1="k`}, + "apexes not closed (key1=\"k)", + }, { "invalid method", base.HeaderValue{"Testing key1=val1"}, diff --git a/pkg/headers/authorization.go b/pkg/headers/authorization.go index 73dd79c4..fd602a62 100644 --- a/pkg/headers/authorization.go +++ b/pkg/headers/authorization.go @@ -79,9 +79,7 @@ func (h Authorization) Write() base.HeaderValue { return base.HeaderValue{"Basic " + response} - case AuthDigest: + default: // AuthDigest return h.DigestValues.Write() } - - return nil } diff --git a/pkg/headers/authorization_test.go b/pkg/headers/authorization_test.go index 1aa37c62..3120b905 100644 --- a/pkg/headers/authorization_test.go +++ b/pkg/headers/authorization_test.go @@ -102,8 +102,8 @@ func TestAuthorizationReadError(t *testing.T) { }, { "digest invalid", - base.HeaderValue{`Basic`}, - "invalid authorization header", + base.HeaderValue{`Digest test="v`}, + "apexes not closed (test=\"v)", }, } { t.Run(ca.name, func(t *testing.T) { diff --git a/pkg/headers/transport_test.go b/pkg/headers/transport_test.go index f213766d..6b24e0f7 100644 --- a/pkg/headers/transport_test.go +++ b/pkg/headers/transport_test.go @@ -170,6 +170,11 @@ func TestTransportReadError(t *testing.T) { base.HeaderValue{"a", "b"}, "value provided multiple times ([a b])", }, + { + "invalid keys", + base.HeaderValue{`key1="k`}, + "apexes not closed (key1=\"k)", + }, { "protocol not found", base.HeaderValue{`invalid;unicast;client_port=14186-14187`}, diff --git a/pkg/ringbuffer/ringbuffer.go b/pkg/ringbuffer/ringbuffer.go index 999c6e39..e2c63edd 100644 --- a/pkg/ringbuffer/ringbuffer.go +++ b/pkg/ringbuffer/ringbuffer.go @@ -33,7 +33,7 @@ func (r *RingBuffer) Close() { r.event.signal() } -// Reset restores Pull(). +// Reset restores Pull() after a Close(). func (r *RingBuffer) Reset() { for i := uint64(0); i < r.bufferSize; i++ { atomic.SwapPointer(&r.buffer[i], nil) diff --git a/pkg/ringbuffer/ringbuffer_test.go b/pkg/ringbuffer/ringbuffer_test.go index 9736a02d..6f02dbc4 100644 --- a/pkg/ringbuffer/ringbuffer_test.go +++ b/pkg/ringbuffer/ringbuffer_test.go @@ -58,6 +58,13 @@ func TestClose(t *testing.T) { r.Close() <-done + + r.Reset() + + r.Push([]byte{0x05, 0x06, 0x07, 0x08}) + + _, ok := r.Pull() + require.Equal(t, true, ok) } func BenchmarkPushPullContinuous(b *testing.B) { diff --git a/pkg/rtpaac/mpeg4audioconfig.go b/pkg/rtpaac/mpeg4audioconfig.go index 30bf1247..dd4c2686 100644 --- a/pkg/rtpaac/mpeg4audioconfig.go +++ b/pkg/rtpaac/mpeg4audioconfig.go @@ -84,11 +84,11 @@ func (c *MPEG4AudioConfig) Decode(byts []byte) error { c.SampleRate = sampleRates[sampleRateIndex] case sampleRateIndex == 15: - sampleRateIndex, err := r.ReadBits(24) + tmp, err := r.ReadBits(24) if err != nil { return err } - c.SampleRate = int(sampleRateIndex) + c.SampleRate = int(tmp) default: return fmt.Errorf("invalid sample rate index (%d)", sampleRateIndex) diff --git a/pkg/rtpaac/mpeg4audioconfig_test.go b/pkg/rtpaac/mpeg4audioconfig_test.go index 0cc6b295..19382089 100644 --- a/pkg/rtpaac/mpeg4audioconfig_test.go +++ b/pkg/rtpaac/mpeg4audioconfig_test.go @@ -12,36 +12,36 @@ var configCases = []struct { dec MPEG4AudioConfig }{ { - name: "aac-lc 44.1khz mono", - enc: []byte{0x12, 0x08, 0x56, 0xe5, 0x00}, - dec: MPEG4AudioConfig{ + "aac-lc 44.1khz mono", + []byte{0x12, 0x08, 0x56, 0xe5, 0x00}, + MPEG4AudioConfig{ Type: MPEG4AudioTypeAACLC, SampleRate: 44100, ChannelCount: 1, }, }, { - name: "aac-lc 48khz stereo", - enc: []byte{17, 144}, - dec: MPEG4AudioConfig{ + "aac-lc 48khz stereo", + []byte{17, 144}, + MPEG4AudioConfig{ Type: MPEG4AudioTypeAACLC, SampleRate: 48000, ChannelCount: 2, }, }, { - name: "aac-lc 96khz stereo", - enc: []byte{0x10, 0x10, 0x56, 0xE5, 0x00}, - dec: MPEG4AudioConfig{ + "aac-lc 96khz stereo", + []byte{0x10, 0x10, 0x56, 0xE5, 0x00}, + MPEG4AudioConfig{ Type: MPEG4AudioTypeAACLC, SampleRate: 96000, ChannelCount: 2, }, }, { - name: "aac-lc 44.1khz 5.1", - enc: []byte{0x12, 0x30}, - dec: MPEG4AudioConfig{ + "aac-lc 44.1khz 5.1", + []byte{0x12, 0x30}, + MPEG4AudioConfig{ Type: MPEG4AudioTypeAACLC, SampleRate: 44100, ChannelCount: 6, @@ -59,3 +59,43 @@ func TestConfigDecode(t *testing.T) { }) } } + +func TestConfigDecodeErrors(t *testing.T) { + for _, ca := range []struct { + name string + byts []byte + err string + }{ + { + "empty", + []byte{}, + "EOF", + }, + { + "extended type missing", + []byte{31 << 3}, + "EOF", + }, + { + "extended type invalid", + []byte{31 << 3, 20}, + "unsupported type: 32", + }, + { + "sample rate missing", + []byte{0x12}, + "EOF", + }, + { + "sample rate invalid", + []byte{0x12 | 13>>5, 13 << 3}, + "invalid channel configuration: 13", + }, + } { + t.Run(ca.name, func(t *testing.T) { + var dec MPEG4AudioConfig + err := dec.Decode(ca.byts) + require.Equal(t, ca.err, err.Error()) + }) + } +}