Files
mattermost/model/access_test.go
Harrison Healey fb6f2a123c PLT-5860 Updated copyright date (#6058)
* PLT-5860 Updated copyright date in about modal

* PLT-5860 Updated copyright notice in JSX files

* PLT-5860 Updated copyright notice in go files

* Fixed misc copyright dates

* Fixed component snapshots
2017-04-12 08:27:57 -04:00

98 lines
1.9 KiB
Go

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
package model
import (
"strings"
"testing"
)
func TestAccessJson(t *testing.T) {
a1 := AccessData{}
a1.ClientId = NewId()
a1.UserId = NewId()
a1.Token = NewId()
a1.RefreshToken = NewId()
json := a1.ToJson()
ra1 := AccessDataFromJson(strings.NewReader(json))
if a1.Token != ra1.Token {
t.Fatal("tokens didn't match")
}
}
func TestAccessIsValid(t *testing.T) {
ad := AccessData{}
if err := ad.IsValid(); err == nil {
t.Fatal()
}
ad.ClientId = NewRandomString(28)
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed Client Id")
}
ad.ClientId = ""
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed Client Id")
}
ad.ClientId = NewId()
if err := ad.IsValid(); err == nil {
t.Fatal()
}
ad.UserId = NewRandomString(28)
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed User Id")
}
ad.UserId = ""
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed User Id")
}
ad.UserId = NewId()
if err := ad.IsValid(); err == nil {
t.Fatal("should have failed")
}
ad.Token = NewRandomString(22)
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed Token")
}
ad.Token = NewId()
if err := ad.IsValid(); err == nil {
t.Fatal()
}
ad.RefreshToken = NewRandomString(28)
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed Refresh Token")
}
ad.RefreshToken = NewId()
if err := ad.IsValid(); err == nil {
t.Fatal()
}
ad.RedirectUri = ""
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed Redirect URI not set")
}
ad.RedirectUri = NewRandomString(28)
if err := ad.IsValid(); err == nil {
t.Fatal("Should have failed invalid URL")
}
ad.RedirectUri = "http://example.com"
if err := ad.IsValid(); err != nil {
t.Fatal(err)
}
}