unified-push-xmpp/gateway/token_test.go

26 lines
464 B
Go
Raw Normal View History

2021-09-14 01:32:37 +02:00
package main
import (
"testing"
"github.com/stretchr/testify/assert"
"mellium.im/xmpp/jid"
)
func TestJWT(t *testing.T) {
assert := assert.New(t)
addr := "a@example.org"
token := "pushtoken"
secret := JWTSecret("CHANGEME")
jwt, err := secret.Generate(jid.MustParse(addr), token)
assert.NoError(err)
2021-09-14 20:22:49 +02:00
assert.NotEqual("", jwt)
2021-09-14 01:32:37 +02:00
2021-09-14 20:22:49 +02:00
jid, iToken, err := secret.Read(jwt)
2021-09-14 01:32:37 +02:00
assert.NoError(err)
assert.Equal(addr, jid.String())
2021-09-14 20:22:49 +02:00
assert.Equal(iToken, token)
2021-09-14 01:32:37 +02:00
}