guerrilla_test.go 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292
  1. // integration / smokeless
  2. // =======================
  3. // Tests are in a different package so we can test as a consumer of the guerrilla package
  4. // The following are integration / smokeless, that test the overall server.
  5. // (Please put unit tests to go in a different file)
  6. // How it works:
  7. // Server's log output is redirected to the testlog file which is then used by the tests to look for
  8. // expected behaviour.
  9. //
  10. // (self signed certs are also generated on each run)
  11. // server's responses from a connection are also used to check for expected behaviour
  12. // to run:
  13. // $ go test
  14. package test
  15. import (
  16. "encoding/json"
  17. "github.com/flashmob/go-guerrilla/mail/rfc5321"
  18. "testing"
  19. "time"
  20. "github.com/flashmob/go-guerrilla"
  21. "github.com/flashmob/go-guerrilla/backends"
  22. "github.com/flashmob/go-guerrilla/log"
  23. "bufio"
  24. "crypto/tls"
  25. "errors"
  26. "fmt"
  27. "io/ioutil"
  28. "net"
  29. "strings"
  30. "os"
  31. "github.com/flashmob/go-guerrilla/tests/testcert"
  32. )
  33. type TestConfig struct {
  34. guerrilla.AppConfig
  35. BackendConfig map[string]interface{} `json:"backend_config"`
  36. }
  37. var (
  38. // app config loaded here
  39. config *TestConfig
  40. app guerrilla.Guerrilla
  41. initErr error
  42. logger log.Logger
  43. )
  44. func init() {
  45. config = &TestConfig{}
  46. if err := json.Unmarshal([]byte(configJson), config); err != nil {
  47. initErr = errors.New("Could not Unmarshal config," + err.Error())
  48. } else {
  49. logger, _ = log.GetLogger(config.LogFile, "debug")
  50. initErr = setupCerts(config)
  51. if initErr != nil {
  52. return
  53. }
  54. backend, _ := getBackend(config.BackendConfig, logger)
  55. app, initErr = guerrilla.New(&config.AppConfig, backend, logger)
  56. }
  57. }
  58. // a configuration file with a dummy backend
  59. var configJson = `
  60. {
  61. "log_file" : "./testlog",
  62. "log_level" : "debug",
  63. "pid_file" : "go-guerrilla.pid",
  64. "allowed_hosts": ["spam4.me","grr.la"],
  65. "backend_config" :
  66. {
  67. "log_received_mails" : true
  68. },
  69. "servers" : [
  70. {
  71. "is_enabled" : true,
  72. "host_name":"mail.guerrillamail.com",
  73. "max_size": 100017,
  74. "timeout":160,
  75. "listen_interface":"127.0.0.1:2526",
  76. "max_clients": 2,
  77. "log_file" : "",
  78. "tls" : {
  79. "private_key_file":"/this/will/be/ignored/guerrillamail.com.key.pem",
  80. "public_key_file":"/this/will/be/ignored//guerrillamail.com.crt",
  81. "start_tls_on":true,
  82. "tls_always_on":false
  83. }
  84. },
  85. {
  86. "is_enabled" : true,
  87. "host_name":"mail.guerrillamail.com",
  88. "max_size":1000001,
  89. "timeout":180,
  90. "listen_interface":"127.0.0.1:4654",
  91. "max_clients":1,
  92. "log_file" : "",
  93. "tls" : {
  94. "private_key_file":"/this/will/be/ignored/guerrillamail.com.key.pem",
  95. "public_key_file":"/this/will/be/ignored/guerrillamail.com.crt",
  96. "start_tls_on":false,
  97. "tls_always_on":true
  98. }
  99. }
  100. ]
  101. }
  102. `
  103. func getBackend(backendConfig map[string]interface{}, l log.Logger) (backends.Backend, error) {
  104. b, err := backends.New(backendConfig, l)
  105. if err != nil {
  106. fmt.Println("backend init error", err)
  107. os.Exit(1)
  108. }
  109. return b, err
  110. }
  111. func setupCerts(c *TestConfig) error {
  112. for i := range c.Servers {
  113. err := testcert.GenerateCert(c.Servers[i].Hostname, "", 365*24*time.Hour, false, 2048, "P256", "./")
  114. if err != nil {
  115. return err
  116. }
  117. c.Servers[i].TLS.PrivateKeyFile = c.Servers[i].Hostname + ".key.pem"
  118. c.Servers[i].TLS.PublicKeyFile = c.Servers[i].Hostname + ".cert.pem"
  119. }
  120. return nil
  121. }
  122. func truncateIfExists(filename string) error {
  123. if _, err := os.Stat(filename); !os.IsNotExist(err) {
  124. return os.Truncate(filename, 0)
  125. }
  126. return nil
  127. }
  128. func deleteIfExists(filename string) error {
  129. if _, err := os.Stat(filename); !os.IsNotExist(err) {
  130. return os.Remove(filename)
  131. }
  132. return nil
  133. }
  134. func cleanTestArtifacts(t *testing.T) {
  135. if err := truncateIfExists("./testlog"); err != nil {
  136. t.Error("could not clean tests/testlog:", err)
  137. }
  138. letters := []byte{'A', 'B', 'C', 'D', 'E'}
  139. for _, l := range letters {
  140. if err := deleteIfExists("configJson" + string(l) + ".json"); err != nil {
  141. t.Error("could not delete configJson"+string(l)+".json:", err)
  142. }
  143. }
  144. if err := deleteIfExists("./go-guerrilla.pid"); err != nil {
  145. t.Error("could not delete ./guerrilla", err)
  146. }
  147. if err := deleteIfExists("./go-guerrilla2.pid"); err != nil {
  148. t.Error("could not delete ./go-guerrilla2.pid", err)
  149. }
  150. if err := deleteIfExists("./mail.guerrillamail.com.cert.pem"); err != nil {
  151. t.Error("could not delete ./mail.guerrillamail.com.cert.pem", err)
  152. }
  153. if err := deleteIfExists("./mail.guerrillamail.com.key.pem"); err != nil {
  154. t.Error("could not delete ./mail.guerrillamail.com.key.pem", err)
  155. }
  156. }
  157. // Testing start and stop of server
  158. func TestStart(t *testing.T) {
  159. if initErr != nil {
  160. t.Error(initErr)
  161. t.FailNow()
  162. }
  163. defer cleanTestArtifacts(t)
  164. if startErrors := app.Start(); startErrors != nil {
  165. t.Error(startErrors)
  166. t.FailNow()
  167. }
  168. time.Sleep(time.Second)
  169. app.Shutdown()
  170. if read, err := ioutil.ReadFile("./testlog"); err == nil {
  171. logOutput := string(read)
  172. if i := strings.Index(logOutput, "Listening on TCP 127.0.0.1:4654"); i < 0 {
  173. t.Error("Server did not listen on 127.0.0.1:4654")
  174. }
  175. if i := strings.Index(logOutput, "Listening on TCP 127.0.0.1:2526"); i < 0 {
  176. t.Error("Server did not listen on 127.0.0.1:2526")
  177. }
  178. if i := strings.Index(logOutput, "[127.0.0.1:4654] Waiting for a new client"); i < 0 {
  179. t.Error("Server did not wait on 127.0.0.1:4654")
  180. }
  181. if i := strings.Index(logOutput, "[127.0.0.1:2526] Waiting for a new client"); i < 0 {
  182. t.Error("Server did not wait on 127.0.0.1:2526")
  183. }
  184. if i := strings.Index(logOutput, "Server [127.0.0.1:4654] has stopped accepting new clients"); i < 0 {
  185. t.Error("Server did not stop on 127.0.0.1:4654")
  186. }
  187. if i := strings.Index(logOutput, "Server [127.0.0.1:2526] has stopped accepting new clients"); i < 0 {
  188. t.Error("Server did not stop on 127.0.0.1:2526")
  189. }
  190. if i := strings.Index(logOutput, "shutdown completed for [127.0.0.1:4654]"); i < 0 {
  191. t.Error("Server did not complete shutdown on 127.0.0.1:4654")
  192. }
  193. if i := strings.Index(logOutput, "shutdown completed for [127.0.0.1:2526]"); i < 0 {
  194. t.Error("Server did not complete shutdown on 127.0.0.1:2526")
  195. }
  196. if i := strings.Index(logOutput, "shutting down pool [127.0.0.1:4654]"); i < 0 {
  197. t.Error("Server did not shutdown pool on 127.0.0.1:4654")
  198. }
  199. if i := strings.Index(logOutput, "shutting down pool [127.0.0.1:2526]"); i < 0 {
  200. t.Error("Server did not shutdown pool on 127.0.0.1:2526")
  201. }
  202. if i := strings.Index(logOutput, "Backend shutdown completed"); i < 0 {
  203. t.Error("Backend didn't shut down")
  204. }
  205. }
  206. }
  207. // Simple smoke-test to see if the server can listen & issues a greeting on connect
  208. func TestGreeting(t *testing.T) {
  209. if initErr != nil {
  210. t.Error(initErr)
  211. t.FailNow()
  212. }
  213. defer cleanTestArtifacts(t)
  214. if startErrors := app.Start(); startErrors == nil {
  215. // 1. plaintext connection
  216. conn, err := net.Dial("tcp", config.Servers[0].ListenInterface)
  217. if err != nil {
  218. // handle error
  219. t.Error("Cannot dial server", config.Servers[0].ListenInterface)
  220. }
  221. if err := conn.SetReadDeadline(time.Now().Add(time.Millisecond * 500)); err != nil {
  222. t.Error(err)
  223. }
  224. greeting, err := bufio.NewReader(conn).ReadString('\n')
  225. if err != nil {
  226. t.Error(err)
  227. t.FailNow()
  228. } else {
  229. expected := "220 mail.guerrillamail.com SMTP Guerrilla"
  230. if strings.Index(greeting, expected) != 0 {
  231. t.Error("Server[1] did not have the expected greeting prefix", expected)
  232. }
  233. }
  234. _ = conn.Close()
  235. // 2. tls connection
  236. // roots, err := x509.SystemCertPool()
  237. conn, err = tls.Dial("tcp", config.Servers[1].ListenInterface, &tls.Config{
  238. InsecureSkipVerify: true,
  239. ServerName: "127.0.0.1",
  240. })
  241. if err != nil {
  242. // handle error
  243. t.Error(err, "Cannot dial server (TLS)", config.Servers[1].ListenInterface)
  244. t.FailNow()
  245. }
  246. if err := conn.SetReadDeadline(time.Now().Add(time.Millisecond * 500)); err != nil {
  247. t.Error(err)
  248. }
  249. greeting, err = bufio.NewReader(conn).ReadString('\n')
  250. if err != nil {
  251. t.Error(err)
  252. t.FailNow()
  253. } else {
  254. expected := "220 mail.guerrillamail.com SMTP Guerrilla"
  255. if strings.Index(greeting, expected) != 0 {
  256. t.Error("Server[2] (TLS) did not have the expected greeting prefix", expected)
  257. }
  258. }
  259. _ = conn.Close()
  260. } else {
  261. fmt.Println("Nope", startErrors)
  262. if startErrors := app.Start(); startErrors != nil {
  263. t.Error(startErrors)
  264. t.FailNow()
  265. }
  266. }
  267. app.Shutdown()
  268. if read, err := ioutil.ReadFile("./testlog"); err == nil {
  269. logOutput := string(read)
  270. if i := strings.Index(logOutput, "Handle client [127.0.0.1"); i < 0 {
  271. t.Error("Server did not handle any clients")
  272. }
  273. }
  274. }
  275. // start up a server, connect a client, greet, then shutdown, then client sends a command
  276. // expecting: 421 Server is shutting down. Please try again later. Sayonara!
  277. // server should close connection after that
  278. func TestShutDown(t *testing.T) {
  279. if initErr != nil {
  280. t.Error(initErr)
  281. t.FailNow()
  282. }
  283. defer cleanTestArtifacts(t)
  284. if startErrors := app.Start(); startErrors == nil {
  285. conn, bufin, err := Connect(config.Servers[0], 20)
  286. if err != nil {
  287. // handle error
  288. t.Error(err.Error(), config.Servers[0].ListenInterface)
  289. t.FailNow()
  290. } else {
  291. // client goes into command state
  292. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  293. t.Error("Hello command failed", err.Error())
  294. }
  295. // do a shutdown while the client is connected & in client state
  296. go app.Shutdown()
  297. time.Sleep(time.Millisecond * 150) // let server to Shutdown
  298. // issue a command while shutting down
  299. response, err := Command(conn, bufin, "HELP")
  300. if err != nil {
  301. t.Error("Help command failed", err.Error())
  302. }
  303. expected := "421 4.3.0 Server is shutting down. Please try again later. Sayonara!"
  304. if strings.Index(response, expected) != 0 {
  305. t.Error("Server did not shut down with", expected, ", it said:"+response)
  306. }
  307. time.Sleep(time.Millisecond * 250) // let server to close
  308. }
  309. _ = conn.Close()
  310. } else {
  311. if startErrors := app.Start(); startErrors != nil {
  312. t.Error(startErrors)
  313. app.Shutdown()
  314. t.FailNow()
  315. }
  316. }
  317. // assuming server has shutdown by now
  318. if read, err := ioutil.ReadFile("./testlog"); err == nil {
  319. logOutput := string(read)
  320. // fmt.Println(logOutput)
  321. if i := strings.Index(logOutput, "Handle client [127.0.0.1"); i < 0 {
  322. t.Error("Server did not handle any clients")
  323. }
  324. }
  325. }
  326. // add more than 100 recipients, it should fail at 101
  327. func TestRFC2821LimitRecipients(t *testing.T) {
  328. if initErr != nil {
  329. t.Error(initErr)
  330. t.FailNow()
  331. }
  332. defer cleanTestArtifacts(t)
  333. if startErrors := app.Start(); startErrors == nil {
  334. conn, bufin, err := Connect(config.Servers[0], 20)
  335. if err != nil {
  336. // handle error
  337. t.Error(err.Error(), config.Servers[0].ListenInterface)
  338. t.FailNow()
  339. } else {
  340. // client goes into command state
  341. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  342. t.Error("Hello command failed", err.Error())
  343. }
  344. for i := 0; i < 101; i++ {
  345. //fmt.Println(fmt.Sprintf("RCPT TO:test%[email protected]", i))
  346. if _, err := Command(conn, bufin, fmt.Sprintf("RCPT TO:<test%[email protected]>", i)); err != nil {
  347. t.Error("RCPT TO", err.Error())
  348. break
  349. }
  350. }
  351. response, err := Command(conn, bufin, "RCPT TO:<[email protected]>")
  352. if err != nil {
  353. t.Error("rcpt command failed", err.Error())
  354. }
  355. expected := "452 4.5.3 Too many recipients"
  356. if strings.Index(response, expected) != 0 {
  357. t.Error("Server did not respond with", expected, ", it said:"+response)
  358. }
  359. }
  360. _ = conn.Close()
  361. app.Shutdown()
  362. } else {
  363. if startErrors := app.Start(); startErrors != nil {
  364. t.Error(startErrors)
  365. app.Shutdown()
  366. t.FailNow()
  367. }
  368. }
  369. }
  370. // RCPT TO & MAIL FROM with 64 chars in local part, it should fail at 65
  371. func TestRFC2832LimitLocalPart(t *testing.T) {
  372. if initErr != nil {
  373. t.Error(initErr)
  374. t.FailNow()
  375. }
  376. defer cleanTestArtifacts(t)
  377. if startErrors := app.Start(); startErrors == nil {
  378. conn, bufin, err := Connect(config.Servers[0], 20)
  379. if err != nil {
  380. // handle error
  381. t.Error(err.Error(), config.Servers[0].ListenInterface)
  382. t.FailNow()
  383. } else {
  384. // client goes into command state
  385. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  386. t.Error("Hello command failed", err.Error())
  387. }
  388. // repeat > 64 characters in local part
  389. response, err := Command(conn, bufin, fmt.Sprintf("RCPT TO:<%[email protected]>", strings.Repeat("a", rfc5321.LimitLocalPart+1)))
  390. if err != nil {
  391. t.Error("rcpt command failed", err.Error())
  392. }
  393. expected := "550 5.5.4 Local part too long"
  394. if strings.Index(response, expected) != 0 {
  395. t.Error("Server did not respond with", expected, ", it said:"+response)
  396. }
  397. // what about if it's exactly 64?
  398. // repeat > 64 characters in local part
  399. response, err = Command(conn, bufin, fmt.Sprintf("RCPT TO:<%[email protected]>", strings.Repeat("a", rfc5321.LimitLocalPart-1)))
  400. if err != nil {
  401. t.Error("rcpt command failed", err.Error())
  402. }
  403. expected = "250 2.1.5 OK"
  404. if strings.Index(response, expected) != 0 {
  405. t.Error("Server did not respond with", expected, ", it said:"+response)
  406. }
  407. }
  408. _ = conn.Close()
  409. app.Shutdown()
  410. } else {
  411. if startErrors := app.Start(); startErrors != nil {
  412. t.Error(startErrors)
  413. app.Shutdown()
  414. t.FailNow()
  415. }
  416. }
  417. }
  418. //RFC2821LimitPath fail if path > 256 but different error if below
  419. func TestRFC2821LimitPath(t *testing.T) {
  420. if initErr != nil {
  421. t.Error(initErr)
  422. t.FailNow()
  423. }
  424. if startErrors := app.Start(); startErrors == nil {
  425. conn, bufin, err := Connect(config.Servers[0], 20)
  426. if err != nil {
  427. // handle error
  428. t.Error(err.Error(), config.Servers[0].ListenInterface)
  429. t.FailNow()
  430. } else {
  431. // client goes into command state
  432. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  433. t.Error("Hello command failed", err.Error())
  434. }
  435. // repeat > 256 characters in local part
  436. response, err := Command(conn, bufin, fmt.Sprintf("RCPT TO:<%[email protected]>", strings.Repeat("a", 257-7)))
  437. if err != nil {
  438. t.Error("rcpt command failed", err.Error())
  439. }
  440. expected := "550 5.5.4 Path too long"
  441. if strings.Index(response, expected) != 0 {
  442. t.Error("Server did not respond with", expected, ", it said:"+response)
  443. }
  444. // what about if it's exactly 256?
  445. response, err = Command(conn, bufin,
  446. fmt.Sprintf("RCPT TO:<%s@%s.la>", strings.Repeat("a", 64), strings.Repeat("b", 186)))
  447. if err != nil {
  448. t.Error("rcpt command failed", err.Error())
  449. }
  450. expected = "454 4.1.1 Error: Relay access denied"
  451. if strings.Index(response, expected) != 0 {
  452. t.Error("Server did not respond with", expected, ", it said:"+response)
  453. }
  454. }
  455. _ = conn.Close()
  456. app.Shutdown()
  457. } else {
  458. if startErrors := app.Start(); startErrors != nil {
  459. t.Error(startErrors)
  460. app.Shutdown()
  461. t.FailNow()
  462. }
  463. }
  464. }
  465. // RFC2821LimitDomain 501 Domain cannot exceed 255 characters
  466. func TestRFC2821LimitDomain(t *testing.T) {
  467. if initErr != nil {
  468. t.Error(initErr)
  469. t.FailNow()
  470. }
  471. defer cleanTestArtifacts(t)
  472. if startErrors := app.Start(); startErrors == nil {
  473. conn, bufin, err := Connect(config.Servers[0], 20)
  474. if err != nil {
  475. // handle error
  476. t.Error(err.Error(), config.Servers[0].ListenInterface)
  477. t.FailNow()
  478. } else {
  479. // client goes into command state
  480. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  481. t.Error("Hello command failed", err.Error())
  482. }
  483. // repeat > 64 characters in local part
  484. response, err := Command(conn, bufin, fmt.Sprintf("RCPT TO:<a@%s.l>", strings.Repeat("a", 255-2)))
  485. if err != nil {
  486. t.Error("command failed", err.Error())
  487. }
  488. expected := "550 5.5.4 Path too long"
  489. if strings.Index(response, expected) != 0 {
  490. t.Error("Server did not respond with", expected, ", it said:"+response)
  491. }
  492. // what about if it's exactly 255?
  493. response, err = Command(conn, bufin,
  494. fmt.Sprintf("RCPT TO:<a@%s.la>", strings.Repeat("b", 255-6)))
  495. if err != nil {
  496. t.Error("command failed", err.Error())
  497. }
  498. expected = "454 4.1.1 Error: Relay access denied"
  499. if strings.Index(response, expected) != 0 {
  500. t.Error("Server did not respond with", expected, ", it said:"+response)
  501. }
  502. }
  503. _ = conn.Close()
  504. app.Shutdown()
  505. } else {
  506. if startErrors := app.Start(); startErrors != nil {
  507. t.Error(startErrors)
  508. app.Shutdown()
  509. t.FailNow()
  510. }
  511. }
  512. }
  513. // Test several different inputs to MAIL FROM command
  514. func TestMailFromCmd(t *testing.T) {
  515. if initErr != nil {
  516. t.Error(initErr)
  517. t.FailNow()
  518. }
  519. defer cleanTestArtifacts(t)
  520. if startErrors := app.Start(); startErrors == nil {
  521. conn, bufin, err := Connect(config.Servers[0], 20)
  522. if err != nil {
  523. // handle error
  524. t.Error(err.Error(), config.Servers[0].ListenInterface)
  525. t.FailNow()
  526. } else {
  527. // client goes into command state
  528. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  529. t.Error("Hello command failed", err.Error())
  530. }
  531. // Basic valid address
  532. response, err := Command(conn, bufin, "MAIL FROM:<[email protected]>")
  533. if err != nil {
  534. t.Error("command failed", err.Error())
  535. }
  536. expected := "250 2.1.0 OK"
  537. if strings.Index(response, expected) != 0 {
  538. t.Error("Server did not respond with", expected, ", it said:"+response)
  539. }
  540. // Reset
  541. response, err = Command(conn, bufin, "RSET")
  542. if err != nil {
  543. t.Error("command failed", err.Error())
  544. }
  545. expected = "250 2.1.0 OK"
  546. if strings.Index(response, expected) != 0 {
  547. t.Error("Server did not respond with", expected, ", it said:"+response)
  548. }
  549. // Basic valid address (RfC)
  550. response, err = Command(conn, bufin, "MAIL FROM:<[email protected]>")
  551. if err != nil {
  552. t.Error("command failed", err.Error())
  553. }
  554. expected = "250 2.1.0 OK"
  555. if strings.Index(response, expected) != 0 {
  556. t.Error("Server did not respond with", expected, ", it said:"+response)
  557. }
  558. // Reset
  559. response, err = Command(conn, bufin, "RSET")
  560. if err != nil {
  561. t.Error("command failed", err.Error())
  562. }
  563. expected = "250 2.1.0 OK"
  564. if strings.Index(response, expected) != 0 {
  565. t.Error("Server did not respond with", expected, ", it said:"+response)
  566. }
  567. // Bounce
  568. response, err = Command(conn, bufin, "MAIL FROM:<>")
  569. if err != nil {
  570. t.Error("command failed", err.Error())
  571. }
  572. expected = "250 2.1.0 OK"
  573. if strings.Index(response, expected) != 0 {
  574. t.Error("Server did not respond with", expected, ", it said:"+response)
  575. }
  576. // Reset
  577. response, err = Command(conn, bufin, "RSET")
  578. if err != nil {
  579. t.Error("command failed", err.Error())
  580. }
  581. expected = "250 2.1.0 OK"
  582. if strings.Index(response, expected) != 0 {
  583. t.Error("Server did not respond with", expected, ", it said:"+response)
  584. }
  585. // No mail from content
  586. response, err = Command(conn, bufin, "MAIL FROM:")
  587. if err != nil {
  588. t.Error("command failed", err.Error())
  589. }
  590. expected = "501 5.5.4 Invalid address"
  591. if strings.Index(response, expected) != 0 {
  592. t.Error("Server did not respond with", expected, ", it said:"+response)
  593. }
  594. // Reset
  595. response, err = Command(conn, bufin, "RSET")
  596. if err != nil {
  597. t.Error("command failed", err.Error())
  598. }
  599. expected = "250 2.1.0 OK"
  600. if strings.Index(response, expected) != 0 {
  601. t.Error("Server did not respond with", expected, ", it said:"+response)
  602. }
  603. // Short mail from content
  604. response, err = Command(conn, bufin, "MAIL FROM:<")
  605. if err != nil {
  606. t.Error("command failed", err.Error())
  607. }
  608. expected = "501 5.5.4 Invalid address"
  609. if strings.Index(response, expected) != 0 {
  610. t.Error("Server did not respond with", expected, ", it said:"+response)
  611. }
  612. // Reset
  613. response, err = Command(conn, bufin, "RSET")
  614. if err != nil {
  615. t.Error("command failed", err.Error())
  616. }
  617. expected = "250 2.1.0 OK"
  618. if strings.Index(response, expected) != 0 {
  619. t.Error("Server did not respond with", expected, ", it said:"+response)
  620. }
  621. // Short mail from content 2
  622. response, err = Command(conn, bufin, "MAIL FROM:x")
  623. if err != nil {
  624. t.Error("command failed", err.Error())
  625. }
  626. expected = "501 5.5.4 Invalid address"
  627. if strings.Index(response, expected) != 0 {
  628. t.Error("Server did not respond with", expected, ", it said:"+response)
  629. }
  630. // Reset
  631. response, err = Command(conn, bufin, "RSET")
  632. if err != nil {
  633. t.Error("command failed", err.Error())
  634. }
  635. expected = "250 2.1.0 OK"
  636. if strings.Index(response, expected) != 0 {
  637. t.Error("Server did not respond with", expected, ", it said:"+response)
  638. }
  639. // What?
  640. response, err = Command(conn, bufin, "MAIL FROM:<<>>")
  641. if err != nil {
  642. t.Error("command failed", err.Error())
  643. }
  644. expected = "501 5.5.4 Invalid address"
  645. if strings.Index(response, expected) != 0 {
  646. t.Error("Server did not respond with", expected, ", it said:"+response)
  647. }
  648. // Reset
  649. response, err = Command(conn, bufin, "RSET")
  650. if err != nil {
  651. t.Error("command failed", err.Error())
  652. }
  653. expected = "250 2.1.0 OK"
  654. if strings.Index(response, expected) != 0 {
  655. t.Error("Server did not respond with", expected, ", it said:"+response)
  656. }
  657. // Invalid address?
  658. response, err = Command(conn, bufin, "MAIL FROM:<justatest>")
  659. if err != nil {
  660. t.Error("command failed", err.Error())
  661. }
  662. expected = "501 5.5.4 Invalid address"
  663. if strings.Index(response, expected) != 0 {
  664. t.Error("Server did not respond with", expected, ", it said:"+response)
  665. }
  666. // Reset
  667. response, err = Command(conn, bufin, "RSET")
  668. if err != nil {
  669. t.Error("command failed", err.Error())
  670. }
  671. expected = "250 2.1.0 OK"
  672. if strings.Index(response, expected) != 0 {
  673. t.Error("Server did not respond with", expected, ", it said:"+response)
  674. }
  675. /*
  676. // todo SMTPUTF8 not implemented for now,
  677. response, err = Command(conn, bufin, "MAIL FROM:<anö[email protected]>")
  678. if err != nil {
  679. t.Error("command failed", err.Error())
  680. }
  681. expected = "250 2.1.0 OK"
  682. if strings.Index(response, expected) != 0 {
  683. t.Error("Server did not respond with", expected, ", it said:"+response)
  684. }
  685. */
  686. // Reset
  687. response, err = Command(conn, bufin, "RSET")
  688. if err != nil {
  689. t.Error("command failed", err.Error())
  690. }
  691. expected = "250 2.1.0 OK"
  692. if strings.Index(response, expected) != 0 {
  693. t.Error("Server did not respond with", expected, ", it said:"+response)
  694. }
  695. // 8BITMIME (RfC 6152)
  696. response, err = Command(conn, bufin, "MAIL FROM:<[email protected]> BODY=8BITMIME")
  697. if err != nil {
  698. t.Error("command failed", err.Error())
  699. }
  700. expected = "250 2.1.0 OK"
  701. if strings.Index(response, expected) != 0 {
  702. t.Error("Server did not respond with", expected, ", it said:"+response)
  703. }
  704. // Reset
  705. response, err = Command(conn, bufin, "RSET")
  706. if err != nil {
  707. t.Error("command failed", err.Error())
  708. }
  709. expected = "250 2.1.0 OK"
  710. if strings.Index(response, expected) != 0 {
  711. t.Error("Server did not respond with", expected, ", it said:"+response)
  712. }
  713. // 8BITMIME (RfC 6152) Bounce
  714. response, err = Command(conn, bufin, "MAIL FROM:<> BODY=8BITMIME")
  715. if err != nil {
  716. t.Error("command failed", err.Error())
  717. }
  718. expected = "250 2.1.0 OK"
  719. if strings.Index(response, expected) != 0 {
  720. t.Error("Server did not respond with", expected, ", it said:"+response)
  721. }
  722. // Reset
  723. response, err = Command(conn, bufin, "RSET")
  724. if err != nil {
  725. t.Error("command failed", err.Error())
  726. }
  727. expected = "250 2.1.0 OK"
  728. if strings.Index(response, expected) != 0 {
  729. t.Error("Server did not respond with", expected, ", it said:"+response)
  730. }
  731. }
  732. _ = conn.Close()
  733. app.Shutdown()
  734. } else {
  735. if startErrors := app.Start(); startErrors != nil {
  736. t.Error(startErrors)
  737. app.Shutdown()
  738. t.FailNow()
  739. }
  740. }
  741. }
  742. // Test several different inputs to MAIL FROM command
  743. func TestHeloEhlo(t *testing.T) {
  744. if initErr != nil {
  745. t.Error(initErr)
  746. t.FailNow()
  747. }
  748. defer cleanTestArtifacts(t)
  749. if startErrors := app.Start(); startErrors == nil {
  750. conn, bufin, err := Connect(config.Servers[0], 20)
  751. hostname := config.Servers[0].Hostname
  752. if err != nil {
  753. // handle error
  754. t.Error(err.Error(), config.Servers[0].ListenInterface)
  755. t.FailNow()
  756. } else {
  757. // Test HELO
  758. response, err := Command(conn, bufin, "HELO localtester")
  759. if err != nil {
  760. t.Error("command failed", err.Error())
  761. }
  762. expected := fmt.Sprintf("250 %s Hello", hostname)
  763. if strings.Index(response, expected) != 0 {
  764. t.Error("Server did not respond with", expected, ", it said:"+response)
  765. }
  766. // Reset
  767. response, err = Command(conn, bufin, "RSET")
  768. if err != nil {
  769. t.Error("command failed", err.Error())
  770. }
  771. expected = "250 2.1.0 OK"
  772. if strings.Index(response, expected) != 0 {
  773. t.Error("Server did not respond with", expected, ", it said:"+response)
  774. }
  775. // Test EHLO
  776. // This is tricky as it is a multiline response
  777. var fullresp string
  778. response, err = Command(conn, bufin, "EHLO localtester")
  779. fullresp = fullresp + response
  780. if err != nil {
  781. t.Error("command failed", err.Error())
  782. }
  783. for err == nil {
  784. response, err = bufin.ReadString('\n')
  785. fullresp = fullresp + response
  786. if strings.HasPrefix(response, "250 ") { // Last response has a whitespace and no "-"
  787. break // bail
  788. }
  789. }
  790. expected = fmt.Sprintf("250-%s Hello\r\n250-SIZE 100017\r\n250-PIPELINING\r\n250-STARTTLS\r\n250-ENHANCEDSTATUSCODES\r\n250 HELP\r\n", hostname)
  791. if fullresp != expected {
  792. t.Error("Server did not respond with [" + expected + "], it said [" + fullresp + "]")
  793. }
  794. // be kind, QUIT. And we are sure that bufin does not contain fragments from the EHLO command.
  795. response, err = Command(conn, bufin, "QUIT")
  796. if err != nil {
  797. t.Error("command failed", err.Error())
  798. }
  799. expected = "221 2.0.0 Bye"
  800. if strings.Index(response, expected) != 0 {
  801. t.Error("Server did not respond with", expected, ", it said:"+response)
  802. }
  803. }
  804. _ = conn.Close()
  805. app.Shutdown()
  806. } else {
  807. if startErrors := app.Start(); startErrors != nil {
  808. t.Error(startErrors)
  809. app.Shutdown()
  810. t.FailNow()
  811. }
  812. }
  813. }
  814. // It should error when MAIL FROM was given twice
  815. func TestNestedMailCmd(t *testing.T) {
  816. if initErr != nil {
  817. t.Error(initErr)
  818. t.FailNow()
  819. }
  820. defer cleanTestArtifacts(t)
  821. if startErrors := app.Start(); startErrors == nil {
  822. conn, bufin, err := Connect(config.Servers[0], 20)
  823. if err != nil {
  824. // handle error
  825. t.Error(err.Error(), config.Servers[0].ListenInterface)
  826. t.FailNow()
  827. } else {
  828. // client goes into command state
  829. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  830. t.Error("Hello command failed", err.Error())
  831. }
  832. // repeat > 64 characters in local part
  833. response, err := Command(conn, bufin, "MAIL FROM:<[email protected]>")
  834. if err != nil {
  835. t.Error("command failed", err.Error())
  836. }
  837. response, err = Command(conn, bufin, "MAIL FROM:<[email protected]>")
  838. if err != nil {
  839. t.Error("command failed", err.Error())
  840. }
  841. expected := "503 5.5.1 Error: nested MAIL command"
  842. if strings.Index(response, expected) != 0 {
  843. t.Error("Server did not respond with", expected, ", it said:"+response)
  844. }
  845. // Plot twist: if you EHLO , it should allow MAIL FROM again
  846. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  847. t.Error("Hello command failed", err.Error())
  848. }
  849. response, err = Command(conn, bufin, "MAIL FROM:<[email protected]>")
  850. if err != nil {
  851. t.Error("command failed", err.Error())
  852. }
  853. expected = "250 2.1.0 OK"
  854. if strings.Index(response, expected) != 0 {
  855. t.Error("Server did not respond with", expected, ", it said:"+response)
  856. }
  857. // Plot twist: if you RSET , it should allow MAIL FROM again
  858. response, err = Command(conn, bufin, "RSET")
  859. if err != nil {
  860. t.Error("command failed", err.Error())
  861. }
  862. expected = "250 2.1.0 OK"
  863. if strings.Index(response, expected) != 0 {
  864. t.Error("Server did not respond with", expected, ", it said:"+response)
  865. }
  866. response, err = Command(conn, bufin, "MAIL FROM:<[email protected]>")
  867. if err != nil {
  868. t.Error("command failed", err.Error())
  869. }
  870. expected = "250 2.1.0 OK"
  871. if strings.Index(response, expected) != 0 {
  872. t.Error("Server did not respond with", expected, ", it said:"+response)
  873. }
  874. }
  875. _ = conn.Close()
  876. app.Shutdown()
  877. } else {
  878. if startErrors := app.Start(); startErrors != nil {
  879. t.Error(startErrors)
  880. app.Shutdown()
  881. t.FailNow()
  882. }
  883. }
  884. }
  885. // It should error on a very long command line, exceeding CommandLineMaxLength 1024
  886. func TestCommandLineMaxLength(t *testing.T) {
  887. if initErr != nil {
  888. t.Error(initErr)
  889. t.FailNow()
  890. }
  891. defer cleanTestArtifacts(t)
  892. if startErrors := app.Start(); startErrors == nil {
  893. conn, bufin, err := Connect(config.Servers[0], 20)
  894. if err != nil {
  895. // handle error
  896. t.Error(err.Error(), config.Servers[0].ListenInterface)
  897. t.FailNow()
  898. } else {
  899. // client goes into command state
  900. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  901. t.Error("Hello command failed", err.Error())
  902. }
  903. // repeat > 1024 characters
  904. response, err := Command(conn, bufin, strings.Repeat("s", guerrilla.CommandLineMaxLength+1))
  905. if err != nil {
  906. t.Error("command failed", err.Error())
  907. }
  908. expected := "554 5.5.1 Line too long"
  909. if strings.Index(response, expected) != 0 {
  910. t.Error("Server did not respond with", expected, ", it said:"+response)
  911. }
  912. }
  913. _ = conn.Close()
  914. app.Shutdown()
  915. } else {
  916. if startErrors := app.Start(); startErrors != nil {
  917. t.Error(startErrors)
  918. app.Shutdown()
  919. t.FailNow()
  920. }
  921. }
  922. }
  923. // It should error on a very long message, exceeding servers config value
  924. func TestDataMaxLength(t *testing.T) {
  925. if initErr != nil {
  926. t.Error(initErr)
  927. t.FailNow()
  928. }
  929. defer cleanTestArtifacts(t)
  930. if startErrors := app.Start(); startErrors == nil {
  931. conn, bufin, err := Connect(config.Servers[0], 20)
  932. if err != nil {
  933. // handle error
  934. t.Error(err.Error(), config.Servers[0].ListenInterface)
  935. t.FailNow()
  936. } else {
  937. // client goes into command state
  938. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  939. t.Error("Hello command failed", err.Error())
  940. }
  941. response, err := Command(conn, bufin, "MAIL FROM:[email protected]")
  942. if err != nil {
  943. t.Error("command failed", err.Error())
  944. }
  945. //fmt.Println(response)
  946. response, err = Command(conn, bufin, "RCPT TO:<[email protected]>")
  947. if err != nil {
  948. t.Error("command failed", err.Error())
  949. }
  950. //fmt.Println(response)
  951. response, err = Command(conn, bufin, "DATA")
  952. if err != nil {
  953. t.Error("command failed", err.Error())
  954. }
  955. response, err = Command(
  956. conn,
  957. bufin,
  958. fmt.Sprintf("Subject:test\r\n\r\nHello %s\r\n.\r\n",
  959. strings.Repeat("n", int(config.Servers[0].MaxSize-20))))
  960. //expected := "500 Line too long"
  961. expected := "451 4.3.0 Error: maximum DATA size exceeded"
  962. if strings.Index(response, expected) != 0 {
  963. t.Error("Server did not respond with", expected, ", it said:"+response)
  964. }
  965. }
  966. _ = conn.Close()
  967. app.Shutdown()
  968. } else {
  969. if startErrors := app.Start(); startErrors != nil {
  970. t.Error(startErrors)
  971. app.Shutdown()
  972. t.FailNow()
  973. }
  974. }
  975. }
  976. func TestDataCommand(t *testing.T) {
  977. if initErr != nil {
  978. t.Error(initErr)
  979. t.FailNow()
  980. }
  981. defer cleanTestArtifacts(t)
  982. testHeader :=
  983. "Subject: =?Shift_JIS?B?W4NYg06DRYNGg0GBRYNHg2qDYoNOg1ggg0GDSoNFg5ODZ12DQYNKg0WDk4Nn?=\r\n" +
  984. "\t=?Shift_JIS?B?k2+YXoqul7mCzIKokm2C54K5?=\r\n"
  985. email :=
  986. "Delivered-To: [email protected]\r\n" +
  987. "\tReceived: from mail.guerrillamail.com (mail.guerrillamail.com [104.218.55.28:44246])\r\n" +
  988. "\tby grr.la with SMTP id [email protected];\r\n" +
  989. "\tWed, 18 Jan 2017 15:43:29 +0000\r\n" +
  990. "Received: by 192.99.19.220 with HTTP; Wed, 18 Jan 2017 15:43:29 +0000\r\n" +
  991. "MIME-Version: 1.0\r\n" +
  992. "Message-ID: <[email protected]>\r\n" +
  993. "Date: Wed, 18 Jan 2017 15:43:29 +0000\r\n" +
  994. "To: \"[email protected]\" <[email protected]>\r\n" +
  995. "From: <[email protected]>\r\n" +
  996. "Subject: test\r\n" +
  997. "X-Originating-IP: [60.241.160.150]\r\n" +
  998. "Content-Type: text/plain; charset=\"utf-8\"\r\n" +
  999. "Content-Transfer-Encoding: quoted-printable\r\n" +
  1000. "X-Domain-Signer: PHP mailDomainSigner 0.2-20110415 <http://code.google.com/p/php-mail-domain-signer/>\r\n" +
  1001. "DKIM-Signature: v=1; a=rsa-sha256; s=highgrade; d=guerrillamail.com; l=182;\r\n" +
  1002. "\tt=1484754209; c=relaxed/relaxed; h=to:from:subject;\r\n" +
  1003. "\tbh=GHSgjHpBp5QjNn9tzfug681+RcWMOUgpwAuTzppM5wY=;\r\n" +
  1004. "\tb=R7FxWgACnT+pKXqEg15qgzH4ywMFRx5pDlIFCnSt1BfwmLvZPZK7oOLrbiRoGGR2OJnSfyCxeASH\r\n" +
  1005. "\t019LNeLB/B8o+fMRX87m/tBpqIZ2vgXdT9rUCIbSDJnYoCHXakGcF+zGtTE3SEksMbeJQ76aGj6M\r\n" +
  1006. "\tG80p76IT2Xu3iDJLYYWxcAeX+7z4M/bbYNeqxMQcXYZp1wNYlSlHahL6RDUYdcqikDqKoXmzMNVd\r\n" +
  1007. "\tDr0EbH9iiu1DQtfUDzVE5LLus1yn36WU/2KJvEak45gJvm9s9J+Xrcb882CaYkxlAbgQDz1KeQLf\r\n" +
  1008. "\teUyNspyAabkh2yTg7kOvNZSOJtbMSQS6/GMxsg==\r\n" +
  1009. "\r\n" +
  1010. "test=0A.mooo=0A..mooo=0Atest=0A.=0A=0A=0A=0A=0A=0A----=0ASent using Guerril=\r\n" +
  1011. "lamail.com=0ABlock or report abuse: https://www.guerrillamail.com//abuse/?a=\r\n" +
  1012. "=3DVURnES0HUaZbhA8%3D=0A\r\n.\r\n"
  1013. if startErrors := app.Start(); startErrors == nil {
  1014. conn, bufin, err := Connect(config.Servers[0], 20)
  1015. if err != nil {
  1016. // handle error
  1017. t.Error(err.Error(), config.Servers[0].ListenInterface)
  1018. t.FailNow()
  1019. } else {
  1020. // client goes into command state
  1021. if _, err := Command(conn, bufin, "HELO localtester"); err != nil {
  1022. t.Error("Hello command failed", err.Error())
  1023. }
  1024. response, err := Command(conn, bufin, "MAIL FROM:<[email protected]>")
  1025. if err != nil {
  1026. t.Error("command failed", err.Error())
  1027. }
  1028. //fmt.Println(response)
  1029. response, err = Command(conn, bufin, "RCPT TO:<[email protected]>")
  1030. if err != nil {
  1031. t.Error("command failed", err.Error())
  1032. }
  1033. //fmt.Println(response)
  1034. response, err = Command(conn, bufin, "DATA")
  1035. if err != nil {
  1036. t.Error("command failed", err.Error())
  1037. }
  1038. /*
  1039. response, err = Command(
  1040. conn,
  1041. bufin,
  1042. testHeader+"\r\nHello World\r\n.\r\n")
  1043. */
  1044. _ = testHeader
  1045. response, err = Command(
  1046. conn,
  1047. bufin,
  1048. email+"\r\n.\r\n")
  1049. //expected := "500 Line too long"
  1050. expected := "250 2.0.0 OK: queued as "
  1051. if strings.Index(response, expected) != 0 {
  1052. t.Error("Server did not respond with", expected, ", it said:"+response, err)
  1053. }
  1054. }
  1055. _ = conn.Close()
  1056. app.Shutdown()
  1057. } else {
  1058. if startErrors := app.Start(); startErrors != nil {
  1059. t.Error(startErrors)
  1060. app.Shutdown()
  1061. t.FailNow()
  1062. }
  1063. }
  1064. }
  1065. // Fuzzer crashed the server by submitting "DATA\r\n" as the first command
  1066. func TestFuzz86f25b86b09897aed8f6c2aa5b5ee1557358a6de(t *testing.T) {
  1067. if initErr != nil {
  1068. t.Error(initErr)
  1069. t.FailNow()
  1070. }
  1071. defer cleanTestArtifacts(t)
  1072. if startErrors := app.Start(); startErrors == nil {
  1073. conn, bufin, err := Connect(config.Servers[0], 20)
  1074. if err != nil {
  1075. // handle error
  1076. t.Error(err.Error(), config.Servers[0].ListenInterface)
  1077. t.FailNow()
  1078. } else {
  1079. response, err := Command(
  1080. conn,
  1081. bufin,
  1082. "DATA\r\n")
  1083. expected := "503 5.5.1 Error: No recipients"
  1084. if strings.Index(response, expected) != 0 {
  1085. t.Error("Server did not respond with", expected, ", it said:"+response, err)
  1086. }
  1087. }
  1088. _ = conn.Close()
  1089. app.Shutdown()
  1090. } else {
  1091. if startErrors := app.Start(); startErrors != nil {
  1092. t.Error(startErrors)
  1093. app.Shutdown()
  1094. t.FailNow()
  1095. }
  1096. }
  1097. }
  1098. // Appears to hang the fuzz test, but not server.
  1099. func TestFuzz21c56f89989d19c3bbbd81b288b2dae9e6dd2150(t *testing.T) {
  1100. if initErr != nil {
  1101. t.Error(initErr)
  1102. t.FailNow()
  1103. }
  1104. defer cleanTestArtifacts(t)
  1105. str := "X_\r\nMAIL FROM:<u\xfd\xfdrU" +
  1106. "\x10c22695140\xfd727235530" +
  1107. " Walter Sobchak\x1a\tDon" +
  1108. "ny, x_6_, Donnyre " +
  1109. "\t\t outof89 !om>\r\nMAI" +
  1110. "L\t\t \t\tFROM:<C4o\xfd\xfdr@e" +
  1111. "xample.c22695140\xfd727" +
  1112. "235530 Walter Sobcha" +
  1113. "k: Donny, you>re out" +
  1114. " of your element!om>" +
  1115. "\r\nMAIL RCPT TO:t@IRS" +
  1116. "ETRCPTIRSETRCP:<\x00\xfd\xfdr" +
  1117. "@example 7A924_F__4_" +
  1118. "c22695140\xfd-061.0x30C" +
  1119. "8bC87fE4d3 Walter MA" +
  1120. "IL Donny, youiq__n_l" +
  1121. "wR8qs_0RBcw_0hIY_pS_" +
  1122. "___x9_E0___sL598_G82" +
  1123. "_6 out your elemen" +
  1124. "t!>\r\nX _9KB___X_p:<o" +
  1125. "ut\xfd\xfdr@example9gTnr2N" +
  1126. "__Vl_T7U_AqfU_dPfJ_0" +
  1127. "HIqKK0037f6W_KGM_y_Z" +
  1128. "_9_96_w_815Q572py2_9" +
  1129. "F\xfd727235530Walter\tSo" +
  1130. "bchakRSET MAIL from:" +
  1131. " : cows eat\t\t grass" +
  1132. " , _S___46_PbG03_iW'" +
  1133. "__v5L2_2L_J61u_38J55" +
  1134. "_PpwQ_Fs_7L_3p7S_t__" +
  1135. "g9XP48T_9HY_EDl_c_C3" +
  1136. "3_3b708EreT_OR out 9" +
  1137. "9_pUY4 \t\t\t \x05om>\r" +
  1138. "\n FROM<u\xfd\xfdr@example." +
  1139. "<\xfd-05110602 Walter S" +
  1140. "obchak: Donny, \t\t w" +
  1141. "50TI__m_5EsC___n_l_d" +
  1142. "__57GP9G02_32n_FR_xw" +
  1143. "_2_103___rnED5PGIKN7" +
  1144. "BBs3VIuNV_514qDBp_Gs" +
  1145. "_qj4\tre out all cows" +
  1146. " eatof your element\x03" +
  1147. "om>\r\n_2 FROM:<u\x10\xfdr@e" +
  1148. "xample.oQ_VLq909_E_5" +
  1149. "AQ7_4_\xfd1935012674150" +
  1150. "6773818422493001838." +
  1151. "-010\tWalter\tSobchak:" +
  1152. " Donny, youyouteIz2y" +
  1153. "__Z2q5_qoA're Q6MP2_" +
  1154. "CT_z70____0c0nU7_83d" +
  1155. "4jn_eFD7h_9MbPjr_s_L" +
  1156. "9_X23G_7 of _kU_L9Yz" +
  1157. "_K52345QVa902H1__Hj_" +
  1158. "Nl_PP2tW2ODi0_V80F15" +
  1159. "_i65i_V5uSQdiG eleme" +
  1160. "nt!om>\r\n"
  1161. if startErrors := app.Start(); startErrors == nil {
  1162. conn, bufin, err := Connect(config.Servers[0], 20)
  1163. if err != nil {
  1164. // handle error
  1165. t.Error(err.Error(), config.Servers[0].ListenInterface)
  1166. t.FailNow()
  1167. } else {
  1168. response, err := Command(
  1169. conn,
  1170. bufin,
  1171. str)
  1172. expected := "554 5.5.1 Unrecognized command"
  1173. if strings.Index(response, expected) != 0 {
  1174. t.Error("Server did not respond with", expected, ", it said:"+response, err)
  1175. }
  1176. }
  1177. _ = conn.Close()
  1178. app.Shutdown()
  1179. } else {
  1180. if startErrors := app.Start(); startErrors != nil {
  1181. t.Error(startErrors)
  1182. app.Shutdown()
  1183. t.FailNow()
  1184. }
  1185. }
  1186. }