mail_smtp_xclient.t 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. ###############################################################################
  4. use warnings;
  5. use strict;
  6. use Test::More;
  7. use MIME::Base64;
  8. use Socket qw/ CRLF /;
  9. BEGIN { use FindBin; chdir($FindBin::Bin); }
  10. use lib 'lib';
  11. use Test::Nginx;
  12. use Test::Nginx::SMTP;
  13. ###############################################################################
  14. select STDERR; $| = 1;
  15. select STDOUT; $| = 1;
  16. local $SIG{PIPE} = 'IGNORE';
  17. my $t = Test::Nginx->new()->has(qw/mail smtp http rewrite/)->plan(6)
  18. ->run_daemon(\&Test::Nginx::SMTP::smtp_test_daemon)
  19. ->write_file_expand('nginx.conf', <<'EOF')->run();
  20. %%TEST_GLOBALS%%
  21. master_process off;
  22. daemon off;
  23. events {
  24. }
  25. mail {
  26. proxy_pass_error_message on;
  27. auth_http http://127.0.0.1:8080/mail/auth;
  28. xclient on;
  29. server {
  30. listen 127.0.0.1:8025;
  31. protocol smtp;
  32. smtp_auth login plain none;
  33. }
  34. }
  35. http {
  36. %%TEST_GLOBALS_HTTP%%
  37. server {
  38. listen 127.0.0.1:8080;
  39. server_name localhost;
  40. location = /mail/auth {
  41. add_header Auth-Status OK;
  42. add_header Auth-Server 127.0.0.1;
  43. add_header Auth-Port 8026;
  44. add_header Auth-Wait 1;
  45. return 204;
  46. }
  47. }
  48. }
  49. EOF
  50. ###############################################################################
  51. # When XCLIENT's HELO= argument isn't used, the following combinations may be
  52. # send to backend with xclient on:
  53. #
  54. # xclient
  55. # xclient, helo
  56. # xclient, ehlo
  57. # xclient, from, rcpt
  58. # xclient, helo, from, rcpt
  59. # xclient, ehlo, from, rcpt
  60. #
  61. # Test them in order.
  62. # xclient
  63. my $s = Test::Nginx::SMTP->new();
  64. $s->read();
  65. $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
  66. $s->authok('xclient');
  67. # xclient, helo
  68. $s = Test::Nginx::SMTP->new();
  69. $s->read();
  70. $s->send('HELO example.com');
  71. $s->read();
  72. $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
  73. $s->authok('xclient, helo');
  74. # xclient, ehlo
  75. $s = Test::Nginx::SMTP->new();
  76. $s->read();
  77. $s->send('EHLO example.com');
  78. $s->read();
  79. $s->send('AUTH PLAIN ' . encode_base64("\0test\@example.com\0secret", ''));
  80. $s->authok('xclient, ehlo');
  81. # xclient, from, rcpt
  82. $s = Test::Nginx::SMTP->new();
  83. $s->read();
  84. $s->send('MAIL FROM:<test@example.com>');
  85. $s->read();
  86. $s->send('RCPT TO:<test@example.com>');
  87. $s->ok('xclient, from');
  88. # xclient, helo, from, rcpt
  89. $s = Test::Nginx::SMTP->new();
  90. $s->read();
  91. $s->send('HELO example.com');
  92. $s->read();
  93. $s->send('MAIL FROM:<test@example.com>');
  94. $s->read();
  95. $s->send('RCPT TO:<test@example.com>');
  96. $s->ok('xclient, helo, from');
  97. # xclient, ehlo, from, rcpt
  98. $s = Test::Nginx::SMTP->new();
  99. $s->read();
  100. $s->send('EHLO example.com');
  101. $s->read();
  102. $s->send('MAIL FROM:<test@example.com>');
  103. $s->read();
  104. $s->send('RCPT TO:<test@example.com>');
  105. $s->ok('xclient, ehlo, from');
  106. ###############################################################################