mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2026-03-14 14:35:44 +01:00
Merge pull request #1145 from strukturag/linter-updates
Enable more linters
This commit is contained in:
commit
4243276698
87 changed files with 757 additions and 434 deletions
|
|
@ -1,9 +1,30 @@
|
|||
version: "2"
|
||||
linters:
|
||||
enable:
|
||||
- errchkjson
|
||||
- exptostd
|
||||
- gocritic
|
||||
- misspell
|
||||
- modernize
|
||||
- paralleltest
|
||||
- perfsprint
|
||||
- revive
|
||||
- testifylint
|
||||
settings:
|
||||
errchkjson:
|
||||
check-error-free-encoding: true
|
||||
report-no-exported: true
|
||||
gocritic:
|
||||
disabled-checks:
|
||||
- singleCaseSwitch
|
||||
settings:
|
||||
ifElseChain:
|
||||
# Min number of if-else blocks that makes the warning trigger.
|
||||
# Default: 2
|
||||
minThreshold: 3
|
||||
govet:
|
||||
enable:
|
||||
- nilness
|
||||
disable:
|
||||
- stdversion
|
||||
revive:
|
||||
|
|
@ -34,6 +55,9 @@ linters:
|
|||
- name: unreachable-code
|
||||
- name: use-any
|
||||
- name: redefines-builtin-id
|
||||
testifylint:
|
||||
disable:
|
||||
- require-error
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestAllowedIps(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
a, err := ParseAllowedIps("127.0.0.1, 192.168.0.1, 192.168.1.1/24")
|
||||
require.NoError(err)
|
||||
|
|
@ -49,6 +50,7 @@ func TestAllowedIps(t *testing.T) {
|
|||
|
||||
for _, addr := range allowed {
|
||||
t.Run(addr, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
if ip := net.ParseIP(addr); assert.NotNil(ip, "error parsing %s", addr) {
|
||||
assert.True(a.Allowed(ip), "should allow %s", addr)
|
||||
|
|
@ -58,6 +60,7 @@ func TestAllowedIps(t *testing.T) {
|
|||
|
||||
for _, addr := range notAllowed {
|
||||
t.Run(addr, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
if ip := net.ParseIP(addr); assert.NotNil(ip, "error parsing %s", addr) {
|
||||
assert.False(a.Allowed(ip), "should not allow %s", addr)
|
||||
|
|
|
|||
|
|
@ -50,13 +50,14 @@ func formatWithRemainder(value uint64, divisor uint64, format string) string {
|
|||
|
||||
// String returns the formatted bandwidth.
|
||||
func (b Bandwidth) String() string {
|
||||
if b >= Gigabit {
|
||||
switch {
|
||||
case b >= Gigabit:
|
||||
return formatWithRemainder(b.Bits(), Gigabit.Bits(), "Gbps")
|
||||
} else if b >= Megabit {
|
||||
case b >= Megabit:
|
||||
return formatWithRemainder(b.Bits(), Megabit.Bits(), "Mbps")
|
||||
} else if b >= Kilobit {
|
||||
case b >= Kilobit:
|
||||
return formatWithRemainder(b.Bits(), Kilobit.Bits(), "Kbps")
|
||||
} else {
|
||||
default:
|
||||
return fmt.Sprintf("%d bps", b)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,10 +68,10 @@ func GetStringMapString[T ~string](m StringMap, key string) (T, bool) {
|
|||
}
|
||||
|
||||
switch v := v.(type) {
|
||||
case T:
|
||||
return v, true
|
||||
case string:
|
||||
return T(v), true
|
||||
case T:
|
||||
return v, true
|
||||
default:
|
||||
return defaultValue, false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestConvertStringMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
d := map[string]any{
|
||||
"foo": "bar",
|
||||
|
|
@ -56,6 +57,7 @@ func TestConvertStringMap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetStringMapString(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
type StringMapTestString string
|
||||
|
|
@ -90,6 +92,7 @@ func TestGetStringMapString(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetStringMapStringMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
m := StringMap{
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"crypto/subtle"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
|
@ -461,7 +462,7 @@ type BackendInformationEtcd struct {
|
|||
|
||||
func (p *BackendInformationEtcd) CheckValid() (err error) {
|
||||
if p.Secret == "" {
|
||||
return fmt.Errorf("secret missing")
|
||||
return errors.New("secret missing")
|
||||
}
|
||||
|
||||
if len(p.Urls) > 0 {
|
||||
|
|
@ -504,7 +505,7 @@ func (p *BackendInformationEtcd) CheckValid() (err error) {
|
|||
p.Urls = append(p.Urls, p.Url)
|
||||
p.parsedUrls = append(p.parsedUrls, parsedUrl)
|
||||
} else {
|
||||
return fmt.Errorf("urls missing")
|
||||
return errors.New("urls missing")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
package signaling
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// Information on a GRPC target in the etcd cluster.
|
||||
|
|
@ -33,7 +33,7 @@ type GrpcTargetInformationEtcd struct {
|
|||
|
||||
func (p *GrpcTargetInformationEtcd) CheckValid() error {
|
||||
if l := len(p.Address); l == 0 {
|
||||
return fmt.Errorf("address missing")
|
||||
return errors.New("address missing")
|
||||
} else if p.Address[l-1] == '/' {
|
||||
p.Address = p.Address[:l-1]
|
||||
}
|
||||
|
|
|
|||
40
api_proxy.go
40
api_proxy.go
|
|
@ -23,6 +23,7 @@ package signaling
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
|
|
@ -62,10 +63,10 @@ func (m *ProxyClientMessage) String() string {
|
|||
func (m *ProxyClientMessage) CheckValid() error {
|
||||
switch m.Type {
|
||||
case "":
|
||||
return fmt.Errorf("type missing")
|
||||
return errors.New("type missing")
|
||||
case "hello":
|
||||
if m.Hello == nil {
|
||||
return fmt.Errorf("hello missing")
|
||||
return errors.New("hello missing")
|
||||
} else if err := m.Hello.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -78,13 +79,13 @@ func (m *ProxyClientMessage) CheckValid() error {
|
|||
}
|
||||
case "command":
|
||||
if m.Command == nil {
|
||||
return fmt.Errorf("command missing")
|
||||
return errors.New("command missing")
|
||||
} else if err := m.Command.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "payload":
|
||||
if m.Payload == nil {
|
||||
return fmt.Errorf("payload missing")
|
||||
return errors.New("payload missing")
|
||||
} else if err := m.Payload.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -166,7 +167,7 @@ func (m *HelloProxyClientMessage) CheckValid() error {
|
|||
}
|
||||
if m.ResumeId == "" {
|
||||
if m.Token == "" {
|
||||
return fmt.Errorf("token missing")
|
||||
return errors.New("token missing")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -232,21 +233,21 @@ type CommandProxyClientMessage struct {
|
|||
func (m *CommandProxyClientMessage) CheckValid() error {
|
||||
switch m.Type {
|
||||
case "":
|
||||
return fmt.Errorf("type missing")
|
||||
return errors.New("type missing")
|
||||
case "create-publisher":
|
||||
if m.StreamType == "" {
|
||||
return fmt.Errorf("stream type missing")
|
||||
return errors.New("stream type missing")
|
||||
}
|
||||
case "create-subscriber":
|
||||
if m.PublisherId == "" {
|
||||
return fmt.Errorf("publisher id missing")
|
||||
return errors.New("publisher id missing")
|
||||
}
|
||||
if m.StreamType == "" {
|
||||
return fmt.Errorf("stream type missing")
|
||||
return errors.New("stream type missing")
|
||||
}
|
||||
if m.RemoteUrl != "" {
|
||||
if m.RemoteToken == "" {
|
||||
return fmt.Errorf("remote token missing")
|
||||
return errors.New("remote token missing")
|
||||
}
|
||||
|
||||
remoteUrl, err := url.Parse(m.RemoteUrl)
|
||||
|
|
@ -259,7 +260,7 @@ func (m *CommandProxyClientMessage) CheckValid() error {
|
|||
fallthrough
|
||||
case "delete-subscriber":
|
||||
if m.ClientId == "" {
|
||||
return fmt.Errorf("client id missing")
|
||||
return errors.New("client id missing")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -287,14 +288,14 @@ type PayloadProxyClientMessage struct {
|
|||
func (m *PayloadProxyClientMessage) CheckValid() error {
|
||||
switch m.Type {
|
||||
case "":
|
||||
return fmt.Errorf("type missing")
|
||||
return errors.New("type missing")
|
||||
case "offer":
|
||||
fallthrough
|
||||
case "answer":
|
||||
fallthrough
|
||||
case "candidate":
|
||||
if len(m.Payload) == 0 {
|
||||
return fmt.Errorf("payload missing")
|
||||
return errors.New("payload missing")
|
||||
}
|
||||
case "endOfCandidates":
|
||||
fallthrough
|
||||
|
|
@ -302,7 +303,7 @@ func (m *PayloadProxyClientMessage) CheckValid() error {
|
|||
// No payload required.
|
||||
}
|
||||
if m.ClientId == "" {
|
||||
return fmt.Errorf("client id missing")
|
||||
return errors.New("client id missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -329,13 +330,14 @@ type EventProxyServerBandwidth struct {
|
|||
}
|
||||
|
||||
func (b *EventProxyServerBandwidth) String() string {
|
||||
if b.Incoming != nil && b.Outgoing != nil {
|
||||
switch {
|
||||
case b.Incoming != nil && b.Outgoing != nil:
|
||||
return fmt.Sprintf("bandwidth: incoming=%.3f%%, outgoing=%.3f%%", *b.Incoming, *b.Outgoing)
|
||||
} else if b.Incoming != nil {
|
||||
case b.Incoming != nil:
|
||||
return fmt.Sprintf("bandwidth: incoming=%.3f%%, outgoing=unlimited", *b.Incoming)
|
||||
} else if b.Outgoing != nil {
|
||||
case b.Outgoing != nil:
|
||||
return fmt.Sprintf("bandwidth: incoming=unlimited, outgoing=%.3f%%", *b.Outgoing)
|
||||
} else {
|
||||
default:
|
||||
return "bandwidth: incoming=unlimited, outgoing=unlimited"
|
||||
}
|
||||
}
|
||||
|
|
@ -366,7 +368,7 @@ type ProxyInformationEtcd struct {
|
|||
|
||||
func (p *ProxyInformationEtcd) CheckValid() error {
|
||||
if p.Address == "" {
|
||||
return fmt.Errorf("address missing")
|
||||
return errors.New("address missing")
|
||||
}
|
||||
if p.Address[len(p.Address)-1] != '/' {
|
||||
p.Address += "/"
|
||||
|
|
|
|||
|
|
@ -105,10 +105,10 @@ type ClientMessage struct {
|
|||
func (m *ClientMessage) CheckValid() error {
|
||||
switch m.Type {
|
||||
case "":
|
||||
return fmt.Errorf("type missing")
|
||||
return errors.New("type missing")
|
||||
case "hello":
|
||||
if m.Hello == nil {
|
||||
return fmt.Errorf("hello missing")
|
||||
return errors.New("hello missing")
|
||||
} else if err := m.Hello.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -116,31 +116,31 @@ func (m *ClientMessage) CheckValid() error {
|
|||
// No additional check required.
|
||||
case "room":
|
||||
if m.Room == nil {
|
||||
return fmt.Errorf("room missing")
|
||||
return errors.New("room missing")
|
||||
} else if err := m.Room.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "message":
|
||||
if m.Message == nil {
|
||||
return fmt.Errorf("message missing")
|
||||
return errors.New("message missing")
|
||||
} else if err := m.Message.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "control":
|
||||
if m.Control == nil {
|
||||
return fmt.Errorf("control missing")
|
||||
return errors.New("control missing")
|
||||
} else if err := m.Control.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "internal":
|
||||
if m.Internal == nil {
|
||||
return fmt.Errorf("internal missing")
|
||||
return errors.New("internal missing")
|
||||
} else if err := m.Internal.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "transient":
|
||||
if m.TransientData == nil {
|
||||
return fmt.Errorf("transient missing")
|
||||
return errors.New("transient missing")
|
||||
} else if err := m.TransientData.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -362,7 +362,7 @@ type ClientTypeInternalAuthParams struct {
|
|||
|
||||
func (p *ClientTypeInternalAuthParams) CheckValid() error {
|
||||
if p.Backend == "" {
|
||||
return fmt.Errorf("backend missing")
|
||||
return errors.New("backend missing")
|
||||
}
|
||||
|
||||
if p.Backend[len(p.Backend)-1] != '/' {
|
||||
|
|
@ -387,7 +387,7 @@ type HelloV2AuthParams struct {
|
|||
|
||||
func (p *HelloV2AuthParams) CheckValid() error {
|
||||
if p.Token == "" {
|
||||
return fmt.Errorf("token missing")
|
||||
return errors.New("token missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -414,7 +414,7 @@ type FederationAuthParams struct {
|
|||
|
||||
func (p *FederationAuthParams) CheckValid() error {
|
||||
if p.Token == "" {
|
||||
return fmt.Errorf("token missing")
|
||||
return errors.New("token missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -463,7 +463,7 @@ func (m *HelloClientMessage) CheckValid() error {
|
|||
}
|
||||
if m.ResumeId == "" {
|
||||
if m.Auth == nil || len(m.Auth.Params) == 0 {
|
||||
return fmt.Errorf("params missing")
|
||||
return errors.New("params missing")
|
||||
}
|
||||
if m.Auth.Type == "" {
|
||||
m.Auth.Type = HelloClientTypeClient
|
||||
|
|
@ -473,7 +473,7 @@ func (m *HelloClientMessage) CheckValid() error {
|
|||
fallthrough
|
||||
case HelloClientTypeFederation:
|
||||
if m.Auth.Url == "" {
|
||||
return fmt.Errorf("url missing")
|
||||
return errors.New("url missing")
|
||||
}
|
||||
|
||||
if m.Auth.Url[len(m.Auth.Url)-1] != '/' {
|
||||
|
|
@ -520,7 +520,7 @@ func (m *HelloClientMessage) CheckValid() error {
|
|||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported auth type")
|
||||
return errors.New("unsupported auth type")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
@ -891,7 +891,7 @@ func FilterSDPCandidates(s *sdp.SessionDescription, allowed *AllowedIps, blocked
|
|||
|
||||
func (m *MessageClientMessage) CheckValid() error {
|
||||
if len(m.Data) == 0 {
|
||||
return fmt.Errorf("message empty")
|
||||
return errors.New("message empty")
|
||||
}
|
||||
switch m.Recipient.Type {
|
||||
case RecipientTypeRoom:
|
||||
|
|
@ -900,11 +900,11 @@ func (m *MessageClientMessage) CheckValid() error {
|
|||
// No additional checks required.
|
||||
case RecipientTypeSession:
|
||||
if m.Recipient.SessionId == "" {
|
||||
return fmt.Errorf("session id missing")
|
||||
return errors.New("session id missing")
|
||||
}
|
||||
case RecipientTypeUser:
|
||||
if m.Recipient.UserId == "" {
|
||||
return fmt.Errorf("user id missing")
|
||||
return errors.New("user id missing")
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unsupported recipient type %v", m.Recipient.Type)
|
||||
|
|
@ -957,10 +957,10 @@ type CommonSessionInternalClientMessage struct {
|
|||
|
||||
func (m *CommonSessionInternalClientMessage) CheckValid() error {
|
||||
if m.SessionId == "" {
|
||||
return fmt.Errorf("sessionid missing")
|
||||
return errors.New("sessionid missing")
|
||||
}
|
||||
if m.RoomId == "" {
|
||||
return fmt.Errorf("roomid missing")
|
||||
return errors.New("roomid missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -1080,31 +1080,31 @@ func (m *InternalClientMessage) CheckValid() error {
|
|||
return errors.New("type missing")
|
||||
case "addsession":
|
||||
if m.AddSession == nil {
|
||||
return fmt.Errorf("addsession missing")
|
||||
return errors.New("addsession missing")
|
||||
} else if err := m.AddSession.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "updatesession":
|
||||
if m.UpdateSession == nil {
|
||||
return fmt.Errorf("updatesession missing")
|
||||
return errors.New("updatesession missing")
|
||||
} else if err := m.UpdateSession.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "removesession":
|
||||
if m.RemoveSession == nil {
|
||||
return fmt.Errorf("removesession missing")
|
||||
return errors.New("removesession missing")
|
||||
} else if err := m.RemoveSession.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "incall":
|
||||
if m.InCall == nil {
|
||||
return fmt.Errorf("incall missing")
|
||||
return errors.New("incall missing")
|
||||
} else if err := m.InCall.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
case "dialout":
|
||||
if m.Dialout == nil {
|
||||
return fmt.Errorf("dialout missing")
|
||||
return errors.New("dialout missing")
|
||||
} else if err := m.Dialout.CheckValid(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1277,12 +1277,12 @@ func (m *TransientDataClientMessage) CheckValid() error {
|
|||
switch m.Type {
|
||||
case "set":
|
||||
if m.Key == "" {
|
||||
return fmt.Errorf("key missing")
|
||||
return errors.New("key missing")
|
||||
}
|
||||
// A "nil" value is allowed and will remove the key.
|
||||
case "remove":
|
||||
if m.Key == "" {
|
||||
return fmt.Errorf("key missing")
|
||||
return errors.New("key missing")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package signaling
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
|
@ -360,7 +360,7 @@ func TestErrorMessages(t *testing.T) {
|
|||
assert.Equal("error", err1.Type, "%+v", err1)
|
||||
assert.NotNil(err1.Error, "%+v", err1)
|
||||
|
||||
err2 := msg.NewWrappedErrorServerMessage(fmt.Errorf("test-error"))
|
||||
err2 := msg.NewWrappedErrorServerMessage(errors.New("test-error"))
|
||||
assert.Equal(id, err2.Id, "%+v", err2)
|
||||
assert.Equal("error", err2.Type, "%+v", err2)
|
||||
if assert.NotNil(err2.Error, "%+v", err2) {
|
||||
|
|
@ -524,7 +524,7 @@ func TestFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
|
||||
blocked, err := ParseAllowedIps("192.0.0.0/24, 192.168.0.0/16")
|
||||
|
|
@ -542,7 +542,7 @@ func TestFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -574,7 +574,7 @@ func TestNoFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedBefore[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
|
||||
blocked, err := ParseAllowedIps("192.0.0.0/24, 192.168.0.0/16")
|
||||
|
|
@ -592,7 +592,7 @@ func TestNoFilterSDPCandidates(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
assert.Equal(expectedAfter[m.MediaName.Media], count, "invalid number of candidates for media description %s", m.MediaName.Media)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,12 +74,13 @@ func TestPostOnRedirect(t *testing.T) {
|
|||
http.Redirect(w, r, "/ocs/v2.php/two", http.StatusTemporaryRedirect)
|
||||
})
|
||||
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
|
||||
assert := assert.New(t)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
var request map[string]string
|
||||
err = json.Unmarshal(body, &request)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
returnOCS(t, w, body)
|
||||
})
|
||||
|
|
@ -160,9 +161,10 @@ func TestPostOnRedirectStatusFound(t *testing.T) {
|
|||
})
|
||||
r.HandleFunc("/ocs/v2.php/two", func(w http.ResponseWriter, r *http.Request) {
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
if assert.NoError(err) {
|
||||
assert.Empty(string(body), "Should not have received any body, got %s", string(body))
|
||||
}
|
||||
|
||||
assert.Empty(string(body), "Should not have received any body, got %s", string(body))
|
||||
returnOCS(t, w, []byte("{}"))
|
||||
})
|
||||
server := httptest.NewServer(r)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
func testUrls(t *testing.T, config *BackendConfiguration, valid_urls []string, invalid_urls []string) {
|
||||
for _, u := range valid_urls {
|
||||
t.Run(u, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
parsed, err := url.ParseRequestURI(u)
|
||||
if !assert.NoError(err, "The url %s should be valid", u) {
|
||||
|
|
@ -49,6 +50,7 @@ func testUrls(t *testing.T, config *BackendConfiguration, valid_urls []string, i
|
|||
}
|
||||
for _, u := range invalid_urls {
|
||||
t.Run(u, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
parsed, _ := url.ParseRequestURI(u)
|
||||
assert.False(config.IsUrlAllowed(parsed), "The url %s should not be allowed", u)
|
||||
|
|
@ -59,6 +61,7 @@ func testUrls(t *testing.T, config *BackendConfiguration, valid_urls []string, i
|
|||
func testBackends(t *testing.T, config *BackendConfiguration, valid_urls [][]string, invalid_urls []string) {
|
||||
for _, entry := range valid_urls {
|
||||
t.Run(entry[0], func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
u := entry[0]
|
||||
parsed, err := url.ParseRequestURI(u)
|
||||
|
|
@ -73,6 +76,7 @@ func testBackends(t *testing.T, config *BackendConfiguration, valid_urls [][]str
|
|||
}
|
||||
for _, u := range invalid_urls {
|
||||
t.Run(u, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
parsed, _ := url.ParseRequestURI(u)
|
||||
assert.False(config.IsUrlAllowed(parsed), "The url %s should not be allowed", u)
|
||||
|
|
@ -81,6 +85,7 @@ func testBackends(t *testing.T, config *BackendConfiguration, valid_urls [][]str
|
|||
}
|
||||
|
||||
func TestIsUrlAllowed_Compat(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
// Old-style configuration
|
||||
valid_urls := []string{
|
||||
|
|
@ -102,6 +107,7 @@ func TestIsUrlAllowed_Compat(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsUrlAllowed_CompatForceHttps(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
// Old-style configuration, force HTTPS
|
||||
valid_urls := []string{
|
||||
|
|
@ -122,6 +128,7 @@ func TestIsUrlAllowed_CompatForceHttps(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsUrlAllowed(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
valid_urls := [][]string{
|
||||
{"https://domain.invalid/foo", string(testBackendSecret) + "-foo"},
|
||||
|
|
@ -166,6 +173,7 @@ func TestIsUrlAllowed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
valid_urls := []string{}
|
||||
invalid_urls := []string{
|
||||
|
|
@ -182,6 +190,7 @@ func TestIsUrlAllowed_EmptyAllowlist(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsUrlAllowed_AllowAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
valid_urls := []string{
|
||||
"http://domain.invalid",
|
||||
|
|
@ -206,6 +215,7 @@ type ParseBackendIdsTestcase struct {
|
|||
}
|
||||
|
||||
func TestParseBackendIds(t *testing.T) {
|
||||
t.Parallel()
|
||||
testcases := []ParseBackendIdsTestcase{
|
||||
{"", nil},
|
||||
{"backend1", []string{"backend1"}},
|
||||
|
|
@ -223,7 +233,7 @@ func TestParseBackendIds(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendReloadNoChange(t *testing.T) {
|
||||
func TestBackendReloadNoChange(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -257,7 +267,7 @@ func TestBackendReloadNoChange(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendReloadChangeExistingURL(t *testing.T) {
|
||||
func TestBackendReloadChangeExistingURL(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -296,7 +306,7 @@ func TestBackendReloadChangeExistingURL(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendReloadChangeSecret(t *testing.T) {
|
||||
func TestBackendReloadChangeSecret(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -331,7 +341,7 @@ func TestBackendReloadChangeSecret(t *testing.T) {
|
|||
assert.Equal(t, n_cfg, o_cfg, "BackendConfiguration should be equal after Reload")
|
||||
}
|
||||
|
||||
func TestBackendReloadAddBackend(t *testing.T) {
|
||||
func TestBackendReloadAddBackend(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -370,7 +380,7 @@ func TestBackendReloadAddBackend(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendReloadRemoveHost(t *testing.T) {
|
||||
func TestBackendReloadRemoveHost(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -406,7 +416,7 @@ func TestBackendReloadRemoveHost(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendReloadRemoveBackendFromSharedHost(t *testing.T) {
|
||||
func TestBackendReloadRemoveBackendFromSharedHost(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -458,7 +468,7 @@ func mustParse(s string) *url.URL {
|
|||
return p
|
||||
}
|
||||
|
||||
func TestBackendConfiguration_EtcdCompat(t *testing.T) {
|
||||
func TestBackendConfiguration_EtcdCompat(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -619,7 +629,7 @@ func TestBackendCommonSecret(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBackendChangeUrls(t *testing.T) {
|
||||
func TestBackendChangeUrls(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -710,7 +720,7 @@ func TestBackendChangeUrls(t *testing.T) {
|
|||
assert.Nil(b1)
|
||||
}
|
||||
|
||||
func TestBackendConfiguration_EtcdChangeUrls(t *testing.T) {
|
||||
func TestBackendConfiguration_EtcdChangeUrls(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsBackendsCurrent)
|
||||
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
|
|||
|
|
@ -93,10 +93,10 @@ func NewBackendServer(ctx context.Context, config *goconf.ConfigFile, hub *Hub,
|
|||
turnserverslist := slices.Collect(SplitEntries(turnservers, ","))
|
||||
if len(turnserverslist) != 0 {
|
||||
if turnapikey == "" {
|
||||
return nil, fmt.Errorf("need a TURN API key if TURN servers are configured")
|
||||
return nil, errors.New("need a TURN API key if TURN servers are configured")
|
||||
}
|
||||
if turnsecret == "" {
|
||||
return nil, fmt.Errorf("need a shared TURN secret if TURN servers are configured")
|
||||
return nil, errors.New("need a shared TURN secret if TURN servers are configured")
|
||||
}
|
||||
|
||||
logger.Printf("Using configured TURN API key")
|
||||
|
|
@ -167,12 +167,7 @@ func (b *BackendServer) Start(r *mux.Router) error {
|
|||
"nextcloud-spreed-signaling": "Welcome",
|
||||
"version": b.version,
|
||||
}
|
||||
welcomeMessage, err := json.Marshal(welcome)
|
||||
if err != nil {
|
||||
// Should never happen.
|
||||
return err
|
||||
}
|
||||
|
||||
welcomeMessage, _ := json.Marshal(welcome)
|
||||
b.welcomeMessage = string(welcomeMessage) + "\n"
|
||||
|
||||
if b.debug {
|
||||
|
|
|
|||
|
|
@ -390,6 +390,7 @@ func TestBackendServer_UnsupportedRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_RoomInvite(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -457,6 +458,7 @@ func RunTestBackendServer_RoomInvite(ctx context.Context, t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_RoomDisinvite(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -615,6 +617,7 @@ func TestBackendServer_RoomDisinviteDifferentRooms(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_RoomUpdate(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -684,6 +687,7 @@ func RunTestBackendServer_RoomUpdate(ctx context.Context, t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_RoomDelete(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, backend := range eventBackendsForTest {
|
||||
t.Run(backend, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -750,6 +754,7 @@ func RunTestBackendServer_RoomDelete(ctx context.Context, t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_ParticipantsUpdatePermissions(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -1069,6 +1074,7 @@ func TestBackendServer_ParticipantsUpdateTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestBackendServer_InCallAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -1310,11 +1316,12 @@ func TestBackendServer_TurnCredentials(t *testing.T) {
|
|||
m.Write([]byte(cred.Username)) // nolint
|
||||
password := base64.StdEncoding.EncodeToString(m.Sum(nil))
|
||||
assert.Equal(password, cred.Password)
|
||||
assert.EqualValues((24 * time.Hour).Seconds(), cred.TTL)
|
||||
assert.InEpsilon((24 * time.Hour).Seconds(), cred.TTL, 0.0001)
|
||||
assert.Equal(turnServers, cred.URIs)
|
||||
}
|
||||
|
||||
func TestBackendServer_StatsAllowedIps(t *testing.T) {
|
||||
t.Parallel()
|
||||
config := goconf.NewConfigFile()
|
||||
config.AddOption("app", "trustedproxies", "1.2.3.4")
|
||||
config.AddOption("stats", "allowed_ips", "127.0.0.1, 192.168.0.1, 192.168.1.1/24")
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"slices"
|
||||
"time"
|
||||
|
|
@ -52,12 +51,12 @@ type backendStorageEtcd struct {
|
|||
|
||||
func NewBackendStorageEtcd(logger Logger, config *goconf.ConfigFile, etcdClient *EtcdClient) (BackendStorage, error) {
|
||||
if etcdClient == nil || !etcdClient.IsConfigured() {
|
||||
return nil, fmt.Errorf("no etcd endpoints configured")
|
||||
return nil, errors.New("no etcd endpoints configured")
|
||||
}
|
||||
|
||||
keyPrefix, _ := config.GetString("backend", "backendprefix")
|
||||
if keyPrefix == "" {
|
||||
return nil, fmt.Errorf("no backend prefix configured")
|
||||
return nil, errors.New("no backend prefix configured")
|
||||
}
|
||||
|
||||
initializedCtx, initializedFunc := context.WithCancel(context.Background())
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func (tl *testListener) EtcdClientCreated(client *EtcdClient) {
|
|||
close(tl.closed)
|
||||
}
|
||||
|
||||
func Test_BackendStorageEtcdNoLeak(t *testing.T) {
|
||||
func Test_BackendStorageEtcdNoLeak(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
etcd, client := NewEtcdClientForTest(t)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package signaling
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -41,10 +41,10 @@ type exponentialBackoff struct {
|
|||
|
||||
func NewExponentialBackoff(initial time.Duration, maxWait time.Duration) (Backoff, error) {
|
||||
if initial <= 0 {
|
||||
return nil, fmt.Errorf("initial must be larger than 0")
|
||||
return nil, errors.New("initial must be larger than 0")
|
||||
}
|
||||
if maxWait < initial {
|
||||
return nil, fmt.Errorf("maxWait must be larger or equal to initial")
|
||||
return nil, errors.New("maxWait must be larger or equal to initial")
|
||||
}
|
||||
|
||||
return &exponentialBackoff{
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ import (
|
|||
)
|
||||
|
||||
func TestBackoff_Exponential(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
minWait := 100 * time.Millisecond
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ func (e *capabilitiesEntry) update(ctx context.Context, u *url.URL, now time.Tim
|
|||
if !strings.HasSuffix(capUrl.Path, "/") {
|
||||
capUrl.Path += "/"
|
||||
}
|
||||
capUrl.Path = capUrl.Path + "ocs/v2.php/cloud/capabilities"
|
||||
capUrl.Path += "ocs/v2.php/cloud/capabilities"
|
||||
} else if pos := strings.Index(capUrl.Path, "/ocs/v2.php/"); pos >= 0 {
|
||||
capUrl.Path = capUrl.Path[:pos+11] + "/cloud/capabilities"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import (
|
|||
|
||||
func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*CapabilitiesResponse, http.ResponseWriter) error) (*url.URL, *Capabilities) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
pool, err := NewHttpClientPool(1, false)
|
||||
require.NoError(err)
|
||||
capabilities, err := NewCapabilities("0.0", pool)
|
||||
|
|
@ -75,10 +76,11 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
config := api.StringMap{
|
||||
"signaling": signaling,
|
||||
}
|
||||
spreedCapa, _ := json.Marshal(api.StringMap{
|
||||
spreedCapa, err := json.Marshal(api.StringMap{
|
||||
"features": features,
|
||||
"config": config,
|
||||
})
|
||||
assert.NoError(err)
|
||||
emptyArray := []byte("[]")
|
||||
response := &CapabilitiesResponse{
|
||||
Version: CapabilitiesVersion{
|
||||
|
|
@ -91,7 +93,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
}
|
||||
|
||||
data, err := json.Marshal(response)
|
||||
assert.NoError(t, err, "Could not marshal %+v", response)
|
||||
assert.NoError(err, "Could not marshal %+v", response)
|
||||
|
||||
var ocs OcsResponse
|
||||
ocs.Ocs = &OcsBody{
|
||||
|
|
@ -103,7 +105,7 @@ func NewCapabilitiesForTestWithCallback(t *testing.T, callback func(*Capabilitie
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
var cc []string
|
||||
if !strings.Contains(t.Name(), "NoCache") {
|
||||
|
|
@ -354,7 +356,7 @@ func TestCapabilitiesShortCache(t *testing.T) {
|
|||
value = called.Load()
|
||||
assert.EqualValues(1, value)
|
||||
|
||||
// The capabilities are cached for a minumum duration.
|
||||
// The capabilities are cached for a minimum duration.
|
||||
SetCapabilitiesGetNow(t, capabilities, func() time.Time {
|
||||
return time.Now().Add(minCapabilitiesCacheDuration / 2)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestChannelWaiters(t *testing.T) {
|
||||
t.Parallel()
|
||||
var waiters ChannelWaiters
|
||||
|
||||
ch1 := make(chan struct{}, 1)
|
||||
|
|
|
|||
|
|
@ -531,7 +531,7 @@ func main() {
|
|||
if *memprofile != "" {
|
||||
f, err := os.Create(*memprofile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal(err) // nolint (defer pprof.StopCPUProfile() will not run which is ok in case of errors)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
var stats Stats
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCounterWriter(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
var b bytes.Buffer
|
||||
|
|
@ -37,10 +38,10 @@ func TestCounterWriter(t *testing.T) {
|
|||
w: &b,
|
||||
counter: &written,
|
||||
}
|
||||
if count, err := w.Write(nil); assert.NoError(err) && assert.EqualValues(0, count) {
|
||||
assert.EqualValues(0, written)
|
||||
if count, err := w.Write(nil); assert.NoError(err) && assert.Equal(0, count) {
|
||||
assert.Equal(0, written)
|
||||
}
|
||||
if count, err := w.Write([]byte("foo")); assert.NoError(err) && assert.EqualValues(3, count) {
|
||||
assert.EqualValues(3, written)
|
||||
if count, err := w.Write([]byte("foo")); assert.NoError(err) && assert.Equal(3, count) {
|
||||
assert.Equal(3, written)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ package signaling
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net/url"
|
||||
|
|
@ -835,28 +836,29 @@ func (s *ClientSession) IsAllowedToSend(data *MessageClientMessageData) error {
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if data != nil && data.RoomType == "screen" {
|
||||
switch {
|
||||
case data != nil && data.RoomType == "screen":
|
||||
if s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_SCREEN) {
|
||||
return nil
|
||||
}
|
||||
return &PermissionError{PERMISSION_MAY_PUBLISH_SCREEN}
|
||||
} else if s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_MEDIA) {
|
||||
case s.hasPermissionLocked(PERMISSION_MAY_PUBLISH_MEDIA):
|
||||
// Client is allowed to publish any media (audio / video).
|
||||
return nil
|
||||
} else if data != nil && data.Type == "offer" {
|
||||
case data != nil && data.Type == "offer":
|
||||
// Check what user is trying to publish and check permissions accordingly.
|
||||
if _, err := s.isSdpAllowedToSendLocked(data.offerSdp); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
} else {
|
||||
default:
|
||||
// Candidate or unknown event, check if client is allowed to publish any media.
|
||||
if s.hasAnyPermissionLocked(PERMISSION_MAY_PUBLISH_AUDIO, PERMISSION_MAY_PUBLISH_VIDEO) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("permission check failed")
|
||||
return errors.New("permission check failed")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,24 +84,6 @@ func TestBandwidth_Client(t *testing.T) {
|
|||
|
||||
func TestBandwidth_Backend(t *testing.T) {
|
||||
t.Parallel()
|
||||
hub, _, _, server := CreateHubWithMultipleBackendsForTest(t)
|
||||
|
||||
u, err := url.Parse(server.URL + "/one")
|
||||
require.NoError(t, err)
|
||||
backend := hub.backend.GetBackend(u)
|
||||
require.NotNil(t, backend, "Could not get backend")
|
||||
|
||||
backend.maxScreenBitrate = 1000
|
||||
backend.maxStreamBitrate = 2000
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
mcu := NewTestMCU(t)
|
||||
require.NoError(t, mcu.Start(ctx))
|
||||
defer mcu.Stop()
|
||||
|
||||
hub.SetMcu(mcu)
|
||||
|
||||
streamTypes := []StreamType{
|
||||
StreamTypeVideo,
|
||||
|
|
@ -110,8 +92,29 @@ func TestBandwidth_Backend(t *testing.T) {
|
|||
|
||||
for _, streamType := range streamTypes {
|
||||
t.Run(string(streamType), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
hub, _, _, server := CreateHubWithMultipleBackendsForTest(t)
|
||||
|
||||
u, err := url.Parse(server.URL + "/one")
|
||||
require.NoError(err)
|
||||
backend := hub.backend.GetBackend(u)
|
||||
require.NotNil(backend, "Could not get backend")
|
||||
|
||||
backend.maxScreenBitrate = 1000
|
||||
backend.maxStreamBitrate = 2000
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
mcu := NewTestMCU(t)
|
||||
require.NoError(mcu.Start(ctx))
|
||||
defer mcu.Stop()
|
||||
|
||||
hub.SetMcu(mcu)
|
||||
|
||||
client := NewTestClient(t, server, hub)
|
||||
defer client.CloseWithBye()
|
||||
|
||||
|
|
@ -243,13 +246,16 @@ func TestFeatureChatRelay(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
t.Run("without-chat-relay", testFunc(false))
|
||||
t.Run("with-chat-relay", testFunc(true))
|
||||
t.Run("without-chat-relay", testFunc(false)) // nolint:paralleltest
|
||||
t.Run("with-chat-relay", testFunc(true)) // nolint:paralleltest
|
||||
}
|
||||
|
||||
func TestFeatureChatRelayFederation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var testFunc = func(feature bool) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
@ -452,8 +458,8 @@ func TestFeatureChatRelayFederation(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
t.Run("without-chat-relay", testFunc(false))
|
||||
t.Run("with-chat-relay", testFunc(true))
|
||||
t.Run("without-chat-relay", testFunc(false)) // nolint:paralleltest
|
||||
t.Run("with-chat-relay", testFunc(true)) // nolint:paralleltest
|
||||
}
|
||||
|
||||
func TestPermissionHideDisplayNames(t *testing.T) {
|
||||
|
|
@ -566,6 +572,6 @@ func TestPermissionHideDisplayNames(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
t.Run("without-hide-displaynames", testFunc(false))
|
||||
t.Run("with-hide-displaynames", testFunc(true))
|
||||
t.Run("without-hide-displaynames", testFunc(false)) // nolint:paralleltest
|
||||
t.Run("with-hide-displaynames", testFunc(true)) // nolint:paralleltest
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCloserMulti(t *testing.T) {
|
||||
t.Parallel()
|
||||
closer := NewCloser()
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -48,6 +49,7 @@ func TestCloserMulti(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCloserCloseBeforeWait(t *testing.T) {
|
||||
t.Parallel()
|
||||
closer := NewCloser()
|
||||
closer.Close()
|
||||
assert.True(t, closer.IsClosed())
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestConcurrentStringStringMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
var m ConcurrentMap[string, string]
|
||||
assert.Equal(0, m.Len())
|
||||
|
|
@ -83,7 +84,7 @@ func TestConcurrentStringStringMap(t *testing.T) {
|
|||
|
||||
key := "key-" + strconv.Itoa(x)
|
||||
rnd := newRandomString(32)
|
||||
for y := 0; y < count; y = y + 1 {
|
||||
for y := range count {
|
||||
value := rnd + "-" + strconv.Itoa(y)
|
||||
m.Set(key, value)
|
||||
if v, found := m.Get(key); !found {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDeferredExecutor_MultiClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 0)
|
||||
defer e.waitForStop()
|
||||
|
|
@ -38,6 +39,7 @@ func TestDeferredExecutor_MultiClose(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeferredExecutor_QueueSize(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 0)
|
||||
|
|
@ -61,6 +63,7 @@ func TestDeferredExecutor_QueueSize(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeferredExecutor_Order(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
|
@ -89,6 +92,7 @@ func TestDeferredExecutor_Order(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeferredExecutor_CloseFromFunc(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
|
@ -103,6 +107,7 @@ func TestDeferredExecutor_CloseFromFunc(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeferredExecutor_DeferAfterClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
|
@ -115,6 +120,7 @@ func TestDeferredExecutor_DeferAfterClose(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDeferredExecutor_WaitForStopTwice(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
e := NewDeferredExecutor(logger, 64)
|
||||
defer e.waitForStop()
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ func (m *mockDnsLookup) lookup(host string) ([]net.IP, error) {
|
|||
ips, found := m.ips[host]
|
||||
if !found {
|
||||
return nil, &net.DNSError{
|
||||
Err: fmt.Sprintf("could not resolve %s", host),
|
||||
Err: "could not resolve " + host,
|
||||
Name: host,
|
||||
IsNotFound: true,
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ func (r *dnsMonitorReceiver) ExpectNone() {
|
|||
r.expected = expectNone
|
||||
}
|
||||
|
||||
func TestDnsMonitor(t *testing.T) {
|
||||
func TestDnsMonitor(t *testing.T) { // nolint:paralleltest
|
||||
lookup := newMockDnsLookupForTest(t)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
|
@ -292,6 +292,7 @@ func TestDnsMonitor(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDnsMonitorIP(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
|
|
@ -316,7 +317,7 @@ func TestDnsMonitorIP(t *testing.T) {
|
|||
time.Sleep(5 * interval)
|
||||
}
|
||||
|
||||
func TestDnsMonitorNoLookupIfEmpty(t *testing.T) {
|
||||
func TestDnsMonitorNoLookupIfEmpty(t *testing.T) { // nolint:paralleltest
|
||||
interval := time.Millisecond
|
||||
monitor := newDnsMonitorForTest(t, interval)
|
||||
|
||||
|
|
@ -401,7 +402,7 @@ func (r *deadlockMonitorReceiver) Close() {
|
|||
r.wg.Wait()
|
||||
}
|
||||
|
||||
func TestDnsMonitorDeadlock(t *testing.T) {
|
||||
func TestDnsMonitorDeadlock(t *testing.T) { // nolint:paralleltest
|
||||
lookup := newMockDnsLookupForTest(t)
|
||||
ip1 := net.ParseIP("192.168.0.1")
|
||||
ip2 := net.ParseIP("192.168.0.2")
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import (
|
|||
)
|
||||
|
||||
func Test_FederationInvalidToken(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -73,6 +74,7 @@ func Test_FederationInvalidToken(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_Federation(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -206,7 +208,7 @@ func Test_Federation(t *testing.T) {
|
|||
|
||||
// Leaving and re-joining a room as "direct" session will trigger correct events.
|
||||
if room, ok := client1.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room.Room.RoomId)
|
||||
assert.Empty(room.Room.RoomId)
|
||||
}
|
||||
|
||||
client2.RunUntilLeft(ctx, hello1.Hello)
|
||||
|
|
@ -223,7 +225,7 @@ func Test_Federation(t *testing.T) {
|
|||
|
||||
// Leaving and re-joining a room as "federated" session will trigger correct events.
|
||||
if room, ok := client2.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room.Room.RoomId)
|
||||
assert.Empty(room.Room.RoomId)
|
||||
}
|
||||
|
||||
client1.RunUntilLeft(ctx, &HelloServerMessage{
|
||||
|
|
@ -483,11 +485,12 @@ func Test_Federation(t *testing.T) {
|
|||
}, hello3.Hello, hello4.Hello)
|
||||
|
||||
if room3, ok := client2.JoinRoom(ctx, ""); ok {
|
||||
assert.Equal("", room3.Room.RoomId)
|
||||
assert.Empty(room3.Room.RoomId)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_FederationJoinRoomTwice(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -593,6 +596,7 @@ func Test_FederationJoinRoomTwice(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_FederationChangeRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -700,6 +704,7 @@ func Test_FederationChangeRoom(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_FederationMedia(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -803,6 +808,7 @@ func Test_FederationMedia(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_FederationResume(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -922,6 +928,7 @@ func Test_FederationResume(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_FederationResumeNewSession(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -1036,7 +1043,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
|
|||
// session and get "joined" events for all sessions in the room (including
|
||||
// its own).
|
||||
if message, ok := client2.RunUntilMessage(ctx); ok {
|
||||
assert.Equal("", message.Id)
|
||||
assert.Empty(message.Id)
|
||||
require.Equal("room", message.Type)
|
||||
require.Equal(federatedRoomId, message.Room.RoomId)
|
||||
}
|
||||
|
|
@ -1044,6 +1051,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_FederationTransientData(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ var (
|
|||
)
|
||||
|
||||
func TestFileWatcher_NotExist(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
logger := NewLoggerForTest(t)
|
||||
|
|
@ -46,7 +47,7 @@ func TestFileWatcher_NotExist(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestFileWatcher_File(t *testing.T) {
|
||||
func TestFileWatcher_File(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
|
@ -88,7 +89,7 @@ func TestFileWatcher_File(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestFileWatcher_CurrentDir(t *testing.T) {
|
||||
func TestFileWatcher_CurrentDir(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
|
@ -132,6 +133,7 @@ func TestFileWatcher_CurrentDir(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_Rename(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
|
|
@ -172,6 +174,7 @@ func TestFileWatcher_Rename(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_Symlink(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
|
|
@ -203,6 +206,7 @@ func TestFileWatcher_Symlink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_ChangeSymlinkTarget(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
|
|
@ -239,6 +243,7 @@ func TestFileWatcher_ChangeSymlinkTarget(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_OtherSymlink(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
|
|
@ -272,6 +277,7 @@ func TestFileWatcher_OtherSymlink(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_RenameSymlinkTarget(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
tmpdir := t.TempDir()
|
||||
|
|
@ -315,6 +321,7 @@ func TestFileWatcher_RenameSymlinkTarget(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestFileWatcher_UpdateSymlinkFolder(t *testing.T) {
|
||||
t.Parallel()
|
||||
// This mimics what k8s is doing with configmaps / secrets.
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestFlags(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
var f Flags
|
||||
assert.EqualValues(0, f.Get())
|
||||
|
|
|
|||
3
geoip.go
3
geoip.go
|
|
@ -25,6 +25,7 @@ import (
|
|||
"archive/tar"
|
||||
"compress/gzip"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
|
|
@ -40,7 +41,7 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrDatabaseNotInitialized = fmt.Errorf("GeoIP database not initialized yet")
|
||||
ErrDatabaseNotInitialized = errors.New("GeoIP database not initialized yet")
|
||||
)
|
||||
|
||||
func GetGeoIpDownloadUrl(license string) string {
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ func GetGeoIpUrlForTest(t *testing.T) string {
|
|||
}
|
||||
|
||||
func TestGeoLookup(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, GetGeoIpUrlForTest(t))
|
||||
|
|
@ -88,6 +89,7 @@ func TestGeoLookup(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGeoLookupCaching(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, GetGeoIpUrlForTest(t))
|
||||
|
|
@ -102,18 +104,20 @@ func TestGeoLookupCaching(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGeoLookupContinent(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := map[string][]string{
|
||||
"AU": {"OC"},
|
||||
"DE": {"EU"},
|
||||
"RU": {"EU"},
|
||||
"": nil,
|
||||
"INVALID ": nil,
|
||||
"AU": {"OC"},
|
||||
"DE": {"EU"},
|
||||
"RU": {"EU"},
|
||||
"": nil,
|
||||
"INVALID": nil,
|
||||
}
|
||||
|
||||
for country, expected := range tests {
|
||||
t.Run(country, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
continents := LookupContinents(country)
|
||||
if !assert.Equal(t, len(expected), len(continents), "Continents didn't match for %s: got %s, expected %s", country, continents, expected) {
|
||||
if !assert.Len(t, continents, len(expected), "Continents didn't match for %s: got %s, expected %s", country, continents, expected) {
|
||||
return
|
||||
}
|
||||
for idx, c := range expected {
|
||||
|
|
@ -126,6 +130,7 @@ func TestGeoLookupContinent(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGeoLookupCloseEmpty(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
reader, err := NewGeoLookupFromUrl(logger, "ignore-url")
|
||||
require.NoError(t, err)
|
||||
|
|
@ -133,6 +138,7 @@ func TestGeoLookupCloseEmpty(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGeoLookupFromFile(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
geoIpUrl := GetGeoIpUrlForTest(t)
|
||||
|
|
@ -196,6 +202,7 @@ func TestGeoLookupFromFile(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsValidContinent(t *testing.T) {
|
||||
t.Parallel()
|
||||
for country, continents := range ContinentMap {
|
||||
for _, continent := range continents {
|
||||
assert.True(t, IsValidContinent(continent), "Continent %s of country %s is not valid", continent, country)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
ErrNoSuchResumeId = fmt.Errorf("unknown resume id")
|
||||
ErrNoSuchResumeId = errors.New("unknown resume id")
|
||||
|
||||
customResolverPrefix atomic.Uint64
|
||||
)
|
||||
|
|
@ -619,7 +619,7 @@ loop:
|
|||
c.closeClient(client)
|
||||
client.SetSelf(true)
|
||||
} else if version != c.version {
|
||||
c.logger.Printf("WARNING: Node %s is runing different version %s than local node (%s)", client.Target(), version, c.version)
|
||||
c.logger.Printf("WARNING: Node %s is running different version %s than local node (%s)", client.Target(), version, c.version)
|
||||
} else {
|
||||
c.logger.Printf("Checked GRPC server id of %s running version %s", client.Target(), version)
|
||||
}
|
||||
|
|
@ -802,12 +802,12 @@ func (c *GrpcClients) loadTargetsEtcd(config *goconf.ConfigFile, fromReload bool
|
|||
defer c.mu.Unlock()
|
||||
|
||||
if !c.etcdClient.IsConfigured() {
|
||||
return fmt.Errorf("no etcd endpoints configured")
|
||||
return errors.New("no etcd endpoints configured")
|
||||
}
|
||||
|
||||
targetPrefix, _ := config.GetString("grpc", "targetprefix")
|
||||
if targetPrefix == "" {
|
||||
return fmt.Errorf("no GRPC target prefix configured")
|
||||
return errors.New("no GRPC target prefix configured")
|
||||
}
|
||||
c.targetPrefix = targetPrefix
|
||||
if c.targetInformation == nil {
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ func waitForEvent(ctx context.Context, t *testing.T, ch <-chan struct{}) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_GrpcClients_EtcdInitial(t *testing.T) {
|
||||
func Test_GrpcClients_EtcdInitial(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
|
|
@ -219,7 +219,7 @@ func Test_GrpcClients_EtcdIgnoreSelf(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_GrpcClients_DnsDiscovery(t *testing.T) {
|
||||
func Test_GrpcClients_DnsDiscovery(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
|
|
@ -274,7 +274,7 @@ func Test_GrpcClients_DnsDiscovery(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) {
|
||||
func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) { // nolint:paralleltest
|
||||
assert := assert.New(t)
|
||||
lookup := newMockDnsLookupForTest(t)
|
||||
target := "testgrpc:12345"
|
||||
|
|
@ -303,7 +303,7 @@ func Test_GrpcClients_DnsDiscoveryInitialFailed(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_GrpcClients_Encryption(t *testing.T) {
|
||||
func Test_GrpcClients_Encryption(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
require := require.New(t)
|
||||
serverKey, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func NewGrpcServerForTest(t *testing.T) (server *GrpcServer, addr string) {
|
|||
return NewGrpcServerForTestWithConfig(t, config)
|
||||
}
|
||||
|
||||
func Test_GrpcServer_ReloadCerts(t *testing.T) {
|
||||
func Test_GrpcServer_ReloadCerts(t *testing.T) { // nolint:paralleltest
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
|
|
@ -167,7 +167,7 @@ func Test_GrpcServer_ReloadCerts(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_GrpcServer_ReloadCA(t *testing.T) {
|
||||
func Test_GrpcServer_ReloadCA(t *testing.T) { // nolint:paralleltest
|
||||
logger := NewLoggerForTest(t)
|
||||
require := require.New(t)
|
||||
serverKey, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
|
@ -60,7 +59,7 @@ func (p *Pool) Put(c *http.Client) {
|
|||
|
||||
func newPool(host string, constructor func() *http.Client, size int) (*Pool, error) {
|
||||
if size <= 0 {
|
||||
return nil, fmt.Errorf("can't create empty pool")
|
||||
return nil, errors.New("can't create empty pool")
|
||||
}
|
||||
|
||||
p := &Pool{
|
||||
|
|
@ -87,7 +86,7 @@ type HttpClientPool struct {
|
|||
|
||||
func NewHttpClientPool(maxConcurrentRequestsPerHost int, skipVerify bool) (*HttpClientPool, error) {
|
||||
if maxConcurrentRequestsPerHost <= 0 {
|
||||
return nil, fmt.Errorf("can't create empty pool")
|
||||
return nil, errors.New("can't create empty pool")
|
||||
}
|
||||
|
||||
tlsconfig := &tls.Config{
|
||||
|
|
|
|||
2
hub.go
2
hub.go
|
|
@ -1460,7 +1460,7 @@ func (h *Hub) processHelloV2(ctx context.Context, client HandlerClient, message
|
|||
keyData, _, found = h.backend.capabilities.GetStringConfig(backendCtx, url, ConfigGroupSignaling, ConfigKeyHelloV2TokenKey)
|
||||
}
|
||||
if !found {
|
||||
return nil, fmt.Errorf("no key found for issuer")
|
||||
return nil, errors.New("no key found for issuer")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
108
hub_test.go
108
hub_test.go
|
|
@ -53,6 +53,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/api"
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -341,22 +342,22 @@ func WaitForHub(ctx context.Context, t *testing.T, h *Hub) {
|
|||
|
||||
func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Request, *BackendClientRequest) *BackendClientResponse) func(http.ResponseWriter, *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
rnd := r.Header.Get(HeaderBackendSignalingRandom)
|
||||
checksum := r.Header.Get(HeaderBackendSignalingChecksum)
|
||||
if rnd == "" || checksum == "" {
|
||||
require.Fail("No checksum headers found", "request to %s", r.URL)
|
||||
assert.Fail("No checksum headers found", "request to %s", r.URL)
|
||||
}
|
||||
|
||||
if verify := CalculateBackendChecksum(rnd, body, testBackendSecret); verify != checksum {
|
||||
require.Fail("Backend checksum verification failed", "request to %s", r.URL)
|
||||
assert.Fail("Backend checksum verification failed", "request to %s", r.URL)
|
||||
}
|
||||
|
||||
var request BackendClientRequest
|
||||
require.NoError(json.Unmarshal(body, &request))
|
||||
assert.NoError(json.Unmarshal(body, &request))
|
||||
|
||||
response := f(w, r, &request)
|
||||
if response == nil {
|
||||
|
|
@ -365,7 +366,7 @@ func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Req
|
|||
}
|
||||
|
||||
data, err := json.Marshal(response)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
if r.Header.Get("OCS-APIRequest") != "" {
|
||||
var ocs OcsResponse
|
||||
|
|
@ -378,7 +379,7 @@ func validateBackendChecksum(t *testing.T, f func(http.ResponseWriter, *http.Req
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
@ -414,8 +415,7 @@ func processAuthRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
|
|||
userdata := map[string]string{
|
||||
"displayname": "Displayname " + params.UserId,
|
||||
}
|
||||
data, err := json.Marshal(userdata)
|
||||
require.NoError(err)
|
||||
data, _ := json.Marshal(userdata)
|
||||
response.Auth.User = data
|
||||
return response
|
||||
}
|
||||
|
|
@ -476,8 +476,7 @@ func processRoomRequest(t *testing.T, w http.ResponseWriter, r *http.Request, re
|
|||
data := map[string]string{
|
||||
"userid": "userid-from-sessiondata",
|
||||
}
|
||||
tmp, err := json.Marshal(data)
|
||||
require.NoError(err)
|
||||
tmp, _ := json.Marshal(data)
|
||||
response.Room.Session = tmp
|
||||
case "test-room-initial-permissions":
|
||||
permissions := []Permission{PERMISSION_MAY_PUBLISH_AUDIO}
|
||||
|
|
@ -539,30 +538,22 @@ func processSessionRequest(t *testing.T, w http.ResponseWriter, r *http.Request,
|
|||
return response
|
||||
}
|
||||
|
||||
var pingRequests map[*testing.T][]*BackendClientRequest
|
||||
var (
|
||||
pingRequests internal.TestStorage[[]*BackendClientRequest]
|
||||
)
|
||||
|
||||
func getPingRequests(t *testing.T) []*BackendClientRequest {
|
||||
return pingRequests[t]
|
||||
entries, _ := pingRequests.Get(t)
|
||||
return entries
|
||||
}
|
||||
|
||||
func clearPingRequests(t *testing.T) {
|
||||
delete(pingRequests, t)
|
||||
pingRequests.Del(t)
|
||||
}
|
||||
|
||||
func storePingRequest(t *testing.T, request *BackendClientRequest) {
|
||||
if entries, found := pingRequests[t]; !found {
|
||||
if pingRequests == nil {
|
||||
pingRequests = make(map[*testing.T][]*BackendClientRequest)
|
||||
}
|
||||
pingRequests[t] = []*BackendClientRequest{
|
||||
request,
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
clearPingRequests(t)
|
||||
})
|
||||
} else {
|
||||
pingRequests[t] = append(entries, request)
|
||||
}
|
||||
entries, _ := pingRequests.Get(t)
|
||||
pingRequests.Set(t, append(entries, request))
|
||||
}
|
||||
|
||||
func processPingRequest(t *testing.T, w http.ResponseWriter, r *http.Request, request *BackendClientRequest) *BackendClientResponse {
|
||||
|
|
@ -594,7 +585,7 @@ type testAuthToken struct {
|
|||
}
|
||||
|
||||
var (
|
||||
authTokens testStorage[testAuthToken]
|
||||
authTokens internal.TestStorage[testAuthToken]
|
||||
)
|
||||
|
||||
func ensureAuthTokens(t *testing.T) (string, string) {
|
||||
|
|
@ -703,7 +694,7 @@ func registerBackendHandler(t *testing.T, router *mux.Router) {
|
|||
}
|
||||
|
||||
var (
|
||||
skipV2Capabilities testStorage[bool]
|
||||
skipV2Capabilities internal.TestStorage[bool]
|
||||
)
|
||||
|
||||
func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
||||
|
|
@ -755,7 +746,7 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
if (strings.Contains(t.Name(), "V2") && !skipV2) || strings.Contains(t.Name(), "Federation") {
|
||||
key := getPublicAuthToken(t)
|
||||
public, err := x509.MarshalPKIXPublicKey(key)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
var pemType string
|
||||
if strings.Contains(t.Name(), "ECDSA") {
|
||||
pemType = "ECDSA PUBLIC KEY"
|
||||
|
|
@ -777,10 +768,11 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
signaling[ConfigKeyHelloV2TokenKey] = string(public)
|
||||
}
|
||||
}
|
||||
spreedCapa, _ := json.Marshal(api.StringMap{
|
||||
spreedCapa, err := json.Marshal(api.StringMap{
|
||||
"features": features,
|
||||
"config": config,
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
response := &CapabilitiesResponse{
|
||||
Version: CapabilitiesVersion{
|
||||
Major: 20,
|
||||
|
|
@ -803,7 +795,7 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
|
|||
Data: data,
|
||||
}
|
||||
data, err = json.Marshal(ocs)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(data) // nolint
|
||||
|
|
@ -1001,8 +993,10 @@ func TestClientHelloV1(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
|
@ -1037,8 +1031,10 @@ func TestClientHelloV2(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_IssuedInFuture(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
|
@ -1062,8 +1058,10 @@ func TestClientHelloV2_IssuedInFuture(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_IssuedFarInFuture(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
||||
|
|
@ -1083,8 +1081,10 @@ func TestClientHelloV2_IssuedFarInFuture(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_Expired(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
||||
|
|
@ -1104,8 +1104,10 @@ func TestClientHelloV2_Expired(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_IssuedAtMissing(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
||||
|
|
@ -1125,8 +1127,10 @@ func TestClientHelloV2_IssuedAtMissing(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_ExpiresAtMissing(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
||||
|
|
@ -1146,8 +1150,10 @@ func TestClientHelloV2_ExpiresAtMissing(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloV2_CachedCapabilities(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, algo := range testHelloV2Algorithms {
|
||||
t.Run(algo, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
hub, _, _, server := CreateHubForTest(t)
|
||||
|
|
@ -1220,6 +1226,7 @@ func TestClientHelloAllowAll(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientHelloSessionLimit(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -1364,7 +1371,7 @@ func TestSessionIdsUnordered(t *testing.T) {
|
|||
ctx, cancel := context.WithTimeout(context.Background(), testTimeout)
|
||||
defer cancel()
|
||||
|
||||
_, hello := NewTestClientWithHello(ctx, t, server, hub, testDefaultUserId)
|
||||
_, hello := NewTestClientWithHello(ctx, t, server, hub, testDefaultUserId) // nolint:testifylint
|
||||
assert.Equal(testDefaultUserId, hello.Hello.UserId, "%+v", hello.Hello)
|
||||
assert.NotEmpty(hello.Hello.SessionId, "%+v", hello.Hello)
|
||||
|
||||
|
|
@ -1753,7 +1760,7 @@ func runGrpcProxyTest(t *testing.T, f func(hub1, hub2 *Hub, server1, server2 *ht
|
|||
f(hub1, hub2, server1, server2)
|
||||
}
|
||||
|
||||
func TestClientHelloResumeProxy(t *testing.T) {
|
||||
func TestClientHelloResumeProxy(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) {
|
||||
require := require.New(t)
|
||||
|
|
@ -1803,7 +1810,7 @@ func TestClientHelloResumeProxy(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestClientHelloResumeProxy_Takeover(t *testing.T) {
|
||||
func TestClientHelloResumeProxy_Takeover(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) {
|
||||
require := require.New(t)
|
||||
|
|
@ -1857,7 +1864,7 @@ func TestClientHelloResumeProxy_Takeover(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestClientHelloResumeProxy_Disconnect(t *testing.T) {
|
||||
func TestClientHelloResumeProxy_Disconnect(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
runGrpcProxyTest(t, func(hub1, hub2 *Hub, server1, server2 *httptest.Server) {
|
||||
require := require.New(t)
|
||||
|
|
@ -1952,6 +1959,7 @@ func TestClientHelloInternal(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientMessageToSessionId(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2016,6 +2024,7 @@ func TestClientMessageToSessionId(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientControlToSessionId(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2238,6 +2247,7 @@ func TestClientMessageToUserIdMultipleSessions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientMessageToRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2300,6 +2310,7 @@ func TestClientMessageToRoom(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientControlToRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2362,6 +2373,7 @@ func TestClientControlToRoom(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientMessageToCall(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2466,6 +2478,7 @@ func TestClientMessageToCall(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientControlToCall(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -2591,7 +2604,7 @@ func TestJoinRoom(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinRoomBackendBandwidth(t *testing.T) {
|
||||
|
|
@ -2837,7 +2850,7 @@ func TestExpectAnonymousJoinRoomAfterLeave(t *testing.T) {
|
|||
|
||||
// Leave room
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
|
||||
// Perform housekeeping in the future, this will cause the connection to
|
||||
// be terminated because the anonymous client didn't join a room.
|
||||
|
|
@ -2882,7 +2895,7 @@ func TestJoinRoomChange(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinMultiple(t *testing.T) {
|
||||
|
|
@ -2916,13 +2929,13 @@ func TestJoinMultiple(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client1.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
|
||||
// The second client will now receive a "left" event
|
||||
client2.RunUntilLeft(ctx, hello1.Hello)
|
||||
|
||||
roomMsg = MustSucceed2(t, client2.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestJoinDisplaynamesPermission(t *testing.T) {
|
||||
|
|
@ -3046,10 +3059,11 @@ func TestJoinRoomSwitchClient(t *testing.T) {
|
|||
|
||||
// Leave room.
|
||||
roomMsg = MustSucceed2(t, client2.JoinRoom, ctx, "")
|
||||
require.Equal("", roomMsg.Room.RoomId)
|
||||
require.Empty(roomMsg.Room.RoomId)
|
||||
}
|
||||
|
||||
func TestGetRealUserIP(t *testing.T) {
|
||||
t.Parallel()
|
||||
testcases := []struct {
|
||||
expected string
|
||||
headers http.Header
|
||||
|
|
@ -3474,6 +3488,7 @@ func TestRoomParticipantsListUpdateWhileDisconnected(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientTakeoverRoomSession(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -3903,6 +3918,7 @@ loop:
|
|||
}
|
||||
|
||||
func TestClientRequestOfferNotInRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -4301,6 +4317,7 @@ func TestSameRoomOnDifferentUrls(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestClientSendOffer(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -4443,6 +4460,7 @@ func TestClientUnshareScreen(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestVirtualClientSessions(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -4683,6 +4701,7 @@ func TestVirtualClientSessions(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDuplicateVirtualSessions(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -5042,12 +5061,14 @@ func DoTestSwitchToOne(t *testing.T, details api.StringMap) {
|
|||
}
|
||||
|
||||
func TestSwitchToOneMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
DoTestSwitchToOne(t, api.StringMap{
|
||||
"foo": "bar",
|
||||
})
|
||||
}
|
||||
|
||||
func TestSwitchToOneList(t *testing.T) {
|
||||
t.Parallel()
|
||||
DoTestSwitchToOne(t, nil)
|
||||
}
|
||||
|
||||
|
|
@ -5140,6 +5161,7 @@ func DoTestSwitchToMultiple(t *testing.T, details1 api.StringMap, details2 api.S
|
|||
}
|
||||
|
||||
func TestSwitchToMultipleMap(t *testing.T) {
|
||||
t.Parallel()
|
||||
DoTestSwitchToMultiple(t, api.StringMap{
|
||||
"foo": "bar",
|
||||
}, api.StringMap{
|
||||
|
|
@ -5148,10 +5170,12 @@ func TestSwitchToMultipleMap(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSwitchToMultipleList(t *testing.T) {
|
||||
t.Parallel()
|
||||
DoTestSwitchToMultiple(t, nil, nil)
|
||||
}
|
||||
|
||||
func TestSwitchToMultipleMixed(t *testing.T) {
|
||||
t.Parallel()
|
||||
DoTestSwitchToMultiple(t, api.StringMap{
|
||||
"foo": "bar",
|
||||
}, nil)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCanonicalizeUrl(t *testing.T) {
|
||||
t.Parallel()
|
||||
mustParse := func(s string) *url.URL {
|
||||
t.Helper()
|
||||
u, err := url.Parse(s)
|
||||
|
|
@ -66,7 +67,7 @@ func TestCanonicalizeUrl(t *testing.T) {
|
|||
for idx, tc := range testcases {
|
||||
expectChanged := tc.url.String() != tc.expected.String()
|
||||
canonicalized, changed := CanonicalizeUrl(tc.url)
|
||||
assert.Equal(tc.url, canonicalized) //urls will be changed inplace
|
||||
assert.Equal(tc.url, canonicalized) // urls will be changed inplace
|
||||
if !expectChanged {
|
||||
assert.False(changed, "testcase %d should not have changed the url", idx)
|
||||
continue
|
||||
|
|
@ -79,6 +80,7 @@ func TestCanonicalizeUrl(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestCanonicalizeUrlString(t *testing.T) {
|
||||
t.Parallel()
|
||||
testcases := []struct {
|
||||
s string
|
||||
expected string
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestIsLoopbackIP(t *testing.T) {
|
||||
t.Parallel()
|
||||
loopback := []string{
|
||||
"127.0.0.1",
|
||||
"127.1.0.1",
|
||||
|
|
@ -51,6 +52,7 @@ func TestIsLoopbackIP(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestIsPrivateIP(t *testing.T) {
|
||||
t.Parallel()
|
||||
private := []string{
|
||||
"10.1.2.3",
|
||||
"172.20.21.22",
|
||||
|
|
|
|||
41
internal/make_ptr_test.go
Normal file
41
internal/make_ptr_test.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/**
|
||||
* Standalone signaling server for the Nextcloud Spreed app.
|
||||
* Copyright (C) 2025 struktur AG
|
||||
*
|
||||
* @author Joachim Bauch <bauch@struktur.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_MakePtr(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
|
||||
if v := MakePtr(10); assert.NotNil(v) {
|
||||
assert.Equal(10, *v)
|
||||
}
|
||||
|
||||
if v := MakePtr("foo"); assert.NotNil(v) {
|
||||
assert.Equal("foo", *v)
|
||||
}
|
||||
}
|
||||
78
internal/test_storage.go
Normal file
78
internal/test_storage.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
/**
|
||||
* Standalone signaling server for the Nextcloud Spreed app.
|
||||
* Copyright (C) 2025 struktur AG
|
||||
*
|
||||
* @author Joachim Bauch <bauch@struktur.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type TestStorage[T any] struct {
|
||||
mu sync.Mutex
|
||||
// +checklocks:mu
|
||||
entries map[string]T // +checklocksignore: Not supported yet, see https://github.com/google/gvisor/issues/11671
|
||||
}
|
||||
|
||||
func (s *TestStorage[T]) cleanup(key string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
delete(s.entries, key)
|
||||
if len(s.entries) == 0 {
|
||||
s.entries = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TestStorage[T]) Set(tb testing.TB, value T) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
key := tb.Name()
|
||||
if _, found := s.entries[key]; !found {
|
||||
tb.Cleanup(func() {
|
||||
s.cleanup(key)
|
||||
})
|
||||
}
|
||||
|
||||
if s.entries == nil {
|
||||
s.entries = make(map[string]T)
|
||||
}
|
||||
s.entries[key] = value
|
||||
}
|
||||
|
||||
func (s *TestStorage[T]) Get(tb testing.TB) (T, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
key := tb.Name()
|
||||
if value, found := s.entries[key]; found {
|
||||
return value, true
|
||||
}
|
||||
|
||||
var defaultValue T
|
||||
return defaultValue, false
|
||||
}
|
||||
|
||||
func (s *TestStorage[T]) Del(tb testing.TB) {
|
||||
key := tb.Name()
|
||||
s.cleanup(key)
|
||||
}
|
||||
64
internal/test_storage_test.go
Normal file
64
internal/test_storage_test.go
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Standalone signaling server for the Nextcloud Spreed app.
|
||||
* Copyright (C) 2025 struktur AG
|
||||
*
|
||||
* @author Joachim Bauch <bauch@struktur.de>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_TestStorage(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
var storage TestStorage[int]
|
||||
|
||||
t.Cleanup(func() {
|
||||
storage.mu.Lock()
|
||||
defer storage.mu.Unlock()
|
||||
|
||||
assert.Nil(storage.entries)
|
||||
})
|
||||
|
||||
v, found := storage.Get(t)
|
||||
assert.False(found, "expected missing value, got %d", v)
|
||||
|
||||
storage.Set(t, 10)
|
||||
v, found = storage.Get(t)
|
||||
assert.True(found)
|
||||
assert.Equal(10, v)
|
||||
|
||||
storage.Set(t, 20)
|
||||
v, found = storage.Get(t)
|
||||
assert.True(found)
|
||||
assert.Equal(20, v)
|
||||
|
||||
storage.Del(t)
|
||||
|
||||
v, found = storage.Get(t)
|
||||
assert.False(found, "expected missing value, got %d", v)
|
||||
|
||||
storage.Set(t, 30)
|
||||
v, found = storage.Get(t)
|
||||
assert.True(found)
|
||||
assert.Equal(30, v)
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ import (
|
|||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
|
@ -372,7 +373,7 @@ func (gateway *JanusGateway) send(msg api.StringMap, t *transaction) (uint64, er
|
|||
if gateway.conn == nil {
|
||||
gateway.writeMu.Unlock()
|
||||
gateway.removeTransaction(id)
|
||||
return 0, fmt.Errorf("not connected")
|
||||
return 0, errors.New("not connected")
|
||||
}
|
||||
|
||||
err = gateway.conn.WriteMessage(websocket.TextMessage, data)
|
||||
|
|
@ -719,7 +720,7 @@ type JanusHandle struct {
|
|||
// Type // pub or sub
|
||||
Type string
|
||||
|
||||
//User // Userid
|
||||
// User // Userid
|
||||
User string
|
||||
|
||||
// Events is a receive only channel that can be used to receive events
|
||||
|
|
|
|||
42
lru_test.go
42
lru_test.go
|
|
@ -22,96 +22,98 @@
|
|||
package signaling
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLruUnbound(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
lru := NewLruCache[int](0)
|
||||
count := 10
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
lru.Set(key, i)
|
||||
}
|
||||
assert.Equal(count, lru.Len())
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
// The first key ("0") is now the oldest.
|
||||
lru.RemoveOldest()
|
||||
assert.Equal(count-1, lru.Len())
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
|
||||
// NOTE: Key "0" no longer exists below, so make sure to not set it again.
|
||||
|
||||
// Using the same keys will update the ordering.
|
||||
for i := count - 1; i >= 1; i-- {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
lru.Set(key, i)
|
||||
}
|
||||
assert.Equal(count-1, lru.Len())
|
||||
// NOTE: The same ordering as the Set calls above.
|
||||
for i := count - 1; i >= 1; i-- {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
|
||||
// The last key ("9") is now the oldest.
|
||||
lru.RemoveOldest()
|
||||
assert.Equal(count-2, lru.Len())
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i == 0 || i == count-1 {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove an arbitrary key from the cache
|
||||
key := fmt.Sprintf("%d", count/2)
|
||||
key := strconv.Itoa(count / 2)
|
||||
lru.Remove(key)
|
||||
assert.Equal(count-3, lru.Len())
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i == 0 || i == count-1 || i == count/2 {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLruBound(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
size := 2
|
||||
lru := NewLruCache[int](size)
|
||||
count := 10
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
lru.Set(key, i)
|
||||
}
|
||||
assert.Equal(size, lru.Len())
|
||||
// Only the last "size" entries have been stored.
|
||||
for i := range count {
|
||||
key := fmt.Sprintf("%d", i)
|
||||
key := strconv.Itoa(i)
|
||||
value := lru.Get(key)
|
||||
if i < count-size {
|
||||
assert.EqualValues(0, value, "The value for key %s should have been removed", key)
|
||||
assert.Equal(0, value, "The value for key %s should have been removed", key)
|
||||
} else {
|
||||
assert.EqualValues(i, value, "Failed for %s", key)
|
||||
assert.Equal(i, value, "Failed for %s", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package signaling
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ var (
|
|||
defaultMaxStreamBitrate = api.BandwidthFromMegabits(1)
|
||||
defaultMaxScreenBitrate = api.BandwidthFromMegabits(2)
|
||||
|
||||
ErrNotConnected = fmt.Errorf("not connected")
|
||||
ErrNotConnected = errors.New("not connected")
|
||||
)
|
||||
|
||||
type MediaType int
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestCommonMcuStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
collectAndLint(t, commonMcuStats...)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -466,7 +466,7 @@ func (m *mcuJanus) Start(ctx context.Context) error {
|
|||
|
||||
m.logger.Printf("Used dependencies: %+v", info.Dependencies)
|
||||
if !info.DataChannels {
|
||||
return fmt.Errorf("data channels are not supported")
|
||||
return errors.New("data channels are not supported")
|
||||
}
|
||||
|
||||
m.logger.Println("Data channels are supported")
|
||||
|
|
|
|||
|
|
@ -247,9 +247,7 @@ func (c *mcuJanusClient) selectStream(ctx context.Context, stream *streamSelecti
|
|||
configure_msg := api.StringMap{
|
||||
"request": "configure",
|
||||
}
|
||||
if stream != nil {
|
||||
stream.AddToMessage(configure_msg)
|
||||
}
|
||||
stream.AddToMessage(configure_msg)
|
||||
_, err := handle.Message(ctx, configure_msg, nil)
|
||||
if err != nil {
|
||||
callback(err, nil)
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ type TestJanusEventsServerHandler struct {
|
|||
|
||||
func (h *TestJanusEventsServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
h.t.Helper()
|
||||
require := require.New(h.t)
|
||||
assert := assert.New(h.t)
|
||||
conn, err := h.upgrader.Upgrade(w, r, nil)
|
||||
require.NoError(err)
|
||||
assert.NoError(err)
|
||||
|
||||
if conn.Subprotocol() == JanusEventsSubprotocol {
|
||||
addr := h.addr
|
||||
|
|
@ -70,10 +70,10 @@ func (h *TestJanusEventsServerHandler) ServeHTTP(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
deadline := time.Now().Add(time.Second)
|
||||
require.NoError(conn.SetWriteDeadline(deadline))
|
||||
require.NoError(conn.WriteJSON(map[string]string{"error": "invalid_subprotocol"}))
|
||||
require.NoError(conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseProtocolError, "invalid_subprotocol"), deadline))
|
||||
require.NoError(conn.Close())
|
||||
assert.NoError(conn.SetWriteDeadline(deadline))
|
||||
assert.NoError(conn.WriteJSON(map[string]string{"error": "invalid_subprotocol"}))
|
||||
assert.NoError(conn.WriteControl(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseProtocolError, "invalid_subprotocol"), deadline))
|
||||
assert.NoError(conn.Close())
|
||||
}
|
||||
|
||||
func NewTestJanusEventsHandlerServer(t *testing.T) (*httptest.Server, string, *TestJanusEventsServerHandler) {
|
||||
|
|
@ -121,7 +121,7 @@ func TestJanusEventsHandlerNoMcu(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal("no mcu configured", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ func TestJanusEventsHandlerInvalidMcu(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal(websocket.CloseInternalServerErr, ce.Code)
|
||||
assert.Equal("mcu does not support events", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +186,7 @@ func TestJanusEventsHandlerPublicIP(t *testing.T) {
|
|||
if mt, msg, err := conn.ReadMessage(); err == nil {
|
||||
assert.Fail("connection was not closed", "expected close error, got message %s with type %d", string(msg), mt)
|
||||
} else if assert.ErrorAs(err, &ce) {
|
||||
assert.EqualValues(websocket.ClosePolicyViolation, ce.Code)
|
||||
assert.Equal(websocket.ClosePolicyViolation, ce.Code)
|
||||
assert.Equal("only loopback and private connections allowed", ce.Text)
|
||||
}
|
||||
}
|
||||
|
|
@ -210,14 +210,14 @@ func (m *TestMcuWithEvents) UpdateBandwidth(handle uint64, media string, sent ap
|
|||
switch m.idx {
|
||||
case 1:
|
||||
assert.EqualValues(1, handle)
|
||||
assert.EqualValues("audio", media)
|
||||
assert.EqualValues(api.BandwidthFromBytes(100), sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(200), received)
|
||||
assert.Equal("audio", media)
|
||||
assert.Equal(api.BandwidthFromBytes(100), sent)
|
||||
assert.Equal(api.BandwidthFromBytes(200), received)
|
||||
case 2:
|
||||
assert.EqualValues(1, handle)
|
||||
assert.EqualValues("video", media)
|
||||
assert.EqualValues(api.BandwidthFromBytes(200), sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(300), received)
|
||||
assert.Equal("video", media)
|
||||
assert.Equal(api.BandwidthFromBytes(200), sent)
|
||||
assert.Equal(api.BandwidthFromBytes(300), received)
|
||||
default:
|
||||
assert.Fail("too many updates", "received update %d (handle=%d, media=%s, sent=%d, received=%d)", m.idx, handle, media, sent, received)
|
||||
}
|
||||
|
|
@ -498,6 +498,7 @@ func TestJanusEventsHandlerDifferentTypes(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestJanusEventsHandlerNotGrouped(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
@ -637,6 +638,6 @@ func TestValueCounter(t *testing.T) {
|
|||
assert.EqualValues(1, c.Update("foo", 11))
|
||||
assert.EqualValues(10, c.Update("bar", 10))
|
||||
assert.EqualValues(1, c.Update("bar", 11))
|
||||
assert.EqualValues(uint64(math.MaxUint64-10), c.Update("baz", math.MaxUint64-10))
|
||||
assert.Equal(uint64(math.MaxUint64-10), c.Update("baz", math.MaxUint64-10))
|
||||
assert.EqualValues(20, c.Update("baz", 10))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -319,7 +319,8 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream,
|
|||
continue
|
||||
}
|
||||
|
||||
if strings.EqualFold(s.Type, "audio") {
|
||||
switch {
|
||||
case strings.EqualFold(s.Type, "audio"):
|
||||
s.Codec = answerCodec.Name
|
||||
if value, found := getFmtpValue(answerCodec.Fmtp, "useinbandfec"); found && value == "1" {
|
||||
s.Fec = true
|
||||
|
|
@ -330,7 +331,7 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream,
|
|||
if value, found := getFmtpValue(answerCodec.Fmtp, "stereo"); found && value == "1" {
|
||||
s.Stereo = true
|
||||
}
|
||||
} else if strings.EqualFold(s.Type, "video") {
|
||||
case strings.EqualFold(s.Type, "video"):
|
||||
s.Codec = answerCodec.Name
|
||||
// TODO: Determine if SVC is used.
|
||||
s.Svc = false
|
||||
|
|
@ -384,9 +385,9 @@ func (p *mcuJanusPublisher) GetStreams(ctx context.Context) ([]PublisherStream,
|
|||
}
|
||||
}
|
||||
|
||||
} else if strings.EqualFold(s.Type, "data") { // nolint
|
||||
case strings.EqualFold(s.Type, "data"):
|
||||
// Already handled above.
|
||||
} else {
|
||||
default:
|
||||
p.logger.Printf("Skip type %s", s.Type)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
)
|
||||
|
||||
func TestGetFmtpValueH264(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
testcases := []struct {
|
||||
fmtp string
|
||||
|
|
@ -70,6 +71,7 @@ func TestGetFmtpValueH264(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestGetFmtpValueVP9(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
testcases := []struct {
|
||||
fmtp string
|
||||
|
|
@ -120,10 +122,10 @@ func TestJanusPublisherRemote(t *testing.T) {
|
|||
assert.Equal(hostname, value)
|
||||
}
|
||||
if value, found := api.GetStringMapEntry[float64](body, "port"); assert.True(found) {
|
||||
assert.EqualValues(port, value)
|
||||
assert.InEpsilon(port, value, 0.0001)
|
||||
}
|
||||
if value, found := api.GetStringMapEntry[float64](body, "rtcp_port"); assert.True(found) {
|
||||
assert.EqualValues(rtcpPort, value)
|
||||
assert.InEpsilon(rtcpPort, value, 0.0001)
|
||||
}
|
||||
if value, found := api.GetStringMapString[string](body, "remote_id"); assert.True(found) {
|
||||
prev := remotePublishId.Swap(value)
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ retry:
|
|||
return
|
||||
}
|
||||
}
|
||||
//p.logger.Println("Joined as listener", join_response)
|
||||
// p.logger.Println("Joined as listener", join_response)
|
||||
|
||||
p.session = join_response.Session
|
||||
callback(nil, join_response.Jsep)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import (
|
|||
)
|
||||
|
||||
func TestMcuJanusStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
collectAndLint(t, janusMcuStats...)
|
||||
}
|
||||
|
||||
|
|
@ -103,11 +104,11 @@ func NewTestJanusGateway(t *testing.T) *TestJanusGateway {
|
|||
assert := assert.New(t)
|
||||
gateway.mu.Lock()
|
||||
defer gateway.mu.Unlock()
|
||||
assert.Len(gateway.sessions, 0)
|
||||
assert.Len(gateway.transactions, 0)
|
||||
assert.Len(gateway.handles, 0)
|
||||
assert.Len(gateway.rooms, 0)
|
||||
assert.Len(gateway.handleRooms, 0)
|
||||
assert.Empty(gateway.sessions)
|
||||
assert.Empty(gateway.transactions)
|
||||
assert.Empty(gateway.handles)
|
||||
assert.Empty(gateway.rooms)
|
||||
assert.Empty(gateway.handleRooms)
|
||||
})
|
||||
|
||||
return gateway
|
||||
|
|
@ -351,7 +352,7 @@ func (g *TestJanusGateway) processMessage(session *JanusSession, handle *TestJan
|
|||
}
|
||||
}
|
||||
|
||||
assert.EqualValues(g.t, room.id, uint64(rid))
|
||||
assert.Equal(g.t, room.id, uint64(rid))
|
||||
delete(g.rooms, uint64(rid))
|
||||
for h, r := range g.handleRooms {
|
||||
if r.id == room.id {
|
||||
|
|
@ -979,7 +980,7 @@ func Test_JanusPublisherGetStreamsAudioOnly(t *testing.T) {
|
|||
stream := streams[0]
|
||||
assert.Equal("audio", stream.Type)
|
||||
assert.Equal("audio", stream.Mid)
|
||||
assert.EqualValues(0, stream.Mindex)
|
||||
assert.Equal(0, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("opus", stream.Codec)
|
||||
assert.False(stream.Stereo)
|
||||
|
|
@ -1061,7 +1062,7 @@ func Test_JanusPublisherGetStreamsAudioVideo(t *testing.T) {
|
|||
stream := streams[0]
|
||||
assert.Equal("audio", stream.Type)
|
||||
assert.Equal("audio", stream.Mid)
|
||||
assert.EqualValues(0, stream.Mindex)
|
||||
assert.Equal(0, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("opus", stream.Codec)
|
||||
assert.False(stream.Stereo)
|
||||
|
|
@ -1071,7 +1072,7 @@ func Test_JanusPublisherGetStreamsAudioVideo(t *testing.T) {
|
|||
stream = streams[1]
|
||||
assert.Equal("video", stream.Type)
|
||||
assert.Equal("video", stream.Mid)
|
||||
assert.EqualValues(1, stream.Mindex)
|
||||
assert.Equal(1, stream.Mindex)
|
||||
assert.False(stream.Disabled)
|
||||
assert.Equal("H264", stream.Codec)
|
||||
assert.Equal("4d0028", stream.ProfileH264)
|
||||
|
|
@ -1080,7 +1081,7 @@ func Test_JanusPublisherGetStreamsAudioVideo(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func Test_JanusPublisherSubscriber(t *testing.T) {
|
||||
func Test_JanusPublisherSubscriber(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("incoming"))
|
||||
ResetStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("outgoing"))
|
||||
|
||||
|
|
@ -1120,12 +1121,12 @@ func Test_JanusPublisherSubscriber(t *testing.T) {
|
|||
assert.Nil(janusPub.Bandwidth())
|
||||
mcu.UpdateBandwidth(janusPub.Handle(), "video", api.BandwidthFromBytes(1000), api.BandwidthFromBytes(2000))
|
||||
if bw := janusPub.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(2000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(2000), bw.Received)
|
||||
}
|
||||
if bw := mcu.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(2000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(1000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(2000), bw.Received)
|
||||
}
|
||||
mcu.updateBandwidthStats()
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("incoming"), 2000)
|
||||
|
|
@ -1148,12 +1149,12 @@ func Test_JanusPublisherSubscriber(t *testing.T) {
|
|||
assert.Nil(janusSub.Bandwidth())
|
||||
mcu.UpdateBandwidth(janusSub.Handle(), "video", api.BandwidthFromBytes(3000), api.BandwidthFromBytes(4000))
|
||||
if bw := janusSub.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(3000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(4000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(3000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(4000), bw.Received)
|
||||
}
|
||||
if bw := mcu.Bandwidth(); assert.NotNil(bw) {
|
||||
assert.EqualValues(api.BandwidthFromBytes(4000), bw.Sent)
|
||||
assert.EqualValues(api.BandwidthFromBytes(6000), bw.Received)
|
||||
assert.Equal(api.BandwidthFromBytes(4000), bw.Sent)
|
||||
assert.Equal(api.BandwidthFromBytes(6000), bw.Received)
|
||||
}
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("incoming"), 2000)
|
||||
checkStatsValue(t, statsJanusBandwidthCurrent.WithLabelValues("outgoing"), 1000)
|
||||
|
|
@ -1165,6 +1166,7 @@ func Test_JanusPublisherSubscriber(t *testing.T) {
|
|||
func Test_JanusSubscriberPublisher(t *testing.T) {
|
||||
t.Parallel()
|
||||
require := require.New(t)
|
||||
assert := assert.New(t)
|
||||
|
||||
mcu, gateway := newMcuJanusForTesting(t)
|
||||
gateway.registerHandlers(map[string]TestJanusHandler{})
|
||||
|
|
@ -1189,7 +1191,10 @@ func Test_JanusSubscriberPublisher(t *testing.T) {
|
|||
defer close(done)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
pub, err := mcu.NewPublisher(ctx, listener1, pubId, "sid", StreamTypeVideo, settings1, initiator1)
|
||||
require.NoError(err)
|
||||
if !assert.NoError(err) {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
<-ready
|
||||
pub.Close(context.Background())
|
||||
|
|
@ -1270,7 +1275,9 @@ func Test_JanusSubscriberRequestOffer(t *testing.T) {
|
|||
"sdp": MockSdpOfferAudioAndVideo,
|
||||
},
|
||||
}
|
||||
require.NoError(data.CheckValid())
|
||||
if !assert.NoError(data.CheckValid()) {
|
||||
return
|
||||
}
|
||||
|
||||
done := make(chan struct{})
|
||||
pub.SendMessage(ctx, &MessageClientMessage{}, data, func(err error, m api.StringMap) {
|
||||
|
|
@ -1395,7 +1402,7 @@ func Test_JanusRemotePublisher(t *testing.T) {
|
|||
assert.EqualValues(1, removed.Load())
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberNoSuchRoom(t *testing.T) {
|
||||
func Test_JanusSubscriberNoSuchRoom(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
@ -1494,7 +1501,7 @@ func Test_JanusSubscriberNoSuchRoom(t *testing.T) {
|
|||
client2.RunUntilOffer(ctx, MockSdpOfferAudioAndVideo)
|
||||
}
|
||||
|
||||
func test_JanusSubscriberAlreadyJoined(t *testing.T) {
|
||||
func test_JanusSubscriberAlreadyJoined(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
@ -1595,15 +1602,15 @@ func test_JanusSubscriberAlreadyJoined(t *testing.T) {
|
|||
client2.RunUntilOffer(ctx, MockSdpOfferAudioAndVideo)
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberAlreadyJoined(t *testing.T) {
|
||||
func Test_JanusSubscriberAlreadyJoined(t *testing.T) { // nolint:paralleltest
|
||||
test_JanusSubscriberAlreadyJoined(t)
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberAlreadyJoinedAttachError(t *testing.T) {
|
||||
func Test_JanusSubscriberAlreadyJoinedAttachError(t *testing.T) { // nolint:paralleltest
|
||||
test_JanusSubscriberAlreadyJoined(t)
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberTimeout(t *testing.T) {
|
||||
func Test_JanusSubscriberTimeout(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
@ -1706,7 +1713,7 @@ func Test_JanusSubscriberTimeout(t *testing.T) {
|
|||
client2.RunUntilOffer(ctx, MockSdpOfferAudioAndVideo)
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberCloseEmptyStreams(t *testing.T) {
|
||||
func Test_JanusSubscriberCloseEmptyStreams(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
@ -1816,7 +1823,7 @@ func Test_JanusSubscriberCloseEmptyStreams(t *testing.T) {
|
|||
assert.Nil(handle, "subscriber should have been closed")
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberRoomDestroyed(t *testing.T) {
|
||||
func Test_JanusSubscriberRoomDestroyed(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
@ -1926,7 +1933,7 @@ func Test_JanusSubscriberRoomDestroyed(t *testing.T) {
|
|||
assert.Nil(handle, "subscriber should have been closed")
|
||||
}
|
||||
|
||||
func Test_JanusSubscriberUpdateOffer(t *testing.T) {
|
||||
func Test_JanusSubscriberUpdateOffer(t *testing.T) { // nolint:paralleltest
|
||||
ResetStatsValue(t, statsSubscribersCurrent.WithLabelValues("video"))
|
||||
t.Cleanup(func() {
|
||||
if !t.Failed() {
|
||||
|
|
|
|||
34
mcu_proxy.go
34
mcu_proxy.go
|
|
@ -1518,11 +1518,11 @@ func NewMcuProxy(ctx context.Context, config *goconf.ConfigFile, etcdClient *Etc
|
|||
|
||||
tokenId, _ := config.GetString("mcu", "token_id")
|
||||
if tokenId == "" {
|
||||
return nil, fmt.Errorf("no token id configured")
|
||||
return nil, errors.New("no token id configured")
|
||||
}
|
||||
tokenKeyFilename, _ := config.GetString("mcu", "token_key")
|
||||
if tokenKeyFilename == "" {
|
||||
return nil, fmt.Errorf("no token key configured")
|
||||
return nil, errors.New("no token key configured")
|
||||
}
|
||||
tokenKeyData, err := os.ReadFile(tokenKeyFilename)
|
||||
if err != nil {
|
||||
|
|
@ -2086,18 +2086,20 @@ func (m *mcuProxy) NewPublisher(ctx context.Context, listener McuListener, id Pu
|
|||
incoming_b = bw.Incoming
|
||||
}
|
||||
|
||||
if incoming_a == nil && incoming_b == nil {
|
||||
switch {
|
||||
case incoming_a == nil && incoming_b == nil:
|
||||
return 0
|
||||
} else if incoming_a == nil && incoming_b != nil {
|
||||
case incoming_a == nil && incoming_b != nil:
|
||||
return -1
|
||||
} else if incoming_a != nil && incoming_b == nil {
|
||||
case incoming_a != nil && incoming_b == nil:
|
||||
return -1
|
||||
} else if *incoming_a < *incoming_b {
|
||||
case *incoming_a < *incoming_b:
|
||||
return -1
|
||||
} else if *incoming_a > *incoming_b {
|
||||
case *incoming_a > *incoming_b:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
})
|
||||
publisher = m.createPublisher(ctx, listener, id, sid, streamType, settings, initiator, connections2, func(c *mcuProxyConnection) bool {
|
||||
return true
|
||||
|
|
@ -2106,7 +2108,7 @@ func (m *mcuProxy) NewPublisher(ctx context.Context, listener McuListener, id Pu
|
|||
|
||||
if publisher == nil {
|
||||
statsProxyNobackendAvailableTotal.WithLabelValues(string(streamType)).Inc()
|
||||
return nil, fmt.Errorf("no MCU connection available")
|
||||
return nil, errors.New("no MCU connection available")
|
||||
}
|
||||
|
||||
return publisher, nil
|
||||
|
|
@ -2349,18 +2351,20 @@ func (m *mcuProxy) NewSubscriber(ctx context.Context, listener McuListener, publ
|
|||
outgoing_b = bw.Outgoing
|
||||
}
|
||||
|
||||
if outgoing_a == nil && outgoing_b == nil {
|
||||
switch {
|
||||
case outgoing_a == nil && outgoing_b == nil:
|
||||
return 0
|
||||
} else if outgoing_a == nil && outgoing_b != nil {
|
||||
case outgoing_a == nil && outgoing_b != nil:
|
||||
return -1
|
||||
} else if outgoing_a != nil && outgoing_b == nil {
|
||||
case outgoing_a != nil && outgoing_b == nil:
|
||||
return -1
|
||||
} else if *outgoing_a < *outgoing_b {
|
||||
case *outgoing_a < *outgoing_b:
|
||||
return -1
|
||||
} else if *outgoing_a > *outgoing_b {
|
||||
case *outgoing_a > *outgoing_b:
|
||||
return 1
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
})
|
||||
subscriber = m.createSubscriber(ctx, listener, publisherInfo, publisher, streamType, connections2, func(c *mcuProxyConnection) bool {
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import (
|
|||
"net/url"
|
||||
"path"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
|
@ -54,6 +55,7 @@ const (
|
|||
)
|
||||
|
||||
func TestMcuProxyStats(t *testing.T) {
|
||||
t.Parallel()
|
||||
collectAndLint(t, proxyMcuStats...)
|
||||
}
|
||||
|
||||
|
|
@ -64,6 +66,7 @@ func newProxyConnectionWithCountry(country string) *mcuProxyConnection {
|
|||
}
|
||||
|
||||
func Test_sortConnectionsForCountry(t *testing.T) {
|
||||
t.Parallel()
|
||||
conn_de := newProxyConnectionWithCountry("DE")
|
||||
conn_at := newProxyConnectionWithCountry("AT")
|
||||
conn_jp := newProxyConnectionWithCountry("JP")
|
||||
|
|
@ -109,6 +112,7 @@ func Test_sortConnectionsForCountry(t *testing.T) {
|
|||
|
||||
for country, test := range testcases {
|
||||
t.Run(country, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sorted := sortConnectionsForCountry(test[0], country, nil)
|
||||
for idx, conn := range sorted {
|
||||
assert.Equal(t, test[1][idx], conn, "Index %d for %s: expected %s, got %s", idx, country, test[1][idx].Country(), conn.Country())
|
||||
|
|
@ -118,6 +122,7 @@ func Test_sortConnectionsForCountry(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_sortConnectionsForCountryWithOverride(t *testing.T) {
|
||||
t.Parallel()
|
||||
conn_de := newProxyConnectionWithCountry("DE")
|
||||
conn_at := newProxyConnectionWithCountry("AT")
|
||||
conn_jp := newProxyConnectionWithCountry("JP")
|
||||
|
|
@ -179,6 +184,7 @@ func Test_sortConnectionsForCountryWithOverride(t *testing.T) {
|
|||
}
|
||||
for country, test := range testcases {
|
||||
t.Run(country, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
sorted := sortConnectionsForCountry(test[0], country, continentMap)
|
||||
for idx, conn := range sorted {
|
||||
assert.Equal(t, test[1][idx], conn, "Index %d for %s: expected %s, got %s", idx, country, test[1][idx].Country(), conn.Country())
|
||||
|
|
@ -257,7 +263,7 @@ func (c *testProxyServerClient) processHello(msg *ProxyClientMessage) (*ProxySer
|
|||
|
||||
key, found := c.server.tokens[claims.Issuer]
|
||||
if !assert.True(c.t, found) {
|
||||
return nil, fmt.Errorf("no key found for issuer")
|
||||
return nil, errors.New("no key found for issuer")
|
||||
}
|
||||
|
||||
return key, nil
|
||||
|
|
@ -312,9 +318,9 @@ func (c *testProxyServerClient) processCommandMessage(msg *ProxyClientMessage) (
|
|||
|
||||
if assert.NotNil(c.t, msg.Command.PublisherSettings) {
|
||||
if assert.NotEqualValues(c.t, 0, msg.Command.PublisherSettings.Bitrate) {
|
||||
assert.EqualValues(c.t, msg.Command.Bitrate, msg.Command.PublisherSettings.Bitrate)
|
||||
assert.Equal(c.t, msg.Command.Bitrate, msg.Command.PublisherSettings.Bitrate)
|
||||
}
|
||||
assert.EqualValues(c.t, msg.Command.MediaTypes, msg.Command.PublisherSettings.MediaTypes)
|
||||
assert.Equal(c.t, msg.Command.MediaTypes, msg.Command.PublisherSettings.MediaTypes)
|
||||
if strings.Contains(c.t.Name(), "Codecs") {
|
||||
assert.Equal(c.t, "opus,g722", msg.Command.PublisherSettings.AudioCodec)
|
||||
assert.Equal(c.t, "vp9,vp8,av1", msg.Command.PublisherSettings.VideoCodec)
|
||||
|
|
@ -366,7 +372,7 @@ func (c *testProxyServerClient) processCommandMessage(msg *ProxyClientMessage) (
|
|||
|
||||
key, found := server.tokens[claims.Issuer]
|
||||
if !assert.True(c.t, found) {
|
||||
return nil, fmt.Errorf("no key found for issuer")
|
||||
return nil, errors.New("no key found for issuer")
|
||||
}
|
||||
|
||||
return key, nil
|
||||
|
|
@ -860,7 +866,7 @@ func newMcuProxyForTestWithOptions(t *testing.T, options proxyTestOptions, idx i
|
|||
if strings.Contains(t.Name(), "DnsDiscovery") {
|
||||
cfg.AddOption("mcu", "dnsdiscovery", "true")
|
||||
}
|
||||
cfg.AddOption("mcu", "proxytimeout", fmt.Sprintf("%d", int(testTimeout.Seconds())))
|
||||
cfg.AddOption("mcu", "proxytimeout", strconv.Itoa(int(testTimeout.Seconds())))
|
||||
var urls []string
|
||||
waitingMap := make(map[string]bool)
|
||||
if len(options.servers) == 0 {
|
||||
|
|
@ -1017,7 +1023,7 @@ func Test_ProxyAddRemoveConnections(t *testing.T) {
|
|||
assert.NoError(waitCtx.Err(), "error while waiting for connection to be removed")
|
||||
}
|
||||
|
||||
func Test_ProxyAddRemoveConnectionsDnsDiscovery(t *testing.T) {
|
||||
func Test_ProxyAddRemoveConnectionsDnsDiscovery(t *testing.T) { // nolint:paralleltest
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -1056,7 +1062,7 @@ func Test_ProxyAddRemoveConnectionsDnsDiscovery(t *testing.T) {
|
|||
require.NotNil(dnsMonitor)
|
||||
|
||||
server2 := NewProxyServerForTest(t, "DE")
|
||||
l, err := net.Listen("tcp", fmt.Sprintf("127.0.0.2:%s", port))
|
||||
l, err := net.Listen("tcp", "127.0.0.2:"+port)
|
||||
require.NoError(err)
|
||||
assert.NoError(server2.server.Listener.Close())
|
||||
server2.server.Listener = l
|
||||
|
|
@ -2438,6 +2444,7 @@ func Test_ProxySubscriberTimeout(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_ProxyReconnectAfter(t *testing.T) {
|
||||
t.Parallel()
|
||||
reasons := []string{
|
||||
"session_resumed",
|
||||
"session_expired",
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ func (m *TestMCU) NewSubscriber(ctx context.Context, listener McuListener, publi
|
|||
|
||||
pub := m.publishers[publisher]
|
||||
if pub == nil {
|
||||
return nil, fmt.Errorf("Waiting for publisher not implemented yet")
|
||||
return nil, errors.New("Waiting for publisher not implemented yet")
|
||||
}
|
||||
|
||||
id := newRandomString(8)
|
||||
|
|
@ -220,7 +220,7 @@ func (p *TestMCUPublisher) SetMedia(mt MediaType) {
|
|||
func (p *TestMCUPublisher) SendMessage(ctx context.Context, message *MessageClientMessage, data *MessageClientMessageData, callback func(error, api.StringMap)) {
|
||||
go func() {
|
||||
if p.isClosed() {
|
||||
callback(fmt.Errorf("Already closed"), nil)
|
||||
callback(errors.New("Already closed"), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ func (s *TestMCUSubscriber) Publisher() PublicSessionId {
|
|||
func (s *TestMCUSubscriber) SendMessage(ctx context.Context, message *MessageClientMessage, data *MessageClientMessageData, callback func(error, api.StringMap)) {
|
||||
go func() {
|
||||
if s.isClosed() {
|
||||
callback(fmt.Errorf("Already closed"), nil)
|
||||
callback(errors.New("Already closed"), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +286,7 @@ func (s *TestMCUSubscriber) SendMessage(ctx context.Context, message *MessageCli
|
|||
case "sendoffer":
|
||||
sdp := s.publisher.sdp
|
||||
if sdp == "" {
|
||||
callback(fmt.Errorf("Publisher not sending (no SDP)"), nil)
|
||||
callback(errors.New("Publisher not sending (no SDP)"), nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
|
@ -105,7 +105,7 @@ func NewNatsClient(ctx context.Context, url string, options ...nats.Option) (Nat
|
|||
logger.Printf("Could not create connection (%s), will retry in %s", err, backoff.NextWait())
|
||||
backoff.Wait(ctx)
|
||||
if ctx.Err() != nil {
|
||||
return nil, fmt.Errorf("interrupted")
|
||||
return nil, errors.New("interrupted")
|
||||
}
|
||||
|
||||
client.conn, err = nats.Connect(url)
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ func CreateLoopbackNatsClientForTest(t *testing.T) NatsClient {
|
|||
return result
|
||||
}
|
||||
|
||||
func TestLoopbackNatsClient_Subscribe(t *testing.T) {
|
||||
func TestLoopbackNatsClient_Subscribe(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
client := CreateLoopbackNatsClientForTest(t)
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ func TestLoopbackNatsClient_Subscribe(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestLoopbackClient_PublishAfterClose(t *testing.T) {
|
||||
func TestLoopbackClient_PublishAfterClose(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
client := CreateLoopbackNatsClientForTest(t)
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ func TestLoopbackClient_PublishAfterClose(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestLoopbackClient_SubscribeAfterClose(t *testing.T) {
|
||||
func TestLoopbackClient_SubscribeAfterClose(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
client := CreateLoopbackNatsClientForTest(t)
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ func TestLoopbackClient_SubscribeAfterClose(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestLoopbackClient_BadSubjects(t *testing.T) {
|
||||
func TestLoopbackClient_BadSubjects(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
client := CreateLoopbackNatsClientForTest(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -107,10 +107,10 @@ func testNatsClient_Subscribe(t *testing.T, client NatsClient) {
|
|||
}
|
||||
<-ch
|
||||
|
||||
require.EqualValues(maxPublish, received.Load(), "Received wrong # of messages")
|
||||
require.Equal(maxPublish, received.Load(), "Received wrong # of messages")
|
||||
}
|
||||
|
||||
func TestNatsClient_Subscribe(t *testing.T) {
|
||||
func TestNatsClient_Subscribe(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
_, _, client := CreateLocalNatsClientForTest(t)
|
||||
|
||||
|
|
@ -124,7 +124,7 @@ func testNatsClient_PublishAfterClose(t *testing.T, client NatsClient) {
|
|||
assert.ErrorIs(t, client.Publish("foo", "bar"), nats.ErrConnectionClosed)
|
||||
}
|
||||
|
||||
func TestNatsClient_PublishAfterClose(t *testing.T) {
|
||||
func TestNatsClient_PublishAfterClose(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
_, _, client := CreateLocalNatsClientForTest(t)
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ func testNatsClient_SubscribeAfterClose(t *testing.T, client NatsClient) {
|
|||
assert.ErrorIs(t, err, nats.ErrConnectionClosed)
|
||||
}
|
||||
|
||||
func TestNatsClient_SubscribeAfterClose(t *testing.T) {
|
||||
func TestNatsClient_SubscribeAfterClose(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
_, _, client := CreateLocalNatsClientForTest(t)
|
||||
|
||||
|
|
@ -162,7 +162,7 @@ func testNatsClient_BadSubjects(t *testing.T, client NatsClient) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNatsClient_BadSubjects(t *testing.T) {
|
||||
func TestNatsClient_BadSubjects(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
_, _, client := CreateLocalNatsClientForTest(t)
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ func TestNatsClient_BadSubjects(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestNatsClient_MaxReconnects(t *testing.T) {
|
||||
func TestNatsClient_MaxReconnects(t *testing.T) { // nolint:paralleltest
|
||||
ensureNoGoroutinesLeak(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import (
|
|||
)
|
||||
|
||||
func TestNotifierNoWaiter(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
// Notifications can be sent even if no waiter exists.
|
||||
|
|
@ -39,6 +40,7 @@ func TestNotifierNoWaiter(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierSimple(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -59,6 +61,7 @@ func TestNotifierSimple(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierMultiNotify(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
waiter := notifier.NewWaiter("foo")
|
||||
|
|
@ -70,6 +73,7 @@ func TestNotifierMultiNotify(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierWaitClosed(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
waiter := notifier.NewWaiter("foo")
|
||||
|
|
@ -79,6 +83,7 @@ func TestNotifierWaitClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierWaitClosedMulti(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
waiter1 := notifier.NewWaiter("foo")
|
||||
|
|
@ -91,6 +96,7 @@ func TestNotifierWaitClosedMulti(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierResetWillNotify(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier Notifier
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -111,6 +117,7 @@ func TestNotifierResetWillNotify(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotifierDuplicate(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
var notifier Notifier
|
||||
var done sync.WaitGroup
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ func (c *RemoteConnection) WaitForDisconnect(ctx context.Context) error {
|
|||
}
|
||||
|
||||
func Test_ProxyRemoteConnectionReconnect(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -101,6 +102,7 @@ func Test_ProxyRemoteConnectionReconnect(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_ProxyRemoteConnectionReconnectUnknownSession(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -143,6 +145,7 @@ func Test_ProxyRemoteConnectionReconnectUnknownSession(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_ProxyRemoteConnectionReconnectExpiredSession(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
@ -178,6 +181,7 @@ func Test_ProxyRemoteConnectionReconnectExpiredSession(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_ProxyRemoteConnectionCreatePublisher(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -153,11 +153,11 @@ type ProxyServer struct {
|
|||
remotePublishers map[string]map[*proxyRemotePublisher]bool
|
||||
}
|
||||
|
||||
func IsPublicIP(IP net.IP) bool {
|
||||
if IP.IsLoopback() || IP.IsLinkLocalMulticast() || IP.IsLinkLocalUnicast() {
|
||||
func IsPublicIP(ip net.IP) bool {
|
||||
if ip.IsLoopback() || ip.IsLinkLocalMulticast() || ip.IsLinkLocalUnicast() {
|
||||
return false
|
||||
}
|
||||
if ip4 := IP.To4(); ip4 != nil {
|
||||
if ip4 := ip.To4(); ip4 != nil {
|
||||
switch {
|
||||
case ip4[0] == 10:
|
||||
return false
|
||||
|
|
@ -289,11 +289,7 @@ func NewProxyServer(ctx context.Context, r *mux.Router, version string, config *
|
|||
"nextcloud-spreed-signaling-proxy": "Welcome",
|
||||
"version": version,
|
||||
}
|
||||
welcomeMessage, err := json.Marshal(welcome)
|
||||
if err != nil {
|
||||
// Should never happen.
|
||||
return nil, err
|
||||
}
|
||||
welcomeMessage, _ := json.Marshal(welcome)
|
||||
|
||||
tokenId, _ := config.GetString("app", "token_id")
|
||||
var tokenKey *rsa.PrivateKey
|
||||
|
|
@ -302,7 +298,7 @@ func NewProxyServer(ctx context.Context, r *mux.Router, version string, config *
|
|||
if tokenId != "" {
|
||||
tokenKeyFilename, _ := config.GetString("app", "token_key")
|
||||
if tokenKeyFilename == "" {
|
||||
return nil, fmt.Errorf("no token key configured")
|
||||
return nil, errors.New("no token key configured")
|
||||
}
|
||||
tokenKeyData, err := os.ReadFile(tokenKeyFilename)
|
||||
if err != nil {
|
||||
|
|
@ -428,7 +424,7 @@ func (s *ProxyServer) checkOrigin(r *http.Request) bool {
|
|||
func (s *ProxyServer) Start(config *goconf.ConfigFile) error {
|
||||
s.url, _ = signaling.GetStringOptionWithEnv(config, "mcu", "url")
|
||||
if s.url == "" {
|
||||
return fmt.Errorf("no MCU server url configured")
|
||||
return errors.New("no MCU server url configured")
|
||||
}
|
||||
|
||||
mcuType, _ := config.GetString("mcu", "type")
|
||||
|
|
@ -470,7 +466,7 @@ func (s *ProxyServer) Start(config *goconf.ConfigFile) error {
|
|||
s.logger.Printf("Could not initialize %s MCU at %s (%s) will retry in %s", mcuType, s.url, err, backoff.NextWait())
|
||||
backoff.Wait(ctx)
|
||||
if ctx.Err() != nil {
|
||||
return fmt.Errorf("cancelled")
|
||||
return errors.New("cancelled")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1433,7 +1429,7 @@ func (s *ProxyServer) parseToken(tokenValue string) (*signaling.TokenClaims, str
|
|||
if !ok {
|
||||
s.logger.Printf("Unsupported claims type: %+v", token.Claims)
|
||||
reason = "unsupported-claims"
|
||||
return nil, fmt.Errorf("unsupported claims type")
|
||||
return nil, errors.New("unsupported claims type")
|
||||
}
|
||||
|
||||
tokenKey, err := s.tokens.Get(claims.Issuer)
|
||||
|
|
@ -1446,7 +1442,7 @@ func (s *ProxyServer) parseToken(tokenValue string) (*signaling.TokenClaims, str
|
|||
if tokenKey == nil || tokenKey.key == nil {
|
||||
s.logger.Printf("Issuer %s is not supported", claims.Issuer)
|
||||
reason = "unsupported-issuer"
|
||||
return nil, fmt.Errorf("no key found for issuer")
|
||||
return nil, errors.New("no key found for issuer")
|
||||
}
|
||||
|
||||
return tokenKey.key, nil
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ func newProxyServerForTest(t *testing.T) (*ProxyServer, *rsa.PrivateKey, *httpte
|
|||
}
|
||||
|
||||
func TestTokenValid(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy, key, _ := newProxyServerForTest(t)
|
||||
|
||||
claims := &signaling.TokenClaims{
|
||||
|
|
@ -174,6 +175,7 @@ func TestTokenValid(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTokenNotSigned(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy, _, _ := newProxyServerForTest(t)
|
||||
|
||||
claims := &signaling.TokenClaims{
|
||||
|
|
@ -198,6 +200,7 @@ func TestTokenNotSigned(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTokenUnknown(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy, key, _ := newProxyServerForTest(t)
|
||||
|
||||
claims := &signaling.TokenClaims{
|
||||
|
|
@ -222,6 +225,7 @@ func TestTokenUnknown(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTokenInFuture(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy, key, _ := newProxyServerForTest(t)
|
||||
|
||||
claims := &signaling.TokenClaims{
|
||||
|
|
@ -246,6 +250,7 @@ func TestTokenInFuture(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestTokenExpired(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy, key, _ := newProxyServerForTest(t)
|
||||
|
||||
claims := &signaling.TokenClaims{
|
||||
|
|
@ -270,6 +275,7 @@ func TestTokenExpired(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestPublicIPs(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
public := []string{
|
||||
"8.8.8.8",
|
||||
|
|
@ -302,6 +308,7 @@ func TestPublicIPs(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestWebsocketFeatures(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
_, _, server := newProxyServerForTest(t)
|
||||
|
||||
|
|
@ -329,6 +336,7 @@ func TestWebsocketFeatures(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProxyCreateSession(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
_, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -480,6 +488,7 @@ func NewPublisherTestMCU(t *testing.T) *PublisherTestMCU {
|
|||
}
|
||||
|
||||
func TestProxyPublisherBandwidth(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -528,10 +537,10 @@ func TestProxyPublisherBandwidth(t *testing.T) {
|
|||
assert.EqualValues(1, message.Event.Load)
|
||||
if bw := message.Event.Bandwidth; assert.NotNil(bw) {
|
||||
if assert.NotNil(bw.Incoming) {
|
||||
assert.EqualValues(20, *bw.Incoming)
|
||||
assert.InEpsilon(20, *bw.Incoming, 0.0001)
|
||||
}
|
||||
if assert.NotNil(bw.Outgoing) {
|
||||
assert.EqualValues(10, *bw.Outgoing)
|
||||
assert.InEpsilon(10, *bw.Outgoing, 0.0001)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -599,6 +608,7 @@ func (m *HangingTestMCU) NewSubscriber(ctx context.Context, listener signaling.M
|
|||
}
|
||||
|
||||
func TestProxyCancelOnClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -677,6 +687,7 @@ func (m *CodecsTestMCU) NewPublisher(ctx context.Context, listener signaling.Mcu
|
|||
}
|
||||
|
||||
func TestProxyCodecs(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -759,6 +770,7 @@ func NewStreamTestMCU(t *testing.T, streams []signaling.PublisherStream) *Stream
|
|||
}
|
||||
|
||||
func TestProxyStreams(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -881,7 +893,7 @@ func (p *TestRemotePublisher) MaxBitrate() api.Bandwidth {
|
|||
}
|
||||
|
||||
func (p *TestRemotePublisher) Close(ctx context.Context) {
|
||||
if count := p.refcnt.Add(-1); assert.True(p.t, count >= 0) && count == 0 {
|
||||
if count := p.refcnt.Add(-1); assert.GreaterOrEqual(p.t, int(count), 0) && count == 0 {
|
||||
p.closeFunc()
|
||||
shortCtx, cancel := context.WithTimeout(ctx, time.Millisecond)
|
||||
defer cancel()
|
||||
|
|
@ -983,6 +995,7 @@ func (m *RemoteSubscriberTestMCU) NewRemoteSubscriber(ctx context.Context, liste
|
|||
}
|
||||
|
||||
func TestProxyRemoteSubscriber(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -1077,6 +1090,7 @@ func TestProxyRemoteSubscriber(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProxyCloseRemoteOnSessionClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -1230,8 +1244,8 @@ func (p *UnpublishRemoteTestPublisher) UnpublishRemote(ctx context.Context, remo
|
|||
assert.Equal(p.t, remoteId, p.remoteId)
|
||||
if remoteData := p.remoteData; assert.NotNil(p.t, remoteData) &&
|
||||
assert.Equal(p.t, remoteData.hostname, hostname) &&
|
||||
assert.EqualValues(p.t, remoteData.port, port) &&
|
||||
assert.EqualValues(p.t, remoteData.rtcpPort, rtcpPort) {
|
||||
assert.Equal(p.t, remoteData.port, port) &&
|
||||
assert.Equal(p.t, remoteData.rtcpPort, rtcpPort) {
|
||||
p.remoteId = ""
|
||||
p.remoteData = nil
|
||||
}
|
||||
|
|
@ -1239,6 +1253,7 @@ func (p *UnpublishRemoteTestPublisher) UnpublishRemote(ctx context.Context, remo
|
|||
}
|
||||
|
||||
func TestProxyUnpublishRemote(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -1323,8 +1338,8 @@ func TestProxyUnpublishRemote(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1355,6 +1370,7 @@ func TestProxyUnpublishRemote(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -1439,8 +1455,8 @@ func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1465,8 +1481,8 @@ func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1486,6 +1502,7 @@ func TestProxyUnpublishRemotePublisherClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProxyUnpublishRemoteOnSessionClose(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
proxy, key, server := newProxyServerForTest(t)
|
||||
|
|
@ -1570,8 +1587,8 @@ func TestProxyUnpublishRemoteOnSessionClose(t *testing.T) {
|
|||
assert.Equal(hello2.Hello.SessionId, publisher.getRemoteId())
|
||||
if remoteData := publisher.getRemoteData(); assert.NotNil(remoteData) {
|
||||
assert.Equal("remote-host", remoteData.hostname)
|
||||
assert.EqualValues(10001, remoteData.port)
|
||||
assert.EqualValues(10002, remoteData.rtcpPort)
|
||||
assert.Equal(10001, remoteData.port)
|
||||
assert.Equal(10002, remoteData.rtcpPort)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ package main
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
|
|
@ -59,7 +60,7 @@ func NewProxyTokensEtcd(logger signaling.Logger, config *goconf.ConfigFile) (Pro
|
|||
}
|
||||
|
||||
if !client.IsConfigured() {
|
||||
return nil, fmt.Errorf("no etcd endpoints configured")
|
||||
return nil, errors.New("no etcd endpoints configured")
|
||||
}
|
||||
|
||||
result := &tokensEtcd{
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ func generateAndSaveKey(t *testing.T, etcd *embed.Etcd, name string) *rsa.Privat
|
|||
}
|
||||
|
||||
func TestProxyTokensEtcd(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
tokens, etcd := newTokensEtcdForTesting(t)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,8 +54,7 @@ func newProxyConfigEtcd(t *testing.T, proxy McuProxy) (*embed.Etcd, ProxyConfig)
|
|||
|
||||
func SetEtcdProxy(t *testing.T, etcd *embed.Etcd, path string, proxy *TestProxyInformationEtcd) {
|
||||
t.Helper()
|
||||
data, err := json.Marshal(proxy)
|
||||
require.NoError(t, err)
|
||||
data, _ := json.Marshal(proxy)
|
||||
SetEtcdValue(etcd, path, data)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ func updateProxyConfigStatic(t *testing.T, config ProxyConfig, dns bool, urls ..
|
|||
}
|
||||
|
||||
func TestProxyConfigStaticSimple(t *testing.T) {
|
||||
t.Parallel()
|
||||
proxy := newMcuProxyForConfig(t)
|
||||
config, _ := newProxyConfigStatic(t, proxy, false, "https://foo/")
|
||||
proxy.Expect("add", "https://foo/")
|
||||
|
|
@ -72,7 +73,7 @@ func TestProxyConfigStaticSimple(t *testing.T) {
|
|||
updateProxyConfigStatic(t, config, false, "https://bar/", "https://baz/")
|
||||
}
|
||||
|
||||
func TestProxyConfigStaticDNS(t *testing.T) {
|
||||
func TestProxyConfigStaticDNS(t *testing.T) { // nolint:paralleltest
|
||||
lookup := newMockDnsLookupForTest(t)
|
||||
proxy := newMcuProxyForConfig(t)
|
||||
config, dnsMonitor := newProxyConfigStatic(t, proxy, true, "https://foo/")
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestPublisherStatsCounter(t *testing.T) {
|
||||
func TestPublisherStatsCounter(t *testing.T) { // nolint:paralleltest
|
||||
RegisterJanusMcuStats()
|
||||
|
||||
var c publisherStatsCounter
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -90,7 +89,7 @@ func (s *RemoteSession) OnProxyMessage(msg *ServerSessionMessage) error {
|
|||
}
|
||||
|
||||
if !s.client.SendMessage(message) {
|
||||
return fmt.Errorf("could not send message to client")
|
||||
return errors.New("could not send message to client")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ func NewRoomPingForTest(ctx context.Context, t *testing.T) (*url.URL, *RoomPing)
|
|||
}
|
||||
|
||||
func TestSingleRoomPing(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
|
|
@ -101,6 +102,7 @@ func TestSingleRoomPing(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMultiRoomPing(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
|
|
@ -140,6 +142,7 @@ func TestMultiRoomPing(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMultiRoomPing_Separate(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
|
|
@ -175,6 +178,7 @@ func TestMultiRoomPing_Separate(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestMultiRoomPing_DeleteRoom(t *testing.T) {
|
||||
t.Parallel()
|
||||
logger := NewLoggerForTest(t)
|
||||
ctx := NewLoggerContext(t.Context(), logger)
|
||||
assert := assert.New(t)
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
)
|
||||
|
||||
func TestRoom_InCall(t *testing.T) {
|
||||
t.Parallel()
|
||||
type Testcase struct {
|
||||
Value any
|
||||
InCall bool
|
||||
|
|
@ -70,7 +71,7 @@ func TestRoom_InCall(t *testing.T) {
|
|||
} else {
|
||||
assert.False(t, ok, "%+v should not be valid", test.Value)
|
||||
}
|
||||
assert.EqualValues(t, test.InCall, inCall, "conversion failed for %+v", test.Value)
|
||||
assert.Equal(t, test.InCall, inCall, "conversion failed for %+v", test.Value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,11 +23,11 @@ package signaling
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoSuchRoomSession = fmt.Errorf("unknown room session id")
|
||||
ErrNoSuchRoomSession = errors.New("unknown room session id")
|
||||
)
|
||||
|
||||
type RoomSessions interface {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
)
|
||||
|
||||
func TestBuiltinRoomSessions(t *testing.T) {
|
||||
t.Parallel()
|
||||
sessions, err := NewBuiltinRoomSessions(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
)
|
||||
|
||||
func TestReverseSessionId(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
codec, err := NewSessionIdCodec([]byte("12345678901234567890123456789012"), []byte("09876543210987654321098765432109"))
|
||||
|
|
@ -127,6 +128,7 @@ func Benchmark_DecodePublicSessionId(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestPublicPrivate(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
require := require.New(t)
|
||||
sd := &SessionIdData{
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import (
|
|||
)
|
||||
|
||||
func TestSingleNotifierNoWaiter(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
// Notifications can be sent even if no waiter exists.
|
||||
|
|
@ -39,6 +40,7 @@ func TestSingleNotifierNoWaiter(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierSimple(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -59,6 +61,7 @@ func TestSingleNotifierSimple(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierMultiNotify(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
waiter := notifier.NewWaiter()
|
||||
|
|
@ -70,6 +73,7 @@ func TestSingleNotifierMultiNotify(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierWaitClosed(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
waiter := notifier.NewWaiter()
|
||||
|
|
@ -79,6 +83,7 @@ func TestSingleNotifierWaitClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierWaitClosedMulti(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
waiter1 := notifier.NewWaiter()
|
||||
|
|
@ -91,6 +96,7 @@ func TestSingleNotifierWaitClosedMulti(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierResetWillNotify(t *testing.T) {
|
||||
t.Parallel()
|
||||
var notifier SingleNotifier
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -111,6 +117,7 @@ func TestSingleNotifierResetWillNotify(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestSingleNotifierDuplicate(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
var notifier SingleNotifier
|
||||
var done sync.WaitGroup
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func assertCollectorChangeBy(t *testing.T, collector prometheus.Collector, delta
|
|||
t.Helper()
|
||||
|
||||
after := testutil.ToFloat64(collector)
|
||||
assert.EqualValues(t, delta, after-before, "failed for %s", desc)
|
||||
assert.InEpsilon(t, delta, after-before, 0.0001, "failed for %s", desc)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -71,24 +71,24 @@ func checkStatsValue(t *testing.T, collector prometheus.Collector, value float64
|
|||
pc := make([]uintptr, 10)
|
||||
n := runtime.Callers(2, pc)
|
||||
if n == 0 {
|
||||
assert.EqualValues(value, v, "failed for %s", desc)
|
||||
assert.InEpsilon(value, v, 0.0001, "failed for %s", desc)
|
||||
return
|
||||
}
|
||||
|
||||
pc = pc[:n]
|
||||
frames := runtime.CallersFrames(pc)
|
||||
stack := ""
|
||||
var stack strings.Builder
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
if !strings.Contains(frame.File, "nextcloud-spreed-signaling") {
|
||||
break
|
||||
}
|
||||
stack += fmt.Sprintf("%s:%d\n", frame.File, frame.Line)
|
||||
fmt.Fprintf(&stack, "%s:%d\n", frame.File, frame.Line)
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.EqualValues(value, v, "Unexpected value for %s at\n%s", desc, stack)
|
||||
assert.InEpsilon(value, v, 0.0001, "Unexpected value for %s at\n%s", desc, stack.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,9 +33,8 @@ func SynctestTest(t *testing.T, f func(t *testing.T)) {
|
|||
|
||||
synctest.Run(func() {
|
||||
t.Run("synctest", func(t *testing.T) {
|
||||
// synctest doesn't support t.Parallel
|
||||
t.Setenv("PARALLEL_CHECK", "1")
|
||||
|
||||
// synctest of Go 1.25 doesn't support "t.Parallel()" but we can't prevent
|
||||
// this here. Invalid calls will be detected when running with Go 1.25.
|
||||
f(t)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -23,10 +23,11 @@ package signaling
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/strukturag/nextcloud-spreed-signaling/internal"
|
||||
)
|
||||
|
||||
type testLogWriter struct {
|
||||
|
|
@ -45,30 +46,19 @@ func (w *testLogWriter) Write(b []byte) (int, error) {
|
|||
}
|
||||
|
||||
var (
|
||||
// +checklocks:testLoggersLock
|
||||
testLoggers = map[testing.TB]Logger{}
|
||||
testLoggersLock sync.Mutex
|
||||
testLoggers internal.TestStorage[Logger]
|
||||
)
|
||||
|
||||
func NewLoggerForTest(t testing.TB) Logger {
|
||||
t.Helper()
|
||||
testLoggersLock.Lock()
|
||||
defer testLoggersLock.Unlock()
|
||||
|
||||
logger, found := testLoggers[t]
|
||||
logger, found := testLoggers.Get(t)
|
||||
if !found {
|
||||
logger = log.New(&testLogWriter{
|
||||
t: t,
|
||||
}, fmt.Sprintf("%s: ", t.Name()), log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
|
||||
}, t.Name()+": ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
|
||||
|
||||
t.Cleanup(func() {
|
||||
testLoggersLock.Lock()
|
||||
defer testLoggersLock.Unlock()
|
||||
|
||||
delete(testLoggers, t)
|
||||
})
|
||||
|
||||
testLoggers[t] = logger
|
||||
testLoggers.Set(t, logger)
|
||||
}
|
||||
return logger
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ var (
|
|||
testBackendSecret = []byte("secret")
|
||||
testInternalSecret = []byte("internal-secret")
|
||||
|
||||
ErrNoMessageReceived = fmt.Errorf("no message was received by the server")
|
||||
ErrNoMessageReceived = errors.New("no message was received by the server")
|
||||
|
||||
testClientDialer = websocket.Dialer{
|
||||
WriteBufferPool: &sync.Pool{},
|
||||
|
|
@ -337,7 +337,7 @@ func (c *TestClient) WaitForClientRemoved(ctx context.Context) error {
|
|||
func (c *TestClient) WaitForSessionRemoved(ctx context.Context, sessionId PublicSessionId) error {
|
||||
data := c.hub.decodePublicSessionId(sessionId)
|
||||
if data == nil {
|
||||
return fmt.Errorf("Invalid session id passed")
|
||||
return errors.New("Invalid session id passed")
|
||||
}
|
||||
|
||||
c.hub.mu.Lock()
|
||||
|
|
@ -1110,7 +1110,7 @@ func checkMessageTransientInitial(t *testing.T, message *ServerMessage, data api
|
|||
assert := assert.New(t)
|
||||
return checkMessageType(t, message, "transient") &&
|
||||
assert.Equal("initial", message.TransientData.Type, "invalid message type in %+v", message) &&
|
||||
assert.EqualValues(data, message.TransientData.Data, "invalid initial data in %+v", message)
|
||||
assert.Equal(data, message.TransientData.Data, "invalid initial data in %+v", message)
|
||||
}
|
||||
|
||||
func checkMessageInCallAll(t *testing.T, message *ServerMessage, roomId string, inCall int) bool {
|
||||
|
|
|
|||
|
|
@ -150,49 +150,3 @@ func AssertEqualSerialized(t *testing.T, expected any, actual any, msgAndArgs ..
|
|||
|
||||
return assert.Equal(t, string(a), string(e), msgAndArgs...)
|
||||
}
|
||||
|
||||
type testStorage[T any] struct {
|
||||
mu sync.Mutex
|
||||
// +checklocks:mu
|
||||
entries map[string]T // +checklocksignore: Not supported yet, see https://github.com/google/gvisor/issues/11671
|
||||
}
|
||||
|
||||
func (s *testStorage[T]) cleanup(key string) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
delete(s.entries, key)
|
||||
if len(s.entries) == 0 {
|
||||
s.entries = nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s *testStorage[T]) Set(t *testing.T, value T) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
key := t.Name()
|
||||
if _, found := s.entries[key]; !found {
|
||||
t.Cleanup(func() {
|
||||
s.cleanup(key)
|
||||
})
|
||||
}
|
||||
|
||||
if s.entries == nil {
|
||||
s.entries = make(map[string]T)
|
||||
}
|
||||
s.entries[key] = value
|
||||
}
|
||||
|
||||
func (s *testStorage[T]) Get(t *testing.T) (T, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
key := t.Name()
|
||||
if value, found := s.entries[key]; found {
|
||||
return value, true
|
||||
}
|
||||
|
||||
var defaultValue T
|
||||
return defaultValue, false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ func expectDelay(t *testing.T, f func(), delay time.Duration) {
|
|||
}
|
||||
|
||||
func TestThrottler(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -101,6 +102,7 @@ func TestThrottler(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottlerIPv6(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -138,6 +140,7 @@ func TestThrottlerIPv6(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottler_Bruteforce(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -164,6 +167,7 @@ func TestThrottler_Bruteforce(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottler_Cleanup(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
throttler := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -220,6 +224,7 @@ func TestThrottler_Cleanup(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottler_ExpirePartial(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -252,6 +257,7 @@ func TestThrottler_ExpirePartial(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottler_ExpireAll(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
@ -284,6 +290,7 @@ func TestThrottler_ExpireAll(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrottler_Negative(t *testing.T) {
|
||||
t.Parallel()
|
||||
SynctestTest(t, func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
th := newMemoryThrottlerForTest(t)
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ func (t *TransientData) SetTTLChannel(ch chan<- struct{}) {
|
|||
}
|
||||
|
||||
func Test_TransientData(t *testing.T) {
|
||||
t.Parallel()
|
||||
assert := assert.New(t)
|
||||
data := NewTransientData()
|
||||
assert.False(data.Set("foo", nil))
|
||||
|
|
@ -119,6 +120,7 @@ func (l *MockTransientListener) Close() {
|
|||
}
|
||||
|
||||
func Test_TransientDataDeadlock(t *testing.T) {
|
||||
t.Parallel()
|
||||
data := NewTransientData()
|
||||
|
||||
listener := &MockTransientListener{
|
||||
|
|
@ -139,6 +141,7 @@ func Test_TransientDataDeadlock(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_TransientMessages(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
@ -313,6 +316,7 @@ func Test_TransientMessages(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_TransientSessionData(t *testing.T) {
|
||||
t.Parallel()
|
||||
for _, subtest := range clusteredTests {
|
||||
t.Run(subtest, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ func TestVirtualSession(t *testing.T) {
|
|||
if flagsMsg, ok := checkMessageParticipantFlags(t, msg4); ok {
|
||||
assert.Equal(roomId, flagsMsg.RoomId)
|
||||
assert.Equal(sessionId, flagsMsg.SessionId)
|
||||
assert.EqualValues(newFlags, flagsMsg.Flags)
|
||||
assert.Equal(newFlags, flagsMsg.Flags)
|
||||
}
|
||||
|
||||
// A new client will receive the initial flags of the virtual session.
|
||||
|
|
@ -162,7 +162,7 @@ func TestVirtualSession(t *testing.T) {
|
|||
|
||||
if assert.Equal(roomId, msg.Event.Flags.RoomId) &&
|
||||
assert.Equal(sessionId, msg.Event.Flags.SessionId) &&
|
||||
assert.EqualValues(newFlags, msg.Event.Flags.Flags) {
|
||||
assert.Equal(newFlags, msg.Event.Flags.Flags) {
|
||||
gotFlags = true
|
||||
break
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ func TestVirtualSessionActorInformation(t *testing.T) {
|
|||
if flagsMsg, ok := checkMessageParticipantFlags(t, msg4); ok {
|
||||
assert.Equal(roomId, flagsMsg.RoomId)
|
||||
assert.Equal(sessionId, flagsMsg.SessionId)
|
||||
assert.EqualValues(newFlags, flagsMsg.Flags)
|
||||
assert.Equal(newFlags, flagsMsg.Flags)
|
||||
}
|
||||
|
||||
// A new client will receive the initial flags of the virtual session.
|
||||
|
|
@ -349,7 +349,7 @@ func TestVirtualSessionActorInformation(t *testing.T) {
|
|||
|
||||
if assert.Equal(roomId, msg.Event.Flags.RoomId) &&
|
||||
assert.Equal(sessionId, msg.Event.Flags.SessionId) &&
|
||||
assert.EqualValues(newFlags, msg.Event.Flags.Flags) {
|
||||
assert.Equal(newFlags, msg.Event.Flags.Flags) {
|
||||
gotFlags = true
|
||||
break
|
||||
}
|
||||
|
|
@ -414,7 +414,7 @@ func checkHasEntryWithInCall(t *testing.T, message *RoomEventServerMessage, sess
|
|||
}
|
||||
|
||||
if value, found := api.GetStringMapEntry[float64](entry, "inCall"); !assert.True(found, "inCall not found or invalid in %+v", entry) ||
|
||||
!assert.EqualValues(value, inCall, "invalid inCall") {
|
||||
!assert.InDelta(value, inCall, 0.0001, "invalid inCall") {
|
||||
return false
|
||||
}
|
||||
found = true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue