代码拉取完成,页面将自动刷新
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
//go:build !js
// +build !js
package turn
import (
"net"
"testing"
"time"
"github.com/pion/logging"
"github.com/stretchr/testify/assert"
)
func TestLtCredMech(t *testing.T) {
username := "1599491771"
sharedSecret := "foobar"
expectedPassword := "Tpz/nKkyvX/vMSLKvL4sbtBt8Vs=" //nolint:gosec
actualPassword, _ := longTermCredentials(username, sharedSecret)
if expectedPassword != actualPassword {
t.Errorf("Expected %q, got %q", expectedPassword, actualPassword)
}
}
func TestNewLongTermAuthHandler(t *testing.T) {
const sharedSecret = "HELLO_WORLD"
serverListener, err := net.ListenPacket("udp4", "0.0.0.0:3478")
assert.NoError(t, err)
server, err := NewServer(ServerConfig{
AuthHandler: NewLongTermAuthHandler(sharedSecret, nil),
PacketConnConfigs: []PacketConnConfig{
{
PacketConn: serverListener,
RelayAddressGenerator: &RelayAddressGeneratorStatic{
RelayAddress: net.ParseIP("127.0.0.1"),
Address: "0.0.0.0",
},
},
},
Realm: "pion.ly",
LoggerFactory: logging.NewDefaultLoggerFactory(),
})
assert.NoError(t, err)
conn, err := net.ListenPacket("udp4", "0.0.0.0:0")
assert.NoError(t, err)
username, password, err := GenerateLongTermCredentials(sharedSecret, time.Minute)
assert.NoError(t, err)
addr := "127.0.0.1:3478"
client, err := NewClient(&ClientConfig{
STUNServerAddr: addr,
TURNServerAddr: addr,
Conn: conn,
Username: username,
Password: password,
LoggerFactory: logging.NewDefaultLoggerFactory(),
})
assert.NoError(t, err)
assert.NoError(t, client.Listen())
relayConn, err := client.Allocate()
assert.NoError(t, err)
client.Close()
assert.NoError(t, relayConn.Close())
assert.NoError(t, conn.Close())
assert.NoError(t, server.Close())
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。