mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-26 22:57:32 +00:00
fix(wanderer): find the author of an account whose one actor wanderer expands as an object
PocketBase answers a back-relation with a single record as the object itself, not a list, so the user lookup failed as an answer TREK did not understand and every search with it. Closes #2799
This commit is contained in:
@@ -55,11 +55,18 @@ const tokenListSchema = z.object({
|
||||
totalItems: z.number().optional(),
|
||||
});
|
||||
|
||||
/** A user record with the ActivityPub actors that stand for it; the local one authors the user's trails. */
|
||||
const actorSchema = z.object({ id: z.string(), is_local: z.boolean().nullish() });
|
||||
|
||||
/**
|
||||
* A user record with the ActivityPub actors that stand for it; the local one
|
||||
* authors the user's trails. PocketBase expands a back-relation as a single
|
||||
* object when only one record can match and as a list otherwise, so an account
|
||||
* with one actor answers with the object itself.
|
||||
*/
|
||||
const userActorsSchema = z.object({
|
||||
expand: z
|
||||
.object({
|
||||
activitypub_actors_via_user: z.array(z.object({ id: z.string(), is_local: z.boolean().nullish() })).nullish(),
|
||||
activitypub_actors_via_user: z.union([z.array(actorSchema), actorSchema.transform((actor) => [actor])]).nullish(),
|
||||
})
|
||||
.nullish(),
|
||||
});
|
||||
|
||||
@@ -126,6 +126,16 @@ describe('WandererClient', () => {
|
||||
expect(searchBody(0).options.filter).toEqual(["author IN ['nspsn7zu7octact']"]);
|
||||
});
|
||||
|
||||
it('RS-03b: an owner with one actor, which wanderer expands as an object rather than a list, is found', async () => {
|
||||
answer({
|
||||
...OWNER,
|
||||
'/api/v1/user/gixauk8ukjpqabm': reply({
|
||||
expand: { activitypub_actors_via_user: { id: 'nspsn7zu7octact', is_local: true } },
|
||||
}),
|
||||
});
|
||||
await expect(client.ownActors(CREDS)).resolves.toEqual(['nspsn7zu7octact']);
|
||||
});
|
||||
|
||||
it('RS-03: a token wanderer reads as anonymous is refused, however 200 the answer', async () => {
|
||||
answer({ '/api/v1/api-token': reply({ items: [], totalItems: 0 }) });
|
||||
expect((await failure(() => client.check(CREDS))).code).toBe('unauthorized');
|
||||
|
||||
Reference in New Issue
Block a user