diff --git a/app/Services/MediaBlocklistService.php b/app/Services/MediaBlocklistService.php index d674b3f2f..cffa8dd00 100644 --- a/app/Services/MediaBlocklistService.php +++ b/app/Services/MediaBlocklistService.php @@ -15,18 +15,12 @@ class MediaBlocklistService public static function exists($hash) { - $hashes = self::get(); - - return in_array($hash, $hashes) == true; + return MediaBlocklist::whereSha256($hash)->whereActive(true)->exists(); } public static function remove($hash) { - if (! self::exists($hash)) { - return; - } MediaBlocklist::whereSha256($hash)->delete(); - } public static function add($hash, $metadata) diff --git a/tests/Feature/Services/MediaBlocklistServiceTest.php b/tests/Feature/Services/MediaBlocklistServiceTest.php new file mode 100644 index 000000000..e16d292c3 --- /dev/null +++ b/tests/Feature/Services/MediaBlocklistServiceTest.php @@ -0,0 +1,60 @@ +sha256 = $sha256; + $m->active = $active; + $m->save(); + + return $m; +} + +it('reports an active hash as existing', function () { + makeBlocklistHash('aaaa1111', true); + + expect(MediaBlocklistService::exists('aaaa1111'))->toBeTrue(); +}); + +it('does not report an inactive hash as existing', function () { + makeBlocklistHash('bbbb2222', false); + + expect(MediaBlocklistService::exists('bbbb2222'))->toBeFalse(); +}); + +it('reports an unknown hash as not existing', function () { + expect(MediaBlocklistService::exists('cccc3333'))->toBeFalse(); +}); + +it('removes an inactive hash that exists() would not match', function () { + makeBlocklistHash('dddd4444', false); + + MediaBlocklistService::remove('dddd4444'); + + expect(MediaBlocklist::whereSha256('dddd4444')->exists())->toBeFalse(); +}); + +it('removes an active hash', function () { + makeBlocklistHash('eeee5555', true); + + MediaBlocklistService::remove('eeee5555'); + + expect(MediaBlocklist::whereSha256('eeee5555')->exists())->toBeFalse(); +});