verify recursion limit in MockResolver
This commit is contained in:
parent
c45d6ea452
commit
6f6ee0436e
2 changed files with 14 additions and 2 deletions
|
|
@ -30,7 +30,7 @@ import { ApRequestService } from './ApRequestService.js';
|
|||
import type { IObject, ApObject, IAnonymousObject } from './type.js';
|
||||
|
||||
export class Resolver {
|
||||
private history: Set<string>;
|
||||
protected readonly history: Set<string>;
|
||||
private user?: MiLocalUser;
|
||||
private logger: Logger;
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ export class Resolver {
|
|||
private readonly apLogService: ApLogService,
|
||||
private readonly apUtilityService: ApUtilityService,
|
||||
private readonly cacheService: CacheService,
|
||||
private recursionLimit = 256,
|
||||
protected readonly recursionLimit = 256,
|
||||
) {
|
||||
this.history = new Set();
|
||||
this.logger = this.loggerService.getLogger('ap-resolve');
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ import { fromTuple } from '@/misc/from-tuple.js';
|
|||
import { SystemAccountService } from '@/core/SystemAccountService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { Resolver } from '@/core/activitypub/ApResolverService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { IdentifiableError } from '@/misc/identifiable-error.js';
|
||||
|
||||
type MockResponse = {
|
||||
type: string;
|
||||
|
|
@ -66,6 +68,7 @@ export class MockResolver extends Resolver {
|
|||
}
|
||||
|
||||
public clear(): void {
|
||||
this.history.clear();
|
||||
this.#responseMap.clear();
|
||||
this.#remoteGetTrials.length = 0;
|
||||
}
|
||||
|
|
@ -81,6 +84,15 @@ export class MockResolver extends Resolver {
|
|||
value = fromTuple(value);
|
||||
if (typeof value !== 'string') return value;
|
||||
|
||||
// Check history - copied from Resolver._resolve
|
||||
if (this.history.has(value)) {
|
||||
throw new IdentifiableError('0dc86cf6-7cd6-4e56-b1e6-5903d62d7ea5', `failed to resolve ${value}: recursive resolution blocked`);
|
||||
}
|
||||
if (this.history.size > this.recursionLimit) {
|
||||
throw new IdentifiableError('d592da9f-822f-4d91-83d7-4ceefabcf3d2', `failed to resolve ${value}: hit recursion limit`);
|
||||
}
|
||||
this.history.add(value);
|
||||
|
||||
this.#remoteGetTrials.push(value);
|
||||
const r = this.#responseMap.get(value);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue