mirror of
https://github.com/projectsend/projectsend.git
synced 2026-09-17 00:55:07 +00:00
6e47d76ba6
Client file sharing, rebuilt from the ground up: a private area per client, resumable uploads, folders, groups and categories, sharing with expiry dates and download limits, comments, file versions, an activity log, a REST API, and sixteen languages. This repository begins here. ProjectSend 2 was developed privately, and that development history is not published — the previous generation remains available, with its own history, at projectsend/legacy. Free software under the GNU General Public License v2, or (at your option) any later version.
56 lines
2.2 KiB
PHP
56 lines
2.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Modules\Platform\Capabilities\Edition;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
beforeEach(function () {
|
|
Route::middleware('capability:users.manage')->get('/test/community-only', fn () => 'ok');
|
|
Route::middleware('capability:branding.customize')->get('/test/cloud-only', fn () => 'ok');
|
|
|
|
// Under api/, because ProblemDetails is scoped to the API on purpose —
|
|
// a refusal on a web route is not supposed to be an RFC 7807 document.
|
|
// Not api/v1/, so OpenApiContractTest's documented-vs-registered
|
|
// comparison ignores it.
|
|
Route::middleware('capability:branding.customize')->get('api/test/cloud-only', fn () => 'ok');
|
|
});
|
|
|
|
test('a capability available in the current edition lets the request through', function () {
|
|
config()->set('projectsend.edition', Edition::Community);
|
|
|
|
$this->get('/test/community-only')->assertOk()->assertSee('ok');
|
|
});
|
|
|
|
test('a capability unavailable in the current edition returns 404 on web requests', function () {
|
|
config()->set('projectsend.edition', Edition::Community);
|
|
|
|
$this->get('/test/cloud-only')->assertNotFound();
|
|
});
|
|
|
|
// The machine-readable half survives, but as an RFC 7807 document like
|
|
// every other API error rather than a shape of its own — a caller that
|
|
// parses errors once should not have to special-case this one. `type` is
|
|
// the slug to branch on; `capability` and `edition` say which feature and
|
|
// where, which is the part worth giving up on rather than retrying.
|
|
test('a capability unavailable in the current edition returns a machine-readable 403 on API requests', function () {
|
|
config()->set('projectsend.edition', Edition::Community);
|
|
|
|
$this->getJson('/api/test/cloud-only')
|
|
->assertForbidden()
|
|
->assertHeader('Content-Type', 'application/problem+json')
|
|
->assertJson([
|
|
'type' => 'capability_unavailable',
|
|
'status' => 403,
|
|
'capability' => 'branding.customize',
|
|
'edition' => 'community',
|
|
]);
|
|
});
|
|
|
|
test('the same routes flip availability when running as the cloud edition', function () {
|
|
config()->set('projectsend.edition', Edition::Cloud);
|
|
|
|
$this->get('/test/cloud-only')->assertOk();
|
|
$this->get('/test/community-only')->assertNotFound();
|
|
});
|