💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 6413a02be962275e78f9c8db53… captured on 2023-04-19 at 23:33:19. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
0 package db
1
2 import (
3 "testing"
4 )
5
6 func TestPassword(t *testing.T) {
7
8 if isPasswordValid("") == nil {
9 t.Fatal("empty passwords are invalid")
10 }
11
12 if isPasswordValid("12345") == nil {
13 t.Fatalf("password shorter than %d are invalid",
14 passwordMinLen)
15 }
16
17 if isPasswordValid("1234567890abcdefghjklmnopqrstuvwx") == nil {
18 t.Fatalf("passwords longer than %d are invalid",
19 passwordMaxLen)
20 }
21
22 if isPasswordValid("123456") != nil {
23 t.Fatal("password should be valid")
24 }
25
26 hash, err := hashPassword("123456")
27 if err != nil {
28 t.Fatal(err)
29 }
30
31 b := checkPassword("123456", hash)
32 if !b {
33 t.Fatal("password should be valid")
34 }
35
36 b = checkPassword("1234567", hash)
37 if b {
38 t.Fatal("password should be invalid")
39 }
40 }
41
42 func TestUsername(t *testing.T) {
43
44 s := ""
45 if isRepoNameValid(s) == nil {
46 t.Fatal("empty usernames are invalid")
47 }
48
49 s = "0abc"
50 if isUsernameValid(s) == nil {
51 t.Fatal("name should start with a letter")
52 }
53
54 s = "iiiiiiiiiiiiiiiiiiiiiiiiI"
55 if isGroupNameValid(s) == nil {
56 t.Fatalf("name should contain less than %d characters",
57 maxNameLen)
58 }
59
60 s = "abc$"
61 if isUsernameValid(s) == nil || isGroupNameValid(s) == nil ||
62 isRepoNameValid(s) == nil {
63 t.Fatal("name should only contain letters and numbers")
64 }
65 n := "abc0"
66 s = "abc_0-"
67 if isUsernameValid(n) != nil || isGroupNameValid(s) != nil ||
68 isRepoNameValid(s) != nil {
69 t.Fatal("name should be valid")
70 }
71 }
72