summaryrefslogtreecommitdiffstats
path: root/model/password_recovery_test.go
blob: d64f430fcb24f0797f3f5fb34f08fbced0e1d648 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.

package model

import (
	"strings"
	"testing"
)

func TestPasswordRecoveryIsValid(t *testing.T) {
	// Valid example.
	p := PasswordRecovery{
		UserId:   NewId(),
		Code:     strings.Repeat("a", 128),
		CreateAt: GetMillis(),
	}

	if err := p.IsValid(); err != nil {
		t.Fatal(err)
	}

	// Various invalid ones.
	p.UserId = "abc"
	if err := p.IsValid(); err == nil {
		t.Fatal("Should have failed validation")
	}

	p.UserId = NewId()
	p.Code = "abc"
	if err := p.IsValid(); err == nil {
		t.Fatal("Should have failed validation")
	}

	p.Code = strings.Repeat("a", 128)
	p.CreateAt = 0
	if err := p.IsValid(); err == nil {
		t.Fatal("Should have failed validation")
	}
}

func TestPasswordRecoveryPreSave(t *testing.T) {
	p := PasswordRecovery{
		UserId: NewId(),
	}

	// Check it's valid after running PreSave
	p.PreSave()

	if err := p.IsValid(); err != nil {
		t.Fatal(err)
	}
}