File: saslprep_test.go

package info (click to toggle)
golang-github-xdg-go-stringprep 1.0.4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 308 kB
  • sloc: makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download | duplicates (2)
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)
				}
			}

		})
	}
}