maintain.t 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright (C) 2009–2018 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 20;
  18. my $hundred_days_ago = $Now - 100 * 24 * 60 * 60;
  19. my $ten_days_ago = $Now - 10 * 24 * 60 * 60;
  20. my $two_days_ago = $Now - 2 * 24 * 60 * 60;
  21. my $ip = '127.0.0.1';
  22. # $ts, $id, $minor, $summary, $host, @rest
  23. # First, make sure that moving all the entries from rc.log leaves no newline in
  24. # the file.
  25. my $log = join("\n",
  26. join($FS, $hundred_days_ago, 'Two_Hundred_Days_Ago', '',
  27. 'Boring', $ip,
  28. 'Alex', '1', '', ''),
  29. '');
  30. WriteStringToFile($RcFile, $log);
  31. test_page(get_page('action=maintain pwd=foo'),
  32. 'Moving 1 log entries',
  33. 'Removing IP numbers from 0 log entries');
  34. $log = ReadFileOrDie($RcOldFile);
  35. test_page($log, "Hundred_Days_Ago.*Anonymous");
  36. test_page_negative($log, $ip);
  37. $log = ReadFileOrDie($RcFile);
  38. is($log, '', 'rc.log is empty');
  39. # Now let's make sure that an old entry get anonymized and moved (like the
  40. # previous test), and that those that are not moved care anonymized if they are
  41. # old enough.
  42. $log = join("\n",
  43. join($FS, $hundred_days_ago, 'One_Hundred_Days_Ago', '',
  44. 'Boring', $ip,
  45. 'Alex', '1', '', ''),
  46. join($FS, $ten_days_ago, 'Ten_Days_Ago', '',
  47. 'Boring', $ip,
  48. 'Alex', '1', '', ''),
  49. join($FS, $two_days_ago, 'Two_Days_Ago', '',
  50. 'Boring', $ip,
  51. 'Alex', '1', '', ''),
  52. '');
  53. WriteStringToFile($RcFile, $log);
  54. test_page(get_page('action=maintain pwd=foo'),
  55. 'Moving 1 log entries',
  56. 'Removing IP numbers from 1 log entries');
  57. $log = ReadFileOrDie($RcOldFile);
  58. test_page($log,
  59. "Two_Hundred_Days_Ago.*Anonymous",
  60. "One_Hundred_Days_Ago.*Anonymous");
  61. test_page_negative($log, $ip);
  62. $log = ReadFileOrDie($RcFile);
  63. test_page($log,
  64. "Ten_Days_Ago.*Anonymous",
  65. "Two_Days_Ago.*$ip");
  66. test_page_negative($log, "Hundred_Days_Ago");
  67. # Let's make sure that updating pages write the right rc lines.
  68. update_page('test', 'this is a test');
  69. my $log = ReadFileOrDie($RcFile);
  70. test_page($log,
  71. "${FS}test${FS}",
  72. "${FS}this is a test${FS}");
  73. test_page_negative($log, "^\n");
  74. # Make sure that pages to be deleted are in fact deleted.
  75. OpenPage('test');
  76. $Page{ts} = 1;
  77. $Page{revision} = 1;
  78. $Page{text} = $DeletedPage;
  79. SavePage();
  80. AppendStringToFile($ConfigFile, "\$KeepDays = 14;\n");
  81. ok(-f GetPageFile($OpenPageName), GetPageFile($OpenPageName)
  82. . " exists");
  83. xpath_test(get_page('action=maintain pwd=foo'),
  84. '//a[text()="test"]/following-sibling::text()[.=" deleted"]');
  85. ok(! -e GetPageFile($OpenPageName), GetPageFile($OpenPageName)
  86. . " was deleted");
  87. my $data = ReadFileOrDie($DeleteFile);
  88. ok($data eq "test\n", "Delete was logged");