github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/oauth_test.go (about)

     1  // Copyright (c) 2015-present Mattermost, 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  	require.Equal(t, a1.Id, ra1.Id, "ids did not match")
    26  }
    27  
    28  func TestOAuthAppPreSave(t *testing.T) {
    29  	a1 := OAuthApp{}
    30  	a1.Id = NewId()
    31  	a1.Name = "TestOAuthApp" + NewId()
    32  	a1.CallbackUrls = []string{"https://nowhere.com"}
    33  	a1.Homepage = "https://nowhere.com"
    34  	a1.IconURL = "https://nowhere.com/icon_image.png"
    35  	a1.ClientSecret = NewId()
    36  	a1.PreSave()
    37  	a1.Etag()
    38  	a1.Sanitize()
    39  }
    40  
    41  func TestOAuthAppPreUpdate(t *testing.T) {
    42  	a1 := OAuthApp{}
    43  	a1.Id = NewId()
    44  	a1.Name = "TestOAuthApp" + NewId()
    45  	a1.CallbackUrls = []string{"https://nowhere.com"}
    46  	a1.Homepage = "https://nowhere.com"
    47  	a1.IconURL = "https://nowhere.com/icon_image.png"
    48  	a1.ClientSecret = NewId()
    49  	a1.PreUpdate()
    50  }
    51  
    52  func TestOAuthAppIsValid(t *testing.T) {
    53  	app := OAuthApp{}
    54  
    55  	require.NotNil(t, app.IsValid())
    56  
    57  	app.Id = NewId()
    58  	require.NotNil(t, app.IsValid())
    59  
    60  	app.CreateAt = 1
    61  	require.NotNil(t, app.IsValid())
    62  
    63  	app.UpdateAt = 1
    64  	require.NotNil(t, app.IsValid())
    65  
    66  	app.CreatorId = NewId()
    67  	require.NotNil(t, app.IsValid())
    68  
    69  	app.ClientSecret = NewId()
    70  	require.NotNil(t, app.IsValid())
    71  
    72  	app.Name = "TestOAuthApp"
    73  	require.NotNil(t, app.IsValid())
    74  
    75  	app.CallbackUrls = []string{"https://nowhere.com"}
    76  	require.NotNil(t, app.IsValid())
    77  
    78  	app.Homepage = "https://nowhere.com"
    79  	require.Nil(t, app.IsValid())
    80  
    81  	app.IconURL = "https://nowhere.com/icon_image.png"
    82  	require.Nil(t, app.IsValid())
    83  }