@if (!empty($errors))
diff --git a/routes/api.php b/routes/api.php
index 741a7e7f4e6..702e83b10f3 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -127,13 +127,13 @@
*/
Route::post('/WebAuthn::list', [WebAuthn\WebAuthnManageController::class, 'list']);
Route::post('/WebAuthn::delete', [WebAuthn\WebAuthnManageController::class, 'delete']);
-Route::post('/WebAuthn::register/options', [\App\Http\Controllers\WebAuthn\WebAuthnRegisterController::class, 'options'])
+Route::post('/WebAuthn::register/options', [WebAuthn\WebAuthnRegisterController::class, 'options'])
->name('webauthn.register.options');
-Route::post('/WebAuthn::register', [\App\Http\Controllers\WebAuthn\WebAuthnRegisterController::class, 'register'])
+Route::post('/WebAuthn::register', [WebAuthn\WebAuthnRegisterController::class, 'register'])
->name('webauthn.register');
-Route::post('/WebAuthn::login/options', [\App\Http\Controllers\WebAuthn\WebAuthnLoginController::class, 'options'])
+Route::post('/WebAuthn::login/options', [WebAuthn\WebAuthnLoginController::class, 'options'])
->name('webauthn.login.options');
-Route::post('/WebAuthn::login', [\App\Http\Controllers\WebAuthn\WebAuthnLoginController::class, 'login'])
+Route::post('/WebAuthn::login', [WebAuthn\WebAuthnLoginController::class, 'login'])
->name('webauthn.login');
/**
diff --git a/routes/web-install.php b/routes/web-install.php
index 780084f3ff2..9a86e2b19e4 100644
--- a/routes/web-install.php
+++ b/routes/web-install.php
@@ -28,3 +28,12 @@
Route::get('install/perm', [PermissionsController::class, 'view'])->name('install-perm');
Route::match(['get', 'post'], 'install/env', [EnvController::class, 'view'])->name('install-env');
Route::get('install/migrate', [MigrationController::class, 'view'])->name('install-migrate');
+
+Route::post('install/admin', [SetUpAdminController::class, 'create'])
+ ->withoutMiddleware(['installation:incomplete'])
+ ->middleware(['admin_user:unset', 'installation:complete'])
+ ->name('install-admin');
+Route::get('install/admin', [SetUpAdminController::class, 'init'])
+ ->withoutMiddleware(['installation:incomplete'])
+ ->middleware(['admin_user:unset', 'installation:complete'])
+ ->name('install-admin');
diff --git a/tests/Boot.php b/tests/Boot.php
new file mode 100644
index 00000000000..cf9403ae17e
--- /dev/null
+++ b/tests/Boot.php
@@ -0,0 +1,44 @@
+createApplication();
+ /** @var User|null $admin */
+ $admin = User::find(1);
+ if ($admin === null) {
+ $admin = new User();
+ $admin->incrementing = false;
+ $admin->id = 1;
+ $admin->may_upload = true;
+ $admin->may_edit_own_settings = true;
+ $admin->may_administrate = true;
+ $admin->username = 'admin';
+ $admin->password = Hash::make('password');
+ $admin->save();
+
+ if (Schema::connection(null)->getConnection()->getDriverName() === 'pgsql' && DB::table('users')->count() > 0) {
+ // when using PostgreSQL, the next ID value is kept when inserting without incrementing
+ // which results in errors because trying to insert a user with ID = 1.
+ // Thus, we need to reset the index to the greatest ID + 1
+ /** @var User $lastUser */
+ $lastUser = User::query()->orderByDesc('id')->first();
+ DB::statement('ALTER SEQUENCE users_id_seq1 RESTART WITH ' . strval($lastUser->id + 1));
+ }
+ } elseif (!$admin->may_administrate) {
+ $admin->may_administrate = true;
+ $admin->save();
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Feature/AlbumTest.php b/tests/Feature/AlbumTest.php
index b72d4fee0c4..c4a974371cd 100644
--- a/tests/Feature/AlbumTest.php
+++ b/tests/Feature/AlbumTest.php
@@ -90,7 +90,7 @@ public function testAddNotLogged(): void
public function testAddReadLogged(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$this->clearCachedSmartAlbums();
$this->albums_tests->get(RecentAlbum::ID);
@@ -164,7 +164,7 @@ public function testAddReadLogged(): void
$this->albums_tests->unlock($albumID1, 'wrong-password', 403);
$this->albums_tests->get($albumID1, 401);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
/*
* Let's try to delete this album.
@@ -228,7 +228,7 @@ public function testMultiDelete(): void
// tests.
static::assertDatabaseCount('base_albums', 0);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// Create the test layout
$albumID1 = $this->albums_tests->add(null, 'Album 1')->offsetGet('id');
@@ -372,7 +372,7 @@ public function testMerge(): void
// tests.
static::assertDatabaseCount('base_albums', 0);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// Create the test layout
$albumID1 = $this->albums_tests->add(null, 'Album 1')->offsetGet('id');
@@ -489,7 +489,7 @@ public function testMerge(): void
public function testTrueNegative(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$this->albums_tests->set_description('-1', 'new description', 422);
$this->albums_tests->set_description('abcdefghijklmnopqrstuvwx', 'new description', 404);
@@ -506,7 +506,7 @@ public function testAlbumTree(): void
$albumSortingOrder = Configs::getValueAsString(self::CONFIG_ALBUMS_SORTING_ORDER);
try {
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
Configs::set(self::CONFIG_ALBUMS_SORTING_COL, 'title');
Configs::set(self::CONFIG_ALBUMS_SORTING_ORDER, 'ASC');
@@ -559,7 +559,7 @@ public function testAlbumTree(): void
public function testAddAlbumByNonAdminUserWithoutUploadPrivilege(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID = $this->users_tests->add('Test user', 'Test password', false)->offsetGet('id');
Auth::logout();
Session::flush();
@@ -569,7 +569,7 @@ public function testAddAlbumByNonAdminUserWithoutUploadPrivilege(): void
public function testAddAlbumByNonAdminUserWithUploadPrivilege(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID = $this->users_tests->add('Test user', 'Test password')->offsetGet('id');
Auth::logout();
Session::flush();
@@ -579,7 +579,7 @@ public function testAddAlbumByNonAdminUserWithUploadPrivilege(): void
public function testEditAlbumByNonOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
@@ -595,7 +595,7 @@ public function testEditAlbumByNonOwner(): void
public function testEditAlbumByOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID = $this->users_tests->add('Test user', 'Test password 1')->offsetGet('id');
Auth::logout();
Session::flush();
@@ -627,7 +627,7 @@ public function testEditAlbumByOwner(): void
public function testDeleteMultipleAlbumsByAnonUser(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID1 = $this->albums_tests->add(null, 'Test Album 1')->offsetGet('id');
$albumID2 = $this->albums_tests->add(null, 'Test Album 2')->offsetGet('id');
Auth::logout();
@@ -637,7 +637,7 @@ public function testDeleteMultipleAlbumsByAnonUser(): void
public function testDeleteMultipleAlbumsByNonAdminUserWithoutUploadPrivilege(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID1 = $this->albums_tests->add(null, 'Test Album 1')->offsetGet('id');
$albumID2 = $this->albums_tests->add(null, 'Test Album 2')->offsetGet('id');
$userID = $this->users_tests->add('Test user', 'Test password', false)->offsetGet('id');
@@ -650,7 +650,7 @@ public function testDeleteMultipleAlbumsByNonAdminUserWithoutUploadPrivilege():
public function testDeleteMultipleAlbumsByNonOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
@@ -667,7 +667,7 @@ public function testDeleteMultipleAlbumsByNonOwner(): void
public function testDeleteMultipleAlbumsByOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
Auth::logout();
Session::flush();
@@ -695,7 +695,7 @@ public function testDeleteMultipleAlbumsByOwner(): void
*/
public function testDeleteNonEmptyTagAlbumWithPhotosFromRegularAlbum(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$regularAlbumID = $this->albums_tests->add(null, 'Regular Album for Delete Test')->offsetGet('id');
$photoID = $this->photos_tests->upload(
self::createUploadedFile(self::SAMPLE_FILE_MONGOLIA_IMAGE), $regularAlbumID
@@ -723,7 +723,7 @@ public function testDeleteNonEmptyTagAlbumWithPhotosFromRegularAlbum(): void
*/
public function testSetCoverByNonOwner()
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID = $this->users_tests->add('Test user', 'Test password 1')->offsetGet('id');
$albumID = $this->albums_tests->add(null, 'Test Album')->offsetGet('id');
$photoID1 = $this->photos_tests->upload(
@@ -748,7 +748,7 @@ public function testSetCoverByNonOwner()
*/
public function testSetCoverByOwner()
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID = $this->albums_tests->add(null, 'Test Album')->offsetGet('id');
$photoID1 = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE),
@@ -783,7 +783,7 @@ public function testSetCoverByOwner()
*/
public function testDeleteUnsorted(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$id = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE)
)->offsetGet('id');
@@ -803,7 +803,7 @@ public function testDeleteUnsorted(): void
public function testHiddenSmartAlbums(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$this->clearCachedSmartAlbums();
Configs::set('SA_enabled', true);
@@ -844,7 +844,7 @@ public function testHiddenSmartAlbums(): void
public function testOnThisDayAlbumWhenThereIsPhotoTakenAtCurrentMonthAndDay(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$today = CarbonImmutable::today();
$photoID = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE)
@@ -866,7 +866,7 @@ public function testOnThisDayAlbumWhenThereIsPhotoTakenAtCurrentMonthAndDay(): v
public function testOnThisDayAlbumWhenThereIsPhotoCreatedAtCurrentMonthAndDay(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$today = CarbonImmutable::today();
$photoID = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE)
@@ -887,7 +887,7 @@ public function testOnThisDayAlbumWhenThereIsPhotoCreatedAtCurrentMonthAndDay():
public function testOnThisDayAlbumWhenIsEmpty(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$today = CarbonImmutable::today();
$photoID = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE)
diff --git a/tests/Feature/ApiTokenTest.php b/tests/Feature/ApiTokenTest.php
index c583b7fe7e8..64e486b06b9 100644
--- a/tests/Feature/ApiTokenTest.php
+++ b/tests/Feature/ApiTokenTest.php
@@ -49,7 +49,7 @@ public function testAuthenticateWithTokenOnly(): void
]);
$this->assertStatus($response, 200);
$response->assertSee([
- 'id' => 0,
+ 'id' => 1,
], false);
$this->assertAuthenticated();
@@ -72,7 +72,7 @@ public function testChangeOfTokensWithoutSession(): void
]);
$this->assertStatus($response, 200);
$response->assertSee([
- 'id' => 0,
+ 'id' => 1,
], false);
// We need to call this to mimic the behaviour of real-world
@@ -112,7 +112,7 @@ public function testForbiddenChangeOfTokensInSameSession(): void
]);
$this->assertStatus($response, 200);
$response->assertSee([
- 'id' => 0,
+ 'id' => 1,
], false);
// We need to call this to mimic the behaviour of real-world
@@ -263,7 +263,7 @@ public function testProvideDifferentTokenThanLogin(): void
*/
protected function resetAdminToken(): string
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$token = $this->users_tests->reset_token()->offsetGet('token');
Auth::logout();
Session::flush();
@@ -279,7 +279,7 @@ protected function resetAdminToken(): string
*/
protected function createUserWithToken(string $userName, string $password): array
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$id = $this->users_tests->add($userName, $password)->offsetGet('id');
Auth::logout();
Session::flush();
diff --git a/tests/Feature/Base/BasePhotoTest.php b/tests/Feature/Base/BasePhotoTest.php
index 2ac90f0ddfb..66351baa2f7 100644
--- a/tests/Feature/Base/BasePhotoTest.php
+++ b/tests/Feature/Base/BasePhotoTest.php
@@ -38,7 +38,7 @@ public function setUp(): void
$this->setUpRequiresExifTool();
$this->setUpRequiresFFMpeg();
$this->setUpRequiresEmptyPhotos();
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
}
public function tearDown(): void
diff --git a/tests/Feature/CommandsTest.php b/tests/Feature/CommandsTest.php
index 207b039cf4e..cf5e8819fe2 100644
--- a/tests/Feature/CommandsTest.php
+++ b/tests/Feature/CommandsTest.php
@@ -30,10 +30,6 @@ public function testCommands(): void
->expectsOutput('No pictures requires EXIF updates.')
->assertExitCode(-1);
- $this->artisan('lychee:reset_admin')
- ->expectsOutput('Admin username and password reset.')
- ->assertExitCode(0);
-
$this->artisan('lychee:logs')
->assertExitCode(0);
diff --git a/tests/Feature/DiagnosticsTest.php b/tests/Feature/DiagnosticsTest.php
index 46026250ce5..f69352596ea 100644
--- a/tests/Feature/DiagnosticsTest.php
+++ b/tests/Feature/DiagnosticsTest.php
@@ -29,7 +29,7 @@ public function testDiagnostics(): void
$response = $this->get('/Diagnostics');
$this->assertOk($response); // code 200 something
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->get('/Diagnostics');
$this->assertOk($response); // code 200 something
diff --git a/tests/Feature/GeoDataTest.php b/tests/Feature/GeoDataTest.php
index ecfd75f2365..5c69ff6f2ae 100644
--- a/tests/Feature/GeoDataTest.php
+++ b/tests/Feature/GeoDataTest.php
@@ -43,7 +43,7 @@ public function setUp(): void
$this->albums_tests = new AlbumsUnitTest($this);
$this->root_album_tests = new RootAlbumUnitTest($this);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$this->setUpRequiresEmptyPhotos();
$this->setUpRequiresEmptyAlbums();
@@ -195,7 +195,7 @@ public function testThumbnailsInsideHiddenAlbum(): void
$includeSubAlbums = Configs::getValueAsBool(self::CONFIG_MAP_INCLUDE_SUBALBUMS);
try {
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
Configs::set(self::CONFIG_PUBLIC_RECENT, true);
Configs::set(self::CONFIG_PUBLIC_HIDDEN, false);
Configs::set(self::CONFIG_PUBLIC_SEARCH, true);
diff --git a/tests/Feature/InstallTest.php b/tests/Feature/InstallTest.php
index c76c082f504..1cc8c433275 100644
--- a/tests/Feature/InstallTest.php
+++ b/tests/Feature/InstallTest.php
@@ -15,6 +15,9 @@
use App\Models\Configs;
use App\Models\User;
use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Schema;
use function Safe\file_get_contents;
use Tests\AbstractTestCase;
@@ -31,8 +34,6 @@ public function testInstall(): void
/*
* Get previous config
*/
- /** @var User $admin */
- $admin = User::query()->find(0);
$prevAppKey = config('app.key');
config(['app.key' => null]);
@@ -129,12 +130,33 @@ public function testInstall(): void
$this->assertOk($response);
$response->assertViewIs('install.migrate');
+ $response = $this->get('install/admin');
+ $this->assertOk($response);
+ $response->assertViewIs('install.setup-admin');
+
+ /**
+ * set up admin user migration.
+ */
+ $response = $this->post('install/admin', ['username' => 'admin', 'password' => 'password', 'password_confirmation' => 'password']);
+ $this->assertOk($response);
+ $response->assertViewIs('install.setup-success');
+
+ // try to login with newly created admin
+ $this->assertTrue(Auth::attempt(['username' => 'admin', 'password' => 'password']));
+ Auth::logout();
+
/**
* Re-Installation should be forbidden now.
*/
$response = $this->get('install/');
$this->assertForbidden($response);
+ /**
+ * Setting admin should be forbidden now.
+ */
+ $response = $this->get('install/admin');
+ $this->assertForbidden($response);
+
/**
* We now should NOT be redirected.
*/
@@ -142,8 +164,32 @@ public function testInstall(): void
$response = $this->get('/');
$this->assertOk($response);
- $admin->save();
- $admin->id = 0;
- $admin->save();
+ /*
+ * make sure there's still an admin user with ID 1
+ */
+ /** @var User|null $admin */
+ $admin = User::find(1);
+ if ($admin === null) {
+ $admin = new User();
+ $admin->incrementing = false;
+ $admin->id = 1;
+ $admin->may_upload = true;
+ $admin->may_edit_own_settings = true;
+ $admin->may_administrate = true;
+ $admin->username = 'admin';
+ $admin->password = Hash::make('password');
+ $admin->save();
+ if (Schema::connection(null)->getConnection()->getDriverName() === 'pgsql' && DB::table('users')->count() > 0) {
+ // when using PostgreSQL, the next ID value is kept when inserting without incrementing
+ // which results in errors because trying to insert a user with ID = 1.
+ // Thus, we need to reset the index to the greatest ID + 1
+ /** @var User $lastUser */
+ $lastUser = User::query()->orderByDesc('id')->first();
+ DB::statement('ALTER SEQUENCE users_id_seq1 RESTART WITH ' . strval($lastUser->id + 1));
+ }
+ } elseif (!$admin->may_administrate) {
+ $admin->may_administrate = true;
+ $admin->save();
+ }
}
}
diff --git a/tests/Feature/LegacyTest.php b/tests/Feature/LegacyTest.php
index 0b1f8afdb10..923702d9cfa 100644
--- a/tests/Feature/LegacyTest.php
+++ b/tests/Feature/LegacyTest.php
@@ -57,7 +57,7 @@ public function tearDown(): void
*/
public function testLegacyConversion(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID = $this->albums_tests->add(null, 'Test Album')->offsetGet('id');
$photoID = $this->photos_tests->upload(
AbstractTestCase::createUploadedFile(AbstractTestCase::SAMPLE_FILE_NIGHT_IMAGE),
diff --git a/tests/Feature/LogsTest.php b/tests/Feature/LogsTest.php
index 04a316320aa..15424614f70 100644
--- a/tests/Feature/LogsTest.php
+++ b/tests/Feature/LogsTest.php
@@ -40,7 +40,7 @@ public function testLogs(): void
$this->assertUnauthorized($response);
// set user as admin
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
Logs::notice(__METHOD__, __LINE__, 'test');
$response = $this->get('/Logs');
@@ -72,7 +72,7 @@ public function testClearLogs(): void
$this->assertUnauthorized($response);
// set user as admin
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api/Logs::clearNoise');
$this->assertNoContent($response);
@@ -90,7 +90,7 @@ public function testClearLogs(): void
private function initAdmin(): void
{
- $this->admin = User::find(0);
+ $this->admin = User::find(1);
$this->saveUsername = $this->admin->username;
$this->savedPassword = $this->admin->password;
$this->admin->username = 'temp';
@@ -100,7 +100,7 @@ private function initAdmin(): void
private function revertAdmin(): void
{
- $this->admin = User::find(0);
+ $this->admin = User::find(1);
$this->admin->username = $this->saveUsername;
$this->admin->password = $this->savedPassword;
$this->admin->save();
diff --git a/tests/Feature/NotificationTest.php b/tests/Feature/NotificationTest.php
index 910723c9a5b..08a5bc3e19c 100644
--- a/tests/Feature/NotificationTest.php
+++ b/tests/Feature/NotificationTest.php
@@ -60,7 +60,7 @@ public function testNotificationSetting(): void
$init_config_value = Configs::getValue('new_photos_notification');
try {
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api/Settings::setNewPhotosNotification', [
'new_photos_notification' => '1',
@@ -79,7 +79,7 @@ public function testNotificationSetting(): void
public function testSetupUserEmail(): void
{
// add email to admin
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$this->users_tests->update_email('test@test.com');
Auth::logout();
@@ -120,7 +120,7 @@ public function testSetAlbumForNotification(): void
$init_config_value = Configs::getValue('new_photos_notification');
Configs::set('new_photos_notification', '1');
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID = $this->albums_tests->add(null, 'Album 1')->offsetGet('id');
$photoID = $this->photos_tests->upload(
self::createUploadedFile(self::SAMPLE_FILE_MONGOLIA_IMAGE))->offsetGet('id');
diff --git a/tests/Feature/PhotosDownloadTest.php b/tests/Feature/PhotosDownloadTest.php
index cf40356e898..34f787f116d 100644
--- a/tests/Feature/PhotosDownloadTest.php
+++ b/tests/Feature/PhotosDownloadTest.php
@@ -239,7 +239,7 @@ public function testAlbumDownloadWithMultibyteTitle(): void
public function testDownloadOfInvisibleUnsortedPhotoByNonOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
@@ -259,7 +259,7 @@ public function testDownloadOfPhotoInSharedDownloadableAlbum(): void
$areAlbumsDownloadable = Configs::getValueAsBool(self::CONFIG_DOWNLOADABLE);
try {
Configs::set(self::CONFIG_DOWNLOADABLE, true);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
@@ -285,7 +285,7 @@ public function testDownloadOfPhotoInSharedNonDownloadableAlbum(): void
$areAlbumsDownloadable = Configs::getValueAsBool(self::CONFIG_DOWNLOADABLE);
try {
Configs::set(self::CONFIG_DOWNLOADABLE, false);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
diff --git a/tests/Feature/PhotosOperationsTest.php b/tests/Feature/PhotosOperationsTest.php
index d3a075e2dc6..6abbe33e865 100644
--- a/tests/Feature/PhotosOperationsTest.php
+++ b/tests/Feature/PhotosOperationsTest.php
@@ -342,7 +342,7 @@ public function testThumbnailsInsideHiddenAlbum(): void
$photoSortingOrder = Configs::getValueAsString(self::CONFIG_PHOTOS_SORTING_ORDER);
try {
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
Configs::set(self::CONFIG_PUBLIC_RECENT, true);
Configs::set(self::CONFIG_PUBLIC_HIDDEN, false);
Configs::set(self::CONFIG_PUBLIC_SEARCH, true);
@@ -474,7 +474,7 @@ public function testThumbnailsInsideHiddenAlbum(): void
public function testDeleteMultiplePhotosByAnonUser(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$albumID = $this->albums_tests->add(null, 'Test Album')->offsetGet('id');
$photoID1 = $this->photos_tests->upload(
self::createUploadedFile(self::SAMPLE_FILE_MONGOLIA_IMAGE), $albumID
@@ -490,7 +490,7 @@ public function testDeleteMultiplePhotosByAnonUser(): void
public function testDeleteMultiplePhotosByNonOwner(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$userID1 = $this->users_tests->add('Test user 1', 'Test password 1')->offsetGet('id');
$userID2 = $this->users_tests->add('Test user 2', 'Test password 2')->offsetGet('id');
Auth::logout();
diff --git a/tests/Feature/RSSTest.php b/tests/Feature/RSSTest.php
index b41acb8a2c4..f8559fb8043 100644
--- a/tests/Feature/RSSTest.php
+++ b/tests/Feature/RSSTest.php
@@ -77,7 +77,7 @@ public function testRSS1(): void
$this->assertOk($response);
// log as admin
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// create an album
$albumID = $this->albums_tests->add(null, 'test_album')->offsetGet('id');
diff --git a/tests/Feature/SettingsTest.php b/tests/Feature/SettingsTest.php
index 44aa65ecbe8..2f0a5caa01f 100644
--- a/tests/Feature/SettingsTest.php
+++ b/tests/Feature/SettingsTest.php
@@ -28,7 +28,7 @@ private function send(
int $status = 204,
?string $assertSee = null): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api' . $url, $params);
$this->assertStatus($response, $status);
@@ -48,7 +48,7 @@ private function sendKV(
?string $assertSee = null): void
{
$oldVal = Configs::getValue($key);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api' . $url, [$key => $value]);
$this->assertStatus($response, $status);
@@ -194,7 +194,7 @@ public function testSetCSS(): void
// Route::post('/Settings::saveAll', [Administration\SettingsController::class, 'saveAll']);
public function testAllSettings(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api/Settings::getAll', []);
$this->assertStatus($response, 200);
diff --git a/tests/Feature/SharingBasicTest.php b/tests/Feature/SharingBasicTest.php
index a5f12910e7a..6cb453ae9ca 100644
--- a/tests/Feature/SharingBasicTest.php
+++ b/tests/Feature/SharingBasicTest.php
@@ -23,7 +23,7 @@ public function testEmptySharingList(): void
$response->assertExactJson([
'shared' => [],
'albums' => [],
- 'users' => [],
+ 'users' => [['id' => 1, 'username' => 'admin']],
]);
}
@@ -42,7 +42,7 @@ public function testSharingListWithAlbums(): void
['id' => $albumID1, 'title' => self::ALBUM_TITLE_1],
['id' => $albumID2, 'title' => self::ALBUM_TITLE_1 . '/' . self::ALBUM_TITLE_2],
],
- 'users' => [],
+ 'users' => [['id' => 1, 'username' => 'admin']],
]);
}
@@ -73,10 +73,12 @@ public function testSharingListWithSharedAlbums(): void
['id' => $albumID1, 'title' => self::ALBUM_TITLE_1],
['id' => $albumID2, 'title' => self::ALBUM_TITLE_2],
],
- 'users' => [
- ['id' => $userID1, 'username' => self::USER_NAME_1],
- ['id' => $userID2, 'username' => self::USER_NAME_2],
- ],
]);
+
+ /** @var array $users */
+ $users = $response->offsetGet('users');
+ self::assertContains(['id' => $userID1, 'username' => self::USER_NAME_1], $users);
+ self::assertContains(['id' => $userID2, 'username' => self::USER_NAME_2], $users);
+ self::assertContains(['id' => 1, 'username' => 'admin'], $users);
}
}
\ No newline at end of file
diff --git a/tests/Feature/Traits/RequiresEmptyUsers.php b/tests/Feature/Traits/RequiresEmptyUsers.php
index 1c383ddb60b..adf7c18f3e0 100644
--- a/tests/Feature/Traits/RequiresEmptyUsers.php
+++ b/tests/Feature/Traits/RequiresEmptyUsers.php
@@ -24,7 +24,7 @@ protected function setUpRequiresEmptyUsers(): void
static::assertEquals(
0,
DB::table('users')
- ->where('id', '!=', 0)
+ ->where('may_administrate', '=', false)
->count()
);
}
@@ -32,6 +32,6 @@ protected function setUpRequiresEmptyUsers(): void
protected function tearDownRequiresEmptyUsers(): void
{
// Clean up remaining stuff from tests
- DB::table('users')->where('id', '!=', 0)->delete();
+ DB::table('users')->where('may_administrate', '=', false)->delete();
}
}
diff --git a/tests/Feature/UpdateTest.php b/tests/Feature/UpdateTest.php
index 9acb4c163fe..a1d2b3aa9e0 100644
--- a/tests/Feature/UpdateTest.php
+++ b/tests/Feature/UpdateTest.php
@@ -41,7 +41,7 @@ public function testDoLogged(): void
{
$gitpull = Configs::getValue('allow_online_git_pull');
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
Configs::set('allow_online_git_pull', '0');
$response = $this->postJson('/api/Update::apply');
@@ -89,7 +89,7 @@ public function testApplyMigration(): void
{
// Prepare for test: we need to make sure there is an admin user registered.
/** @var User $adminUser */
- $adminUser = User::findOrFail(0);
+ $adminUser = User::findOrFail(1);
$login = $adminUser->username;
$pw = $adminUser->password;
$adminUser->username = Hash::make('test_login');
@@ -109,7 +109,7 @@ public function testApplyMigration(): void
$this->assertOk($response);
// check that Legacy did change the username
- $adminUser = User::findOrFail(0);
+ $adminUser = User::findOrFail(1);
$this->assertEquals('test_login', $adminUser->username);
// clean up
diff --git a/tests/Feature/UsersTest.php b/tests/Feature/UsersTest.php
index f7fa13664f5..c79f0741016 100644
--- a/tests/Feature/UsersTest.php
+++ b/tests/Feature/UsersTest.php
@@ -12,7 +12,6 @@
namespace Tests\Feature;
-use App\Legacy\AdminAuthentication;
use App\Models\Configs;
use App\Models\User;
use App\SmartAlbums\OnThisDayAlbum;
@@ -34,32 +33,6 @@ class UsersTest extends AbstractTestCase
{
use InteractWithSmartAlbums;
- public function testSetAdminLoginIfAdminUnconfigured(): void
- {
- /**
- * because there is no dependency injection in test cases.
- */
- $sessions_test = new SessionUnitTest($this);
-
- if (!AdminAuthentication::isAdminNotRegistered()) {
- static::markTestSkipped('Admin user is registered; test skipped.');
- }
-
- static::assertTrue(AdminAuthentication::loginAsAdminIfNotRegistered());
- $sessions_test->set_admin('lychee', 'password');
- $sessions_test->logout();
- static::assertFalse(AdminAuthentication::isAdminNotRegistered());
-
- $sessions_test->set_admin('lychee', 'password', 403, 'Admin user is already registered');
-
- $sessions_test->login('lychee', 'password');
- $sessions_test->logout();
-
- $sessions_test->login('foo', 'bar', 401);
- $sessions_test->login('lychee', 'bar', 401);
- $sessions_test->login('foo', 'password', 401);
- }
-
public function testUsers(): void
{
$sessions_test = new SessionUnitTest($this);
@@ -111,11 +84,12 @@ public function testUsers(): void
* 35. update email
* 36. get email
* 37. update email to blank
- * 38. log out
+ * 38. try to delete yourself (not allowed)
+ * 39. log out
*/
// 1
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// 2
$users_test->add(
@@ -207,7 +181,7 @@ public function testUsers(): void
$sessions_test->logout();
// 15
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// 16
$users_test->save(
@@ -277,7 +251,7 @@ public function testUsers(): void
$sessions_test->logout();
// 30
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
// 31
$users_test->delete($id);
@@ -293,7 +267,7 @@ public function testUsers(): void
$sessions_test->logout();
// 33
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$configs = Configs::get();
$store_new_photos_notification = $configs['new_photos_notification'];
@@ -316,6 +290,9 @@ public function testUsers(): void
$users_test->update_email(null);
// 38
+ $response = $users_test->delete(intval(Auth::id()), 403);
+
+ // 39
$sessions_test->logout();
Configs::set('new_photos_notification', $store_new_photos_notification);
}
@@ -324,7 +301,7 @@ public function testResetToken(): void
{
$users_test = new UsersUnitTest($this);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$oldToken = $users_test->reset_token()->offsetGet('token');
$newToken = $users_test->reset_token()->offsetGet('token');
@@ -337,7 +314,7 @@ public function testUnsetToken(): void
{
$users_test = new UsersUnitTest($this);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$oldToken = $users_test->reset_token()->offsetGet('token');
self::assertNotNull($oldToken);
@@ -373,13 +350,13 @@ public function regressionTestAdminAllMighty(): void
], ]);
// update Admin user to non valid rights
- $admin = User::findOrFail(0);
+ $admin = User::findOrFail(1);
$admin->may_upload = false;
$admin->may_edit_own_settings = true;
$admin->save();
// Log as admin and check the rights
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $sessions_test->init();
$response->assertJsonFragment([
'rights' => [
@@ -395,7 +372,7 @@ public function regressionTestAdminAllMighty(): void
$admin->save();
// Log as admin and verify behaviour
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $sessions_test->init();
$response->assertJsonFragment([
'rights' => [
@@ -415,10 +392,10 @@ public function testGetAuthenticatedUser(): void
$users_test->get_user(204);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$users_test->get_user(200, [
- 'id' => 0,
+ 'id' => 1,
]);
}
}
diff --git a/tests/Feature/WebAuthTest.php b/tests/Feature/WebAuthTest.php
index b161ac28d19..cfae6a7b626 100644
--- a/tests/Feature/WebAuthTest.php
+++ b/tests/Feature/WebAuthTest.php
@@ -30,7 +30,7 @@ class WebAuthTest extends AbstractTestCase
*/
public function testWebAuthTest(): void
{
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api/WebAuthn::register/options');
$this->assertOk($response);
@@ -79,10 +79,10 @@ public function testWebAuthTest(): void
'public_key' => '',
]);
/** @var User $user */
- $user = User::query()->find(0);
+ $user = User::query()->find(1);
$user->webAuthnCredentials()->save($key);
- Auth::loginUsingId(0);
+ Auth::loginUsingId(1);
$response = $this->postJson('/api/WebAuthn::list');
$this->assertOk($response); // code 200 something