oven-exporter/signed-policy/main_test.go

53 lines
1.0 KiB
Go
Raw Normal View History

// https://airensoft.gitbook.io/ovenmediaengine/access-control/signedpolicy
package signedPolicy
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPolicyEncode(t *testing.T) {
assert := assert.New(t)
p := Policy{
URLExpire: 1399721581,
}
assert.Equal("eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ", p.Encode())
}
func TestPolicySign(t *testing.T) {
assert := assert.New(t)
p := Policy{
URLExpire: 1399721581,
}
secretKey := "1kU^b6"
u, _ := url.Parse("ws://192.168.0.100:3333/app/stream")
assert.Equal("dvVdBpoxAeCPl94Kt5RoiqLI0YE", p.Sign(u, secretKey))
}
func TestPolicySignURL(t *testing.T) {
assert := assert.New(t)
p := Policy{
URLExpire: 1399721581,
}
secretKey := "1kU^b6"
u, _ := url.Parse("ws://192.168.0.100:3333/app/stream")
p.SignURL(u, secretKey)
// drop port -> is not part of example
u.Host = u.Hostname()
expected := "ws://192.168.0.100/app/stream?policy=eyJ1cmxfZXhwaXJlIjoxMzk5NzIxNTgxfQ&signature=dvVdBpoxAeCPl94Kt5RoiqLI0YE"
assert.Equal(expected, u.String())
}