@marcel91200 / caddy Mirror · read-only
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 11, 01:00 UTC

master
go 73 lines 2.9 KB
Raw
1 // Copyright 2015 Matthew Holt and The Caddy Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package caddyhttp
16
17 import (
18 "strings"
19 "testing"
20 )
21
22 // TestRandString_NotSameCaseExcludedChars is the regression test for the
23 // randString(sameCase=false) dictionary bug where excluded was still emitted
24 // despite being called out as a confusing character in the doc comment.
25 func TestRandString_NotSameCaseExcludedChars(t *testing.T) {
26 // A sample of 5000 characters makes a leaked excluded character extremely unlikely
27 // to go unnoticed: the dictionary is 55 characters, so the expected
28 // count for any single character would be ~90 if it were present.
29 s := randString(5000, false)
30 if strings.ContainsRune(s, 'l') {
31 t.Errorf("randString(n, sameCase=false) must not emit 'l'; got %q", s)
32 }
33 if strings.ContainsRune(s, 'I') {
34 t.Errorf("randString(n, sameCase=false) must not emit 'I'; got %q", s)
35 }
36 if strings.ContainsRune(s, 'O') {
37 t.Errorf("randString(n, sameCase=false) must not emit 'O'; got %q", s)
38 }
39 if strings.ContainsRune(s, 'S') {
40 t.Errorf("randString(n, sameCase=false) must not emit 'S'; got %q", s)
41 }
42 if strings.ContainsRune(s, '0') {
43 t.Errorf("randString(n, sameCase=false) must not emit '0'; got %q", s)
44 }
45 if strings.ContainsRune(s, '1') {
46 t.Errorf("randString(n, sameCase=false) must not emit '1'; got %q", s)
47 }
48 }
49
50 // TestRandString_SameCaseExcludedChars is the regression test for the
51 // randString(sameCase=true) dictionary bug where excluded was still emitted
52 // despite being called out as a confusing character in the doc comment.
53 func TestRandString_SameCaseExcludedChars(t *testing.T) {
54 // A sample of 5000 characters makes a leaked excluded character extremely unlikely
55 // to go unnoticed: the dictionary is 32 characters, so the expected
56 // count for any single character would be ~156 if it were present.
57 s := randString(5000, true)
58 if strings.ToLower(s) != s {
59 t.Errorf("randString(n, sameCase=true) must not emit uppercase letters; got %q", s)
60 }
61 if strings.ContainsRune(s, 'l') {
62 t.Errorf("randString(n, sameCase=true) must not emit 'l'; got %q", s)
63 }
64 if strings.ContainsRune(s, 'o') {
65 t.Errorf("randString(n, sameCase=true) must not emit 'o': got %q", s)
66 }
67 if strings.ContainsRune(s, '0') {
68 t.Errorf("randString(n, sameCase=true) must not emit '0'; got %q", s)
69 }
70 if strings.ContainsRune(s, '1') {
71 t.Errorf("randString(n, sameCase=true) must not emit '1'; got %q", s)
72 }
73 }