-
Notifications
You must be signed in to change notification settings - Fork 2
/
saslprep_test.go
56 lines (52 loc) · 1.3 KB
/
saslprep_test.go
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
package stringprep
import (
"reflect"
"strconv"
"testing"
)
func TestSASLprep(t *testing.T) {
saslTests := []struct {
label string
in string
out string
err error
}{
{label: "soft hyphen", in: "I\u00ADX", out: "IX", err: nil},
{label: "non ASCII space", in: "I\u2000X", out: "I X", err: nil},
{label: "no transform", in: "user", out: "user", err: nil},
{label: "case preserve", in: "USER", out: "USER", err: nil},
{label: "8859-1 to NFKC", in: "\u00AA", out: "a", err: nil},
{label: "NFKC", in: "\u2168", out: "IX", err: nil},
{
label: "prohibited",
in: "\u0007",
out: "",
err: Error{Msg: errProhibited, Rune: '\u0007'},
},
{
label: "bidi not ok",
in: "\u0627\u0031",
out: "",
err: Error{Msg: errLastRune, Rune: '\u0031'},
},
}
for _, c := range saslTests {
t.Run(c.label, func(t *testing.T) {
got, err := SASLprep.Prepare(c.in)
t.Logf("err is '%v'", err)
if c.err == nil {
if got != c.out {
t.Errorf("input '%s': got '%s', expected '%s'",
strconv.QuoteToASCII(c.in),
strconv.QuoteToASCII(got),
strconv.QuoteToASCII(c.out))
}
} else {
if !reflect.DeepEqual(err, c.err) {
t.Errorf("input '%s': got error '%v', expected '%v'",
strconv.QuoteToASCII(c.in), err, c.err)
}
}
})
}
}