loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at forgejo 77 lines 2.3 kB view raw
1// Copyright 2019 The Gitea Authors. All rights reserved. 2// SPDX-License-Identifier: MIT 3 4package password 5 6import ( 7 "testing" 8 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11) 12 13func TestComplexity_IsComplexEnough(t *testing.T) { 14 matchComplexityOnce.Do(func() {}) 15 16 testlist := []struct { 17 complexity []string 18 truevalues []string 19 falsevalues []string 20 }{ 21 {[]string{"off"}, []string{"1", "-", "a", "A", "ñ", "日本語"}, []string{}}, 22 {[]string{"lower"}, []string{"abc", "abc!"}, []string{"ABC", "123", "=!$", ""}}, 23 {[]string{"upper"}, []string{"ABC"}, []string{"abc", "123", "=!$", "abc!", ""}}, 24 {[]string{"digit"}, []string{"123"}, []string{"abc", "ABC", "=!$", "abc!", ""}}, 25 {[]string{"spec"}, []string{"=!$", "abc!"}, []string{"abc", "ABC", "123", ""}}, 26 {[]string{"off"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}, nil}, 27 {[]string{"lower", "spec"}, []string{"abc!"}, []string{"abc", "ABC", "123", "=!$", "abcABC123", ""}}, 28 {[]string{"lower", "upper", "digit"}, []string{"abcABC123"}, []string{"abc", "ABC", "123", "=!$", "abc!", ""}}, 29 {[]string{""}, []string{"abC=1", "abc!9D"}, []string{"ABC", "123", "=!$", ""}}, 30 } 31 32 for _, test := range testlist { 33 testComplextity(test.complexity) 34 for _, val := range test.truevalues { 35 assert.True(t, IsComplexEnough(val)) 36 } 37 for _, val := range test.falsevalues { 38 assert.False(t, IsComplexEnough(val)) 39 } 40 } 41 42 // Remove settings for other tests 43 testComplextity([]string{"off"}) 44} 45 46func TestComplexity_Generate(t *testing.T) { 47 matchComplexityOnce.Do(func() {}) 48 49 const maxCount = 50 50 const pwdLen = 50 51 52 test := func(t *testing.T, modes []string) { 53 testComplextity(modes) 54 for i := 0; i < maxCount; i++ { 55 pwd, err := Generate(pwdLen) 56 require.NoError(t, err) 57 assert.Len(t, pwd, pwdLen) 58 assert.True(t, IsComplexEnough(pwd), "Failed complexities with modes %+v for generated: %s", modes, pwd) 59 } 60 } 61 62 test(t, []string{"lower"}) 63 test(t, []string{"upper"}) 64 test(t, []string{"lower", "upper", "spec"}) 65 test(t, []string{"off"}) 66 test(t, []string{""}) 67 68 // Remove settings for other tests 69 testComplextity([]string{"off"}) 70} 71 72func testComplextity(values []string) { 73 // Cleanup previous values 74 validChars = "" 75 requiredList = make([]complexity, 0, len(values)) 76 setupComplexity(values) 77}