aboutsummaryrefslogtreecommitdiffstats
path: root/syz-cluster/pkg/emailclient/smtp_sender_test.go
blob: 00b36588739c22f6162417a1af7c6f688db7f2fe (plain)
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
// Copyright 2025 syzkaller project authors. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.

package emailclient

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestRawEmail(t *testing.T) {
	tests := []struct {
		item   *Email
		id     string
		result string
	}{
		{
			item: &Email{
				To:        []string{"1@to.com", "2@to.com"},
				Cc:        []string{"1@cc.com", "2@cc.com"},
				InReplyTo: "<reply-to@domain>",
				Subject:   "subject",
				Body:      []byte("Email body"),
			},
			id: "<id@domain>",
			result: "From: name <a@b.com>\r\n" +
				"To: 1@to.com, 2@to.com\r\n" +
				"Cc: 1@cc.com, 2@cc.com\r\n" +
				"Subject: subject\r\n" +
				"In-Reply-To: <reply-to@domain>\r\n" +
				"Message-ID: <id@domain>\r\n" +
				"MIME-Version: 1.0\r\n" +
				"Content-Type: text/plain; charset=UTF-8\r\n" +
				"Content-Transfer-Encoding: 8bit\r\n\r\n" +
				"Email body",
		},
	}

	for i, test := range tests {
		t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
			ret := rawEmail(TestEmailConfig(), test.item, test.id)
			assert.Equal(t, test.result, string(ret))
		})
	}
}