mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00

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.
42 lines
764 B
Go
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)
|
|
}
|
|
}
|