github.com/keys-pub/mattermost-server@v4.10.10+incompatible/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  
    11  func TestOAuthAppJson(t *testing.T) {
    12  	a1 := OAuthApp{}
    13  	a1.Id = NewId()
    14  	a1.Name = "TestOAuthApp" + NewId()
    15  	a1.CallbackUrls = []string{"https://nowhere.com"}
    16  	a1.Homepage = "https://nowhere.com"
    17  	a1.IconURL = "https://nowhere.com/icon_image.png"
    18  	a1.ClientSecret = NewId()
    19  
    20  	json := a1.ToJson()
    21  	ra1 := OAuthAppFromJson(strings.NewReader(json))
    22  
    23  	if a1.Id != ra1.Id {
    24  		t.Fatal("ids did not match")
    25  	}
    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  	if err := app.IsValid(); err == nil {
    56  		t.Fatal()
    57  	}
    58  
    59  	app.Id = NewId()
    60  	if err := app.IsValid(); err == nil {
    61  		t.Fatal()
    62  	}
    63  
    64  	app.CreateAt = 1
    65  	if err := app.IsValid(); err == nil {
    66  		t.Fatal()
    67  	}
    68  
    69  	app.UpdateAt = 1
    70  	if err := app.IsValid(); err == nil {
    71  		t.Fatal()
    72  	}
    73  
    74  	app.CreatorId = NewId()
    75  	if err := app.IsValid(); err == nil {
    76  		t.Fatal()
    77  	}
    78  
    79  	app.ClientSecret = NewId()
    80  	if err := app.IsValid(); err == nil {
    81  		t.Fatal()
    82  	}
    83  
    84  	app.Name = "TestOAuthApp"
    85  	if err := app.IsValid(); err == nil {
    86  		t.Fatal()
    87  	}
    88  
    89  	app.CallbackUrls = []string{"https://nowhere.com"}
    90  	if err := app.IsValid(); err == nil {
    91  		t.Fatal()
    92  	}
    93  
    94  	app.Homepage = "https://nowhere.com"
    95  	if err := app.IsValid(); err != nil {
    96  		t.Fatal()
    97  	}
    98  
    99  	app.IconURL = "https://nowhere.com/icon_image.png"
   100  	if err := app.IsValid(); err != nil {
   101  		t.Fatal()
   102  	}
   103  }