From afcb68c183cb393a25b9ab869e2874415a1d4cac Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 9 Sep 2026 19:50:14 +0930 Subject: [PATCH] Fix registration form redirecting when max_users is falsy --- .../Controllers/Auth/RegisterController.php | 5 +-- tests/Feature/Auth/RegisterTest.php | 33 +++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 4556023f3..9a6b9f4a4 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -157,10 +157,11 @@ class RegisterController extends Controller $count = User::where(function ($q) { return $q->whereNull('status')->orWhereNotIn('status', ['deleted', 'delete']); })->count(); - if ($limit <= $count) { + // A falsy max_users means "no limit" (matches register() and the + // help view). Guard on $limit so 0/null/'' does not redirect. + if ($limit && $limit <= $count) { return redirect(route('help.instance-max-users-limit')); } - abort_if($limit <= $count, 404); return view('auth.register'); } else { diff --git a/tests/Feature/Auth/RegisterTest.php b/tests/Feature/Auth/RegisterTest.php index d87c9b14f..fd7cde38d 100644 --- a/tests/Feature/Auth/RegisterTest.php +++ b/tests/Feature/Auth/RegisterTest.php @@ -103,3 +103,36 @@ it('redirects authenticated users away from the register page', function () { ->get('/register') ->assertRedirect(); }); + +it('shows the registration form when enforce_max_users is on but max_users is falsy', function () { + // Falsy max_users means "no limit"; the GET form must not redirect to the + // instance-full page (must match the POST handler and the help view). + config(['pixelfed.open_registration' => true]); + config(['pixelfed.enforce_max_users' => true]); + config(['pixelfed.max_users' => 0]); + + $this->get('/register') + ->assertOk(); +}); + +it('redirects the registration form when a real max_users limit is reached', function () { + config(['pixelfed.open_registration' => true]); + config(['pixelfed.enforce_max_users' => true]); + config(['pixelfed.max_users' => 1]); + + User::factory()->create(); + + $this->get('/register') + ->assertRedirect(route('help.instance-max-users-limit')); +}); + +it('shows the registration form when under a real max_users limit', function () { + config(['pixelfed.open_registration' => true]); + config(['pixelfed.enforce_max_users' => true]); + config(['pixelfed.max_users' => 1000]); + + User::factory()->create(); + + $this->get('/register') + ->assertOk(); +});