Files
core/encoding/token/token_test.go
Ingo Oppermann abfe4918b4 Loosen restrictions for IAM user names
The only restriction for an IAM username is that it cannot start with
a '$'. An username that contains a ':' must escape it with another ':'
for use in a token for RTMP or SRT.
2023-06-26 13:49:53 +02:00

42 lines
764 B
Go

package token
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestMarshal(t *testing.T) {
token := "xxx"
data := [][2]string{
{"", ""},
{"foo", "foo"},
{"foo:bar", "foo::bar"},
{"foo::bar", "foo::::bar"},
}
for _, d := range data {
encoded := Marshal(d[0], token)
require.Equal(t, d[1]+":"+token, encoded, d[1])
}
}
func TestUnmarshal(t *testing.T) {
data := [][3]string{
{"foo", "", "foo"},
{"fo::o", "", "fo::o"},
{"::foo", "", "::foo"},
{":xxx", "", "xxx"},
{"foo:xxx", "foo", "xxx"},
{"foo::bar:xxx", "foo:bar", "xxx"},
{"foo::::bar:xxx", "foo::bar", "xxx"},
}
for _, d := range data {
username, token := Unmarshal(d[0])
require.Equal(t, d[1], username, d[0])
require.Equal(t, d[2], token)
}
}