guerrilla_test.go 37 KB

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