You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pixelfed/tests/Feature/Federation/NodeInfoTest.php

83 lines
2.8 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\LazilyRefreshDatabase;
use Illuminate\Support\Facades\Config;
uses(LazilyRefreshDatabase::class);
/*
|--------------------------------------------------------------------------
| Federation & Discovery Endpoint Tests
|--------------------------------------------------------------------------
*/
describe('nodeinfo', function () {
it('returns well-known nodeinfo with links', function () {
$this->getJson('/.well-known/nodeinfo')
->assertOk()
->assertJsonStructure(['links' => [['rel', 'href']]]);
});
it('returns nodeinfo 2.0 with correct structure', function () {
$this->getJson('/api/nodeinfo/2.0.json')
->assertOk()
->assertJsonStructure([
'version',
'software' => ['name', 'version'],
'protocols',
'usage' => ['users', 'localPosts'],
'openRegistrations',
])
->assertJsonFragment(['name' => 'pixelfed']);
});
it('reports correct open registration status', function () {
// pixelfed.open_registration is ENVCONFIG. Under the test env its var
// (OPEN_REGISTRATION) is present + valid, so it is env-authoritative and
// config_cache() returns config() — setting config() is what makes the
// value deterministic now that the master switch is gone.
Config::set('pixelfed.open_registration', true);
$response = $this->getJson('/api/nodeinfo/2.0.json');
$data = $response->json();
expect($data['openRegistrations'])->toBeBool();
});
});
describe('webfinger', function () {
it('returns 400 without resource parameter', function () {
$this->getJson('/.well-known/webfinger')
->assertStatus(400);
});
it('returns 400 for invalid resource format', function () {
$this->getJson('/.well-known/webfinger?resource=invalid')
->assertStatus(400);
});
it('returns 400 for non-existent user', function () {
$this->getJson('/.well-known/webfinger?resource=acct:nonexistent@'.config('pixelfed.domain.app'))
->assertStatus(400);
});
it('returns webfinger data for existing local user', function () {
$user = User::factory()->create();
$user->refresh();
$domain = config('pixelfed.domain.app');
$this->getJson("/.well-known/webfinger?resource=acct:{$user->username}@{$domain}")
->assertOk()
->assertJsonStructure(['subject', 'aliases', 'links']);
});
});
describe('host-meta', function () {
it('returns host-meta XML', function () {
$this->get('/.well-known/host-meta')
->assertOk()
->assertHeader('Content-Type', 'application/xrd+xml');
});
});