guerrilla_test.go 36 KB

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