~samwhited/xmpp

ref: 63e21c13d6c7046cf7ee155cf55acfddf38b6c8e xmpp/jid/safejid_test.go -rw-r--r-- 1.0 KiB
63e21c13Sam Whited Add compile time regression tests 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
37
38
39
// 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"
)

// Compile time check ot make sure that SafeJID is a JID
var _ JID = (*SafeJID)(nil)

// 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()
	}
}