snapshot of https://github.com/pion/webrtc.git (main, 2026-09-15; blobs > 131072B omitted)
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
Some checks failed
REUSE Compliance Check / lint (push) Failing after 0s
Browser E2E / Test (push) Failing after 3s
Test / test (1.24) (push) Failing after 0s
Test / test-i386 (1.25) (push) Failing after 0s
Test / test-i386 (1.24) (push) Failing after 0s
Test / test-windows (1.25) (push) Failing after 0s
Test / test-windows (1.24) (push) Failing after 0s
Test / test (1.25) (push) Failing after 0s
Examples Tests / Test (push) Failing after 3s
Test / test-macos (1.25) (push) Failing after 0s
Test / test-macos (1.24) (push) Failing after 0s
Go mod tidy / tidy (push) Failing after 0s
Test / test-wasm (push) Failing after 0s
CodeQL / analyze (push) Failing after 1s
Fuzz / fuzz (push) Failing after 0s
This commit is contained in:
126
iceserver_test.go
Normal file
126
iceserver_test.go
Normal file
@@ -0,0 +1,126 @@
|
||||
// SPDX-FileCopyrightText: 2026 The Pion community <https://pion.ly>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
//go:build !js
|
||||
|
||||
package webrtc
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"github.com/pion/stun/v4"
|
||||
"github.com/pion/webrtc/v4/pkg/rtcerr"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestICEServer_validate(t *testing.T) {
|
||||
t.Run("Success", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
iceServer ICEServer
|
||||
expectedValidate bool
|
||||
}{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: "placeholder",
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, true},
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:[2001:db8:1234:5678::1]?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: "placeholder",
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, true},
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: OAuthCredential{ //nolint:gosec // not hardcoded credentials.
|
||||
MACKey: "WmtzanB3ZW9peFhtdm42NzUzNG0=",
|
||||
AccessToken: "AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA==",
|
||||
},
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, true},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
var iceServer ICEServer
|
||||
jsonobj, err := json.Marshal(testCase.iceServer)
|
||||
assert.NoError(t, err)
|
||||
err = json.Unmarshal(jsonobj, &iceServer)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, iceServer, testCase.iceServer)
|
||||
_, err = testCase.iceServer.urls()
|
||||
assert.Nil(t, err, "testCase: %d %v", i, testCase)
|
||||
}
|
||||
})
|
||||
t.Run("Failure", func(t *testing.T) {
|
||||
testCases := []struct {
|
||||
iceServer ICEServer
|
||||
expectedErr error
|
||||
}{
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrNoTurnCredentials}},
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
|
||||
{ICEServer{
|
||||
URLs: []string{"turn:192.158.29.39?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: ICECredentialTypePassword,
|
||||
}, &rtcerr.InvalidAccessError{Err: ErrTurnCredentials}},
|
||||
{ICEServer{
|
||||
URLs: []string{"stun:google.de?transport=udp"},
|
||||
Username: "unittest",
|
||||
Credential: false,
|
||||
CredentialType: ICECredentialTypeOauth,
|
||||
}, &rtcerr.InvalidAccessError{Err: stun.ErrSTUNQuery}},
|
||||
}
|
||||
|
||||
for i, testCase := range testCases {
|
||||
_, err := testCase.iceServer.urls()
|
||||
assert.EqualError(t,
|
||||
err,
|
||||
testCase.expectedErr.Error(),
|
||||
"testCase: %d %v", i, testCase,
|
||||
)
|
||||
}
|
||||
})
|
||||
t.Run("JsonFailure", func(t *testing.T) {
|
||||
//nolint:lll
|
||||
testCases := [][]byte{
|
||||
[]byte(`{"urls":"NOTAURL","username":"unittest","credential":"placeholder","credentialType":"password"}`),
|
||||
[]byte(`{"urls":["turn:[2001:db8:1234:5678::1]?transport=udp"],"username":"unittest","credential":"placeholder","credentialType":"invalid"}`),
|
||||
[]byte(`{"urls":["turn:[2001:db8:1234:5678::1]?transport=udp"],"username":6,"credential":"placeholder","credentialType":"password"}`),
|
||||
[]byte(`{"urls":["turn:192.158.29.39?transport=udp"],"username":"unittest","credential":{"Bad Object": true},"credentialType":"oauth"}`),
|
||||
[]byte(`{"urls":["turn:192.158.29.39?transport=udp"],"username":"unittest","credential":{"MACKey":"WmtzanB3ZW9peFhtdm42NzUzNG0=","AccessToken":null,"credentialType":"oauth"}`),
|
||||
[]byte(`{"urls":["turn:192.158.29.39?transport=udp"],"username":"unittest","credential":{"MACKey":"WmtzanB3ZW9peFhtdm42NzUzNG0=","AccessToken":null,"credentialType":"password"}`),
|
||||
[]byte(`{"urls":["turn:192.158.29.39?transport=udp"],"username":"unittest","credential":{"MACKey":1337,"AccessToken":"AAwg3kPHWPfvk9bDFL936wYvkoctMADzQ5VhNDgeMR3+ZlZ35byg972fW8QjpEl7bx91YLBPFsIhsxloWcXPhA=="},"credentialType":"oauth"}`),
|
||||
}
|
||||
for i, testCase := range testCases {
|
||||
var tc ICEServer
|
||||
err := json.Unmarshal(testCase, &tc)
|
||||
assert.Error(t, err, "testCase: %d %v", i, string(testCase))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestICEServerZeroValue(t *testing.T) {
|
||||
server := ICEServer{
|
||||
URLs: []string{"turn:galene.org:1195"},
|
||||
Username: "galene",
|
||||
Credential: "secret",
|
||||
}
|
||||
assert.Equal(t, server.CredentialType, ICECredentialTypePassword)
|
||||
}
|
||||
Reference in New Issue
Block a user