chadtmiller.com/pds.js
An atproto PDS in JavaScript, for Cloudflare Workers and Node
0
0
// A client cannot tell an absent optional endpoint from a broken read unless
// the server answers unregistered NSIDs the way XRPC specifies.
import { describe, expect, it } from 'vitest';
import { PersonalDataServer } from '../packages/core/src/pds.js';
/** @returns {PersonalDataServer} */
function createPds() {
// Nothing here reaches storage, so the ports can be bare stubs.
return new PersonalDataServer({
actorStorage: /** @type {any} */ ({}),
sharedStorage: /** @type {any} */ ({}),
blobs: /** @type {any} */ ({}),
jwtSecret: 'test-secret',
});
}
describe('unregistered XRPC methods', () => {
it('answers MethodNotImplemented', async () => {
const response = await createPds().fetch(
new Request('https://pds.example.com/xrpc/com.example.notAThing'),
);
expect(response.status).toBe(501);
expect(response.headers.get('content-type')).toContain('application/json');
expect(await response.json()).toEqual({
error: 'MethodNotImplemented',
message: 'Method Not Implemented',
});
});
it('answers space methods that way while spaces are off', async () => {
const response = await createPds().fetch(
new Request('https://pds.example.com/xrpc/com.atproto.space.listSpaces'),
);
expect(response.status).toBe(501);
expect((await response.json()).error).toBe('MethodNotImplemented');
});
it('leaves paths outside /xrpc on the plain 404', async () => {
const response = await createPds().fetch(
new Request('https://pds.example.com/not-a-page'),
);
expect(response.status).toBe(404);
});
});