~samwhited/xmpp

xmpp/jid/fuzz_test.go -rw-r--r-- 725 bytes
1a8e804eSam Whited pubsub: make internal package public 4 hours 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
// Copyright 2020 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

//go:build gofuzzbeta
// +build gofuzzbeta

package jid_test

import (
	"testing"

	"mellium.im/xmpp/jid"
)

func FuzzParseJID(f *testing.F) {
	f.Add("@")
	f.Add("/")
	f.Add("xn--")
	f.Add("test@example.net")
	f.Fuzz(func(t *testing.T, j string) {
		parsed, err := jid.Parse(j)
		if err != nil {
			t.Skip()
		}
		s := parsed.String()
		parsed2, err := jid.Parse(s)
		if err != nil {
			t.Fatalf("failed to parse a JID that encodes successfully: %q", s)
		}
		if !parsed.Equal(parsed2) {
			t.Errorf("JID parsing/encoding is unstable: %q, %q", parsed, parsed2)
		}
	})
}