-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfcgi_test.go
82 lines (65 loc) · 2.08 KB
/
fcgi_test.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fcgi_processor
import (
"github.com/flashmob/go-guerrilla/mail"
"net/url"
"strings"
"testing"
)
// change baseDir to location of your save.php and validate.php scripts
var baseDir string = "/vagrant/projects/golang/src/github.com/flashmob/fastcgi-processor/examples/"
// fcgiType is "unix" or "tcp"
var fcgiType string = "unix"
// fcgiAddr is a path to a unix socket descriptor, or IP address with tcp port eg. "127.0.0.1:8000"
var fcgiAddr string = "/var/run/php/php7.0-fpm.sock"
// Test GET method to validate recipient
// This test requires a functioning php-fpm daemon
func TestGet(t *testing.T) {
c := &fcgiConfig{
ScriptFileNameNameSave: baseDir + "/save.php",
ScriptFileNameNameValidate: baseDir + "validate.php",
ConnectionType: fcgiType,
ConnectionAddress: fcgiAddr,
}
f, err := newFastCGIProcessor(c)
if err != nil {
t.Error("could not newFastCGIPorcessor", err)
}
q := url.Values{}
q.Add("rcpt_to", "[email protected]")
result, err := f.get(c.ScriptFileNameNameValidate, q)
if strings.Index(string(result), "PASSED") != 0 {
t.Error("save did not return PASSED, it got:", string(result))
}
}
// Test email saving using POST
// This test requires a functioning php-fpm daemon
func TestPost(t *testing.T) {
c := &fcgiConfig{
ScriptFileNameNameSave: baseDir + "save.php",
ScriptFileNameNameValidate: baseDir + "validate.php",
ConnectionType: fcgiType,
ConnectionAddress: fcgiAddr,
}
f, err := newFastCGIProcessor(c)
if err != nil {
t.Error("could not newFastCGIProcessor", err)
}
q := url.Values{}
q.Add("rcpt_to", "[email protected]")
e := &mail.Envelope{
RemoteIP: "127.0.0.1",
QueuedId: "abc12345",
Helo: "helo.example.com",
MailFrom: mail.Address{"test", "example.com"},
TLS: true,
}
e.PushRcpt(mail.Address{"test", "example.com"})
e.Data.WriteString("Subject:Test\n\nThis is a test.")
result, err := f.postSave(e)
if err != nil {
t.Error("postSave error", err)
}
if strings.Index(string(result), "SAVED") != 0 {
t.Error("save did not return SAVED, it got:", string(result))
}
}