dav.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #!/usr/bin/perl
  2. # (C) Maxim Dounin
  3. # Tests for nginx dav module.
  4. ###############################################################################
  5. use warnings;
  6. use strict;
  7. use Test::More;
  8. BEGIN { use FindBin; chdir($FindBin::Bin); }
  9. use lib 'lib';
  10. use Test::Nginx;
  11. ###############################################################################
  12. select STDERR; $| = 1;
  13. select STDOUT; $| = 1;
  14. my $t = Test::Nginx->new()->has(qw/http dav/)->plan(13);
  15. $t->write_file_expand('nginx.conf', <<'EOF');
  16. %%TEST_GLOBALS%%
  17. master_process off;
  18. daemon off;
  19. events {
  20. }
  21. http {
  22. %%TEST_GLOBALS_HTTP%%
  23. server {
  24. listen 127.0.0.1:8080;
  25. server_name localhost;
  26. location / {
  27. dav_methods PUT DELETE MKCOL COPY MOVE;
  28. }
  29. }
  30. }
  31. EOF
  32. $t->run();
  33. ###############################################################################
  34. my $r;
  35. $r = http(<<EOF . '0123456789');
  36. PUT /file HTTP/1.1
  37. Host: localhost
  38. Connection: close
  39. Content-Length: 10
  40. EOF
  41. like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'put file');
  42. is(-s $t->testdir() . '/file', 10, 'put file size');
  43. $r = http(<<EOF);
  44. PUT /file HTTP/1.1
  45. Host: localhost
  46. Connection: close
  47. Content-Length: 0
  48. EOF
  49. like($r, qr/204 No Content/, 'put file again');
  50. unlike($r, qr/Content-Length|Transfer-Encoding/, 'no length in 204');
  51. is(-s $t->testdir() . '/file', 0, 'put file again size');
  52. $r = http(<<EOF);
  53. DELETE /file HTTP/1.1
  54. Host: localhost
  55. Connection: close
  56. Content-Length: 0
  57. EOF
  58. like($r, qr/204 No Content/, 'delete file');
  59. unlike($r, qr/Content-Length|Transfer-Encoding/, 'no length in 204');
  60. ok(!-f $t->testdir() . '/file', 'file deleted');
  61. $r = http(<<EOF . '0123456789' . 'extra');
  62. PUT /file HTTP/1.1
  63. Host: localhost
  64. Connection: close
  65. Content-Length: 10
  66. EOF
  67. like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms,
  68. 'put file extra data');
  69. TODO: {
  70. local $TODO = 'not yet';
  71. is(-s $t->testdir() . '/file', 10,
  72. 'put file extra data size');
  73. }
  74. TODO: {
  75. local $TODO = 'broken in 0.8.32';
  76. # 201 replies contain body, response should indicate it's empty
  77. # before 0.8.32 chunked was explicitly disabled for 201 replies so
  78. # connection was just closed (which isn't perfect but worked)
  79. $r = http(<<EOF);
  80. MKCOL /test/ HTTP/1.1
  81. Host: localhost
  82. Connection: close
  83. EOF
  84. like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'mkcol');
  85. $r = http(<<EOF);
  86. COPY /test/ HTTP/1.1
  87. Host: localhost
  88. Destination: /test-moved/
  89. Connection: close
  90. EOF
  91. like($r, qr/201 Created.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'copy dir');
  92. $r = http(<<EOF);
  93. MOVE /test/ HTTP/1.1
  94. Host: localhost
  95. Destination: /test-moved/
  96. Connection: close
  97. EOF
  98. like($r, qr/201.*(Content-Length|\x0d\0a0\x0d\x0a)/ms, 'move dir');
  99. }
  100. ###############################################################################