Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions lib/bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,16 +288,6 @@ function doarchive(
$pdata .= str_repeat('=', $level) . $array['header'] . str_repeat('=', $level) . $array['content'];
}

if (substr(strtolower(str_replace('_', ' ', $archiveprefix)), 0, strlen($page)) != strtolower($page)) {
$expected_key = hash('sha256', trim($page) . trim($config->archiveprefix) . trim(Config::$archive_key));
if (trim($key) != $expected_key) {
$logger->error(
'Incorrect key for archive prefix; page=' . $page . ', prefix=' . $config->archiveprefix
);
$archiveprefix = $page . '/Archives/';
}
}

if ($age == '99999') {
$age = 0;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/config/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,17 @@ function build_config_from_config_block(string $page, RawConfig $block)
$config->once = $options['once'] === '1';
}

// If the archive prefix is not under the same page, then it requires a key,
// verify the key is correct, otherwise use a default archive prefix.
if (substr(strtolower(str_replace('_', ' ', $config->archiveprefix)), 0, strlen($page)) != strtolower($page)) {
$expected_key = hash('sha256', trim($page) . trim($config->archiveprefix) . trim(Config::$archive_key));
if ($config->key != $expected_key) {
$logger->error('Incorrect key for archive prefix; page=' . $page . ', prefix=' . $config->archiveprefix);
$config->archiveprefix = $page . '/Archives/';
$config->key = DefaultConfig::$key;
}
}

$config->is_valid = true;
return $config;
}
16 changes: 16 additions & 0 deletions tests/ConfigGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,20 @@ public function testGeneratedConfigMatchesExpectedConfig(

$this->assertEquals($generated_config, $expected_config);
}

public function testMismatchedArchivePrefixWithoutValidKeyResetsToDefault(): void
{
$raw_config = '{{User:ClueBot III/ArchiveThis' .
'|archiveprefix=Some Other Page/Archives/' .
'|key=totally-wrong-key' .
'|format=Y/F}}';

$config_blocks = find_config_blocks("ClueBot III", $raw_config);
$this->assertCount(1, $config_blocks);

$config = build_config_from_config_block("Test Page", $config_blocks[0]);

$this->assertEquals("Test Page/Archives/", $config->archiveprefix);
$this->assertEquals(DefaultConfig::$key, $config->key);
}
}
3 changes: 3 additions & 0 deletions tests/data/config-snippets/invalid-key/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Talk:Example Page"
}
4 changes: 4 additions & 0 deletions tests/data/config-snippets/invalid-key/normative.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{User:ClueBot III/ArchiveThis
|archiveprefix=Talk:Example Page/Archives/
|age=2160
}}
1 change: 1 addition & 0 deletions tests/data/config-snippets/invalid-key/page.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{User:ClueBot III/ArchiveThis|archiveprefix=Talk:NotMyPage/Archive|age=2160|key=invalid}}
Loading