1 Star 0 Fork 0

上海老李/turn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
lt_cred_test.go 1.84 KB
一键复制 编辑 原始数据 按行查看 历史
Sean DuBois 提交于 2023-06-27 16:08 . Partial revert of 79fbb4e3
// 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())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/nwaycn/turn.git
git@gitee.com:nwaycn/turn.git
nwaycn
turn
turn
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385