~samwhited/xmpp

ref: 8fb8d7def0c62a960ae1a0d95fa49646f303aedd xmpp/jid/safejid_test.go -rw-r--r-- 944 bytes
8fb8d7deSam Whited Make Bare() part of the JID interface 5 years ago
                                                                                
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
// Copyright 2015 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

package jid

import (
	"testing"
)

// SafeJID's cannot contain invalid UTF8 in the localpart.
func TestNewInvalidUtf8Localpart(t *testing.T) {
	invalid := string([]byte{0xff, 0xfe, 0xfd})
	_, err := SafeFromString(invalid + "@example.com/resourcepart")
	if err == nil {
		t.FailNow()
	}
}

// SafeJID's cannot contain invalid UTF8 in the domainpart.
func TestNewInvalidUtf8Domainpart(t *testing.T) {
	invalid := string([]byte{0xff, 0xfe, 0xfd})
	_, err := SafeFromString("example@" + invalid + "/resourcepart")
	if err == nil {
		t.FailNow()
	}
}

// SafeJID's cannot contain invalid UTF8 in the resourcepart.
func TestNewInvalidUtf8Resourcepart(t *testing.T) {
	invalid := string([]byte{0xff, 0xfe, 0xfd})
	_, err := SafeFromString("example@example.com/" + invalid)
	if err == nil {
		t.FailNow()
	}
}