add autodeploy and add basic auth for file uploader
Some checks failed
Deploy back2 / deploy (push) Failing after 46s

This commit is contained in:
2026-04-02 19:42:04 +03:00
parent ad4a3367c3
commit b36cf07635
10 changed files with 244 additions and 56 deletions

View File

@@ -9,14 +9,60 @@ use Tests\TestCase;
class FileLinkControllerTest extends TestCase
{
public function test_upload_is_unavailable_when_feature_is_disabled(): void
protected function setUp(): void
{
Config::set('file_links.enabled', false);
parent::setUp();
Config::set('file_links.upload_basic_auth_users', [
['username' => 'uploader1', 'password' => 'password1'],
['username' => 'uploader2', 'password' => 'password2'],
]);
}
private function authHeader(string $username = 'uploader1', string $password = 'password1'): array
{
return [
'Authorization' => 'Basic ' . base64_encode($username . ':' . $password),
];
}
public function test_upload_requires_basic_auth(): void
{
Config::set('file_links.enabled', true);
$response = $this->postJson('/api/files/upload', [
'file' => UploadedFile::fake()->create('sample.txt', 1),
]);
$response->assertUnauthorized();
$response->assertHeader('WWW-Authenticate', 'Basic realm="File Upload"');
}
public function test_upload_accepts_second_basic_auth_user(): void
{
Storage::fake('local');
Config::set('file_links.enabled', true);
Config::set('file_links.disk', 'local');
Config::set('file_links.directory', 'temporary-links');
$response = $this->withHeaders($this->authHeader('uploader2', 'password2'))->postJson(
'/api/files/upload',
['file' => UploadedFile::fake()->create('sample.txt', 1)]
);
$response->assertOk();
$response->assertJsonStructure(['path', 'expiresAt', 'url']);
}
public function test_upload_is_unavailable_when_feature_is_disabled(): void
{
Config::set('file_links.enabled', false);
$response = $this->withHeaders($this->authHeader())->postJson(
'/api/files/upload',
['file' => UploadedFile::fake()->create('sample.txt', 1)]
);
$response->assertNotFound();
}
@@ -27,9 +73,10 @@ class FileLinkControllerTest extends TestCase
Config::set('file_links.disk', 'local');
Config::set('file_links.directory', 'temporary-links');
$response = $this->postJson('/api/files/upload', [
'file' => UploadedFile::fake()->create('sample.txt', 1),
]);
$response = $this->withHeaders($this->authHeader())->postJson(
'/api/files/upload',
['file' => UploadedFile::fake()->create('sample.txt', 1)]
);
$response->assertOk();
$response->assertJsonStructure(['path', 'expiresAt', 'url']);
@@ -50,4 +97,3 @@ class FileLinkControllerTest extends TestCase
$downloadResponse->assertHeader('content-disposition');
}
}