Skip to content
Snippets Groups Projects
Unverified Commit dc49a24f authored by tamaina's avatar tamaina Committed by GitHub
Browse files

Merge pull request #9970 from saschanaz/mkusername-empty

fix(backend/ApPersonService): normalize empty value of `name` into an absent value
parents fcb6e0ad 5651353c
No related branches found
No related tags found
No related merge requests found
......@@ -164,6 +164,9 @@ export class ApPersonService implements OnModuleInit {
throw new Error('invalid Actor: wrong name');
}
x.name = truncate(x.name, nameLength);
} else if (x.name === '') {
// Mastodon emits empty string when the name is not set.
x.name = undefined;
}
if (x.summary) {
if (!(typeof x.summary === 'string' && x.summary.length > 0)) {
......
......@@ -11,8 +11,25 @@ import { GlobalModule } from '@/GlobalModule.js';
import { CoreModule } from '@/core/CoreModule.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import { LoggerService } from '@/core/LoggerService.js';
import type { IActor } from '@/core/activitypub/type.js';
import { MockResolver } from '../misc/mock-resolver.js';
const host = 'https://host1.test';
function createRandomActor(): IActor & { id: string } {
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
return {
'@context': 'https://www.w3.org/ns/activitystreams',
id: actorId,
type: 'Person',
preferredUsername,
inbox: `${actorId}/inbox`,
outbox: `${actorId}/outbox`,
};
}
describe('ActivityPub', () => {
let noteService: ApNoteService;
let personService: ApPersonService;
......@@ -36,18 +53,7 @@ describe('ActivityPub', () => {
});
describe('Parse minimum object', () => {
const host = 'https://host1.test';
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
const actor = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: actorId,
type: 'Person',
preferredUsername,
inbox: `${actorId}/inbox`,
outbox: `${actorId}/outbox`,
};
const actor = createRandomActor();
const post = {
'@context': 'https://www.w3.org/ns/activitystreams',
......@@ -80,29 +86,31 @@ describe('ActivityPub', () => {
});
});
describe('Truncate long name', () => {
const host = 'https://host1.test';
const preferredUsername = `${rndstr('A-Z', 4)}${rndstr('a-z', 4)}`;
const actorId = `${host}/users/${preferredUsername.toLowerCase()}`;
describe('Name field', () => {
test('Truncate long name', async () => {
const actor = {
...createRandomActor(),
name: rndstr('0-9a-z', 129),
};
const name = rndstr('0-9a-z', 129);
resolver._register(actor.id, actor);
const actor = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: actorId,
type: 'Person',
preferredUsername,
name,
inbox: `${actorId}/inbox`,
outbox: `${actorId}/outbox`,
};
const user = await personService.createPerson(actor.id, resolver);
assert.deepStrictEqual(user.name, actor.name.slice(0, 128));
});
test('Normalize empty name', async () => {
const actor = {
...createRandomActor(),
name: '',
};
test('Actor', async () => {
resolver._register(actor.id, actor);
const user = await personService.createPerson(actor.id, resolver);
assert.deepStrictEqual(user.name, actor.name.substr(0, 128));
assert.strictEqual(user.name, null);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment