github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/model/oauth_test.go (about)

     1  // Copyright (c) 2015-present Xenia, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestOAuthAppJson(t *testing.T) {
    14  	a1 := OAuthApp{}
    15  	a1.Id = NewId()
    16  	a1.Name = "TestOAuthApp" + NewId()
    17  	a1.CallbackUrls = []string{"https://nowhere.com"}
    18  	a1.Homepage = "https://nowhere.com"
    19  	a1.IconURL = "https://nowhere.com/icon_image.png"
    20  	a1.ClientSecret = NewId()
    21  
    22  	json := a1.ToJson()
    23  	ra1 := OAuthAppFromJson(strings.NewReader(json))
    24  
    25  	if a1.Id != ra1.Id {
    26  		t.Fatal("ids did not match")
    27  	}
    28  }
    29  
    30  func TestOAuthAppPreSave(t *testing.T) {
    31  	a1 := OAuthApp{}
    32  	a1.Id = NewId()
    33  	a1.Name = "TestOAuthApp" + NewId()
    34  	a1.CallbackUrls = []string{"https://nowhere.com"}
    35  	a1.Homepage = "https://nowhere.com"
    36  	a1.IconURL = "https://nowhere.com/icon_image.png"
    37  	a1.ClientSecret = NewId()
    38  	a1.PreSave()
    39  	a1.Etag()
    40  	a1.Sanitize()
    41  }
    42  
    43  func TestOAuthAppPreUpdate(t *testing.T) {
    44  	a1 := OAuthApp{}
    45  	a1.Id = NewId()
    46  	a1.Name = "TestOAuthApp" + NewId()
    47  	a1.CallbackUrls = []string{"https://nowhere.com"}
    48  	a1.Homepage = "https://nowhere.com"
    49  	a1.IconURL = "https://nowhere.com/icon_image.png"
    50  	a1.ClientSecret = NewId()
    51  	a1.PreUpdate()
    52  }
    53  
    54  func TestOAuthAppIsValid(t *testing.T) {
    55  	app := OAuthApp{}
    56  
    57  	require.NotNil(t, app.IsValid())
    58  
    59  	app.Id = NewId()
    60  	require.NotNil(t, app.IsValid())
    61  
    62  	app.CreateAt = 1
    63  	require.NotNil(t, app.IsValid())
    64  
    65  	app.UpdateAt = 1
    66  	require.NotNil(t, app.IsValid())
    67  
    68  	app.CreatorId = NewId()
    69  	require.NotNil(t, app.IsValid())
    70  
    71  	app.ClientSecret = NewId()
    72  	require.NotNil(t, app.IsValid())
    73  
    74  	app.Name = "TestOAuthApp"
    75  	require.NotNil(t, app.IsValid())
    76  
    77  	app.CallbackUrls = []string{"https://nowhere.com"}
    78  	require.NotNil(t, app.IsValid())
    79  
    80  	app.Homepage = "https://nowhere.com"
    81  	require.Nil(t, app.IsValid())
    82  
    83  	app.IconURL = "https://nowhere.com/icon_image.png"
    84  	require.Nil(t, app.IsValid())
    85  }