mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Update for legacy guids
This commit is contained in:
@@ -128,14 +128,14 @@ final class ReleaseSchemaOptimizationMigrationTest extends TestCase
|
||||
public function test_preflight_blocks_bad_identifiers_and_the_opt_out_bypasses_it(): void
|
||||
{
|
||||
DB::table('releases')->insert([
|
||||
['id' => 1, 'guid' => 'not-a-uuid', 'leftguid' => 'z', 'comments' => 0],
|
||||
['id' => 1, 'guid' => str_repeat('a', 41), 'leftguid' => 'a', 'comments' => 0],
|
||||
]);
|
||||
|
||||
try {
|
||||
$this->invoke('assertReleaseIdentifiersAreSafe');
|
||||
$this->fail('The migration accepted an invalid guid.');
|
||||
$this->fail('The migration accepted a guid that does not fit the narrowed column.');
|
||||
} catch (RuntimeException $e) {
|
||||
$this->assertStringContainsString('invalid release GUIDs', $e->getMessage());
|
||||
$this->assertStringContainsString('release GUIDs that do not fit CHAR(40) ascii', $e->getMessage());
|
||||
$this->assertStringContainsString('releases:normalize-guids', $e->getMessage());
|
||||
}
|
||||
|
||||
@@ -144,6 +144,18 @@ final class ReleaseSchemaOptimizationMigrationTest extends TestCase
|
||||
$this->assertSame(1, DB::table('releases')->count());
|
||||
}
|
||||
|
||||
public function test_preflight_accepts_legacy_sha1_guids(): void
|
||||
{
|
||||
DB::table('releases')->insert([
|
||||
['id' => 1, 'guid' => '0c5c002220e26542a4c9dae845a58a38b3e7e63a', 'leftguid' => '0', 'comments' => 0],
|
||||
['id' => 2, 'guid' => '01234567-89ab-cdef-0123-456789abcdef', 'leftguid' => '0', 'comments' => 0],
|
||||
]);
|
||||
|
||||
$this->invoke('assertReleaseIdentifiersAreSafe');
|
||||
|
||||
$this->assertSame(2, DB::table('releases')->count());
|
||||
}
|
||||
|
||||
private function invoke(string $method): void
|
||||
{
|
||||
/** @var Migration $migration */
|
||||
|
||||
@@ -70,7 +70,7 @@ final class ReleasesNormalizeGuidsTest extends TestCase
|
||||
public function test_dry_run_reports_without_writing(): void
|
||||
{
|
||||
$this->insertRelease(1, '01234567-89ab-cdef-0123-456789abcdef', 'f');
|
||||
$this->insertRelease(2, 'd41d8cd98f00b204e9800998ecf8427e', 'd');
|
||||
$this->insertRelease(2, str_repeat('a', 41), 'x');
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids', ['--dry-run' => true]);
|
||||
$output = Artisan::output();
|
||||
@@ -78,21 +78,47 @@ final class ReleasesNormalizeGuidsTest extends TestCase
|
||||
$this->assertSame(1, $status);
|
||||
$this->assertStringContainsString('Dry run: no rows are modified.', $output);
|
||||
$this->assertSame('f', DB::table('releases')->where('id', 1)->value('leftguid'));
|
||||
$this->assertSame('d41d8cd98f00b204e9800998ecf8427e', DB::table('releases')->where('id', 2)->value('guid'));
|
||||
$this->assertSame(str_repeat('a', 41), DB::table('releases')->where('id', 2)->value('guid'));
|
||||
}
|
||||
|
||||
public function test_invalid_guid_is_reported_and_never_rewritten(): void
|
||||
public function test_legacy_sha1_guid_fits_the_narrowed_column_and_does_not_block(): void
|
||||
{
|
||||
$this->insertRelease(1, 'd41d8cd98f00b204e9800998ecf8427e', 'd', ['name' => 'Legacy nZEDb release']);
|
||||
$sha1 = '0c5c002220e26542a4c9dae845a58a38b3e7e63a';
|
||||
$this->insertRelease(1, $sha1, '0');
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids');
|
||||
$output = Artisan::output();
|
||||
|
||||
$this->assertSame(0, $status);
|
||||
$this->assertStringContainsString('Release guids are consistent.', $output);
|
||||
$this->assertStringContainsString('1 releases still carry a legacy non-UUID guid', $output);
|
||||
$this->assertSame($sha1, DB::table('releases')->where('id', 1)->value('guid'));
|
||||
}
|
||||
|
||||
public function test_oversized_guid_is_reported_and_never_rewritten(): void
|
||||
{
|
||||
$tooLong = str_repeat('b', 41);
|
||||
$this->insertRelease(1, $tooLong, 'b', ['name' => 'Oversized guid release']);
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids');
|
||||
$output = Artisan::output();
|
||||
|
||||
$this->assertSame(1, $status);
|
||||
$this->assertStringContainsString('1 releases have a guid that blocks the normalization migration.', $output);
|
||||
$this->assertStringContainsString('d41d8cd98f00b204e9800998ecf8427e', $output);
|
||||
$this->assertStringContainsString('Legacy nZEDb release', $output);
|
||||
$this->assertSame('d41d8cd98f00b204e9800998ecf8427e', DB::table('releases')->where('id', 1)->value('guid'));
|
||||
$this->assertStringContainsString('Oversized guid release', $output);
|
||||
$this->assertSame($tooLong, DB::table('releases')->where('id', 1)->value('guid'));
|
||||
}
|
||||
|
||||
public function test_non_ascii_guid_blocks_the_migration(): void
|
||||
{
|
||||
$this->insertRelease(1, 'd41d8cd98f00b204e9800998ecf842ü', 'd', ['name' => 'Non ASCII guid']);
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids');
|
||||
$output = Artisan::output();
|
||||
|
||||
$this->assertSame(1, $status);
|
||||
$this->assertStringContainsString('1 releases have a guid that blocks', $output);
|
||||
$this->assertStringContainsString('Non ASCII guid', $output);
|
||||
}
|
||||
|
||||
public function test_case_insensitive_duplicates_report_every_id_but_the_lowest(): void
|
||||
|
||||
@@ -69,7 +69,7 @@ final class ReleaseSchemaOptimizationMigrationMariaDbTest extends TestCase
|
||||
$this->assertSame('temporary', DB::table('release_nzb_creation_failures')->where('releases_id', 1)->value('last_error'));
|
||||
$this->assertSame(['id'], $this->primaryKeyColumns());
|
||||
$this->assertSame('ascii_general_ci', $this->columnCollation('guid'));
|
||||
$this->assertSame('char(36)', strtolower($this->columnType('guid')));
|
||||
$this->assertSame('char(40)', strtolower($this->columnType('guid')));
|
||||
$this->assertSame('ascii_general_ci', $this->columnCollation('leftguid'));
|
||||
$this->assertSame(1, (int) DB::table('releases')->where('id', 1)->value('comments'));
|
||||
$this->assertFalse(Schema::hasColumn('releases', 'nzb_password'));
|
||||
@@ -113,6 +113,23 @@ final class ReleaseSchemaOptimizationMigrationMariaDbTest extends TestCase
|
||||
$this->assertDatabaseHas('release_files', ['releases_id' => 1, 'name' => 'kept.nzb']);
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function rebuild_keeps_legacy_sha1_guids_intact(): void
|
||||
{
|
||||
$sha1 = '0c5c002220e26542a4c9dae845a58a38b3e7e63a';
|
||||
DB::table('releases')->insert([
|
||||
'id' => 9001,
|
||||
'guid' => $sha1,
|
||||
'leftguid' => '0',
|
||||
'name' => 'Legacy nZEDb release',
|
||||
]);
|
||||
|
||||
$this->migration()->up();
|
||||
|
||||
$this->assertSame('char(40)', strtolower($this->columnType('guid')));
|
||||
$this->assertSame($sha1, DB::table('releases')->where('id', 9001)->value('guid'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function rebuild_narrows_claim_tokens_and_covers_size_in_one_pass(): void
|
||||
{
|
||||
|
||||
@@ -46,7 +46,7 @@ final class ReleasesNormalizeGuidsMariaDbTest extends TestCase
|
||||
DB::statement(
|
||||
'CREATE TABLE `'.$this->table('releases').'` (
|
||||
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`guid` VARCHAR(40) NOT NULL,
|
||||
`guid` VARCHAR(64) NOT NULL,
|
||||
`leftguid` CHAR(1) NOT NULL DEFAULT "",
|
||||
`name` VARCHAR(255) NOT NULL DEFAULT "",
|
||||
PRIMARY KEY (`id`),
|
||||
@@ -77,19 +77,33 @@ final class ReleasesNormalizeGuidsMariaDbTest extends TestCase
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function legacy_md5_guids_are_detected_by_the_regexp_check(): void
|
||||
public function legacy_sha1_guids_fit_the_narrowed_column_and_do_not_block(): void
|
||||
{
|
||||
$this->insert(1, '01234567-89ab-cdef-0123-456789abcdef', '0');
|
||||
$this->insert(2, 'd41d8cd98f00b204e9800998ecf8427e', 'd', 'Legacy nZEDb release');
|
||||
$this->insert(3, 'not-a-uuid-at-all-------------------x', 'n');
|
||||
$this->insert(2, '0c5c002220e26542a4c9dae845a58a38b3e7e63a', '0', 'Legacy nZEDb release');
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids');
|
||||
$output = Artisan::output();
|
||||
|
||||
$this->assertSame(0, $status);
|
||||
$this->assertStringContainsString('Release guids are consistent.', $output);
|
||||
$this->assertStringContainsString('1 releases still carry a legacy non-UUID guid', $output);
|
||||
$this->assertSame('0c5c002220e26542a4c9dae845a58a38b3e7e63a', DB::table('releases')->where('id', 2)->value('guid'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function oversized_guids_are_detected_by_the_regexp_check(): void
|
||||
{
|
||||
$this->insert(1, '01234567-89ab-cdef-0123-456789abcdef', '0');
|
||||
$this->insert(2, str_repeat('a', 41), 'a', 'Oversized guid release');
|
||||
|
||||
$status = Artisan::call('releases:normalize-guids');
|
||||
$output = Artisan::output();
|
||||
|
||||
$this->assertSame(1, $status);
|
||||
$this->assertStringContainsString('2 releases have a guid that blocks', $output);
|
||||
$this->assertStringContainsString('Legacy nZEDb release', $output);
|
||||
$this->assertSame('d41d8cd98f00b204e9800998ecf8427e', DB::table('releases')->where('id', 2)->value('guid'));
|
||||
$this->assertStringContainsString('1 releases have a guid that blocks', $output);
|
||||
$this->assertStringContainsString('Oversized guid release', $output);
|
||||
$this->assertSame(str_repeat('a', 41), DB::table('releases')->where('id', 2)->value('guid'));
|
||||
}
|
||||
|
||||
#[Test]
|
||||
|
||||
Reference in New Issue
Block a user