-
Notifications
You must be signed in to change notification settings - Fork 66
Mark all existing options as non-updateable #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| // SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly> | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package srtp | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/pion/transport/v4/replaydetector" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // testReplayDetector is a minimal ReplayDetector used in factory option tests. | ||
| type testReplayDetector struct{} | ||
|
|
||
| func (d *testReplayDetector) Check(uint64) (func() bool, bool) { | ||
| return func() bool { return true }, true | ||
| } | ||
|
|
||
| // constructedContext returns a fully constructed Context. | ||
| func constructedContext(t *testing.T) *Context { | ||
| t.Helper() | ||
|
|
||
| c, err := CreateContext(make([]byte, 16), make([]byte, 14), ProtectionProfileAes128CmHmacSha1_80) | ||
| require.NoError(t, err) | ||
|
|
||
| return c | ||
| } | ||
|
|
||
| func TestContextOptions(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| option func() ContextOption | ||
| validate func(t *testing.T, c *Context) | ||
| }{ | ||
| { | ||
| name: "SRTPReplayProtection", | ||
| option: func() ContextOption { return SRTPReplayProtection(128) }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.NotNil(t, c.newSRTPReplayDetector) | ||
| assert.NotNil(t, c.newSRTPReplayDetector()) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTCPReplayProtection", | ||
| option: func() ContextOption { return SRTCPReplayProtection(128) }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.NotNil(t, c.newSRTCPReplayDetector) | ||
| assert.NotNil(t, c.newSRTCPReplayDetector()) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTPNoReplayProtection", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTPNoReplayProtection()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| require.NotNil(t, c.newSRTPReplayDetector) | ||
| _, ok := c.newSRTPReplayDetector().(*nopReplayDetector) | ||
| assert.True(t, ok) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTCPNoReplayProtection", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTCPNoReplayProtection()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| require.NotNil(t, c.newSRTCPReplayDetector) | ||
| _, ok := c.newSRTCPReplayDetector().(*nopReplayDetector) | ||
| assert.True(t, ok) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTPReplayDetectorFactory", | ||
| option: func() ContextOption { | ||
| return SRTPReplayDetectorFactory(func() replaydetector.ReplayDetector { return &testReplayDetector{} }) | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| require.NotNil(t, c.newSRTPReplayDetector) | ||
| _, ok := c.newSRTPReplayDetector().(*testReplayDetector) | ||
| assert.True(t, ok) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTCPReplayDetectorFactory", | ||
| option: func() ContextOption { | ||
| return SRTCPReplayDetectorFactory(func() replaydetector.ReplayDetector { return &testReplayDetector{} }) | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| require.NotNil(t, c.newSRTCPReplayDetector) | ||
| _, ok := c.newSRTCPReplayDetector().(*testReplayDetector) | ||
| assert.True(t, ok) | ||
| }, | ||
| }, | ||
| { | ||
| name: "MasterKeyIndicator", | ||
| option: func() ContextOption { return MasterKeyIndicator([]byte{0x01, 0x02, 0x03, 0x04}) }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, c.sendMKI) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTPEncryption", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTPEncryption()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.True(t, c.encryptSRTP) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTPNoEncryption", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTPNoEncryption()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.False(t, c.encryptSRTP) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTCPEncryption", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTCPEncryption()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.True(t, c.encryptSRTCP) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTCPNoEncryption", | ||
| option: func() ContextOption { | ||
| return func(c *Context) error { return SRTCPNoEncryption()(c) } | ||
| }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.False(t, c.encryptSRTCP) | ||
| }, | ||
| }, | ||
| { | ||
| name: "RolloverCounterCarryingTransform", | ||
| option: func() ContextOption { return RolloverCounterCarryingTransform(RCCMode2, 10) }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| assert.Equal(t, RCCMode2, c.rccMode) | ||
| assert.Equal(t, uint16(10), c.rocTransmitRate) | ||
| }, | ||
| }, | ||
| { | ||
| name: "SRTPAuthenticationTagLength", | ||
| option: func() ContextOption { return SRTPAuthenticationTagLength(8) }, | ||
| validate: func(t *testing.T, c *Context) { | ||
| t.Helper() | ||
| require.NotNil(t, c.authTagRTPLen) | ||
| assert.Equal(t, 8, *c.authTagRTPLen) | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Run("sets value", func(t *testing.T) { | ||
| c := &Context{} | ||
| require.NoError(t, tt.option()(c)) | ||
| tt.validate(t, c) | ||
| }) | ||
|
|
||
| t.Run("constructed error", func(t *testing.T) { | ||
| ctx := constructedContext(t) | ||
| err := tt.option()(ctx) | ||
| assert.ErrorIs(t, err, ErrContextOptionNotUpdatable) | ||
| }) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.