guerrilla_test.go 36 KB

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