-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypt_test.go
More file actions
64 lines (59 loc) · 1.39 KB
/
crypt_test.go
File metadata and controls
64 lines (59 loc) · 1.39 KB
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
54
55
56
57
58
59
60
61
62
63
64
package crypt
import (
"io/ioutil"
"strings"
"testing"
)
func TestCrypt(t *testing.T) {
type args struct {
password string
salt string
}
tests := []struct {
name string
args args
want string
wantErr bool
}{
{"case 1", args{"nutmeg", "Mi"}, "MiqkFWCm1fNJI", false},
{"case 2", args{"ellen1", "ri"}, "ri79kNd7V6.Sk", false},
{"case 3", args{"Sharon", "./"}, "./UY9Q7TvYJDg", false},
{"case 4", args{"norahs", "am"}, "amfIADT2iqjA.", false},
{"case 5", args{"norash", "7a"}, "7aWAMMtfbjEJo", false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Crypt(tt.args.password, tt.args.salt)
if (err != nil) != tt.wantErr {
t.Errorf("Crypt() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Crypt() = %v, want %v", got, tt.want)
}
})
}
}
func TestCrypt2(t *testing.T) {
bytesRead, _ := ioutil.ReadFile("resources/passwords.txt")
file_content := string(bytesRead)
lines := strings.Split(file_content, "\n")
count := 0
for _, line := range lines {
if strings.TrimSpace(line) == "" {
continue
}
parts := strings.Split(line, " ")
password := parts[0]
salt := parts[1][:2]
hash, _ := Crypt(password, salt)
if hash != parts[1] {
t.Errorf("Crypt() = %v, want %v", hash, parts[1])
} else {
count++
}
}
if count < len(lines)-1 {
t.Errorf("In correct count")
}
}