summaryrefslogtreecommitdiff
path: root/src/remote/activitypub
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-07-26 17:13:55 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-07-26 17:13:55 +0900
commitdddd760efd3e3da5be68493d065c7adf11bdba63 (patch)
tree43951da22742a63897de4ce75a2a0a46ba9f973c /src/remote/activitypub
parentFix bug (diff)
downloadsharkey-dddd760efd3e3da5be68493d065c7adf11bdba63.tar.gz
sharkey-dddd760efd3e3da5be68493d065c7adf11bdba63.tar.bz2
sharkey-dddd760efd3e3da5be68493d065c7adf11bdba63.zip
Fix bug
Diffstat (limited to 'src/remote/activitypub')
-rw-r--r--src/remote/activitypub/models/person.ts62
1 files changed, 35 insertions, 27 deletions
diff --git a/src/remote/activitypub/models/person.ts b/src/remote/activitypub/models/person.ts
index 4ff8d23be7..c292d02419 100644
--- a/src/remote/activitypub/models/person.ts
+++ b/src/remote/activitypub/models/person.ts
@@ -14,6 +14,34 @@ import htmlToMFM from '../../../mfm/html-to-mfm';
const log = debug('misskey:activitypub');
+function validatePerson(x: any) {
+ if (x == null) {
+ return new Error('invalid person: object is null');
+ }
+
+ if (x.type != 'Person' && x.type != 'Service') {
+ return new Error(`invalid person: object is not a person or service '${x.type}'`);
+ }
+
+ if (typeof x.preferredUsername !== 'string') {
+ return new Error('invalid person: preferredUsername is not a string');
+ }
+
+ if (typeof x.inbox !== 'string') {
+ return new Error('invalid person: inbox is not a string');
+ }
+
+ if (!validateUsername(x.preferredUsername)) {
+ return new Error('invalid person: invalid username');
+ }
+
+ if (!isValidName(x.name == '' ? null : x.name)) {
+ return new Error('invalid person: invalid name');
+ }
+
+ return null;
+}
+
/**
* Personをフェッチします。
*
@@ -47,28 +75,10 @@ export async function createPerson(value: any, resolver?: Resolver): Promise<IUs
const object = await resolver.resolve(value) as any;
- if (object == null) {
- throw new Error('invalid person: object is null');
- }
-
- if (object.type != 'Person' && object.type != 'Service') {
- throw new Error(`invalid person: object is not a person or service '${object.type}'`);
- }
-
- if (typeof object.preferredUsername !== 'string') {
- throw new Error('invalid person: preferredUsername is not a string');
- }
-
- if (typeof object.inbox !== 'string') {
- throw new Error('invalid person: inbox is not a string');
- }
+ const err = validatePerson(object);
- if (!validateUsername(object.preferredUsername)) {
- throw new Error('invalid person: invalid username');
- }
-
- if (!isValidName(object.name == '' ? null : object.name)) {
- throw new Error('invalid person: invalid name');
+ if (err) {
+ throw err;
}
const person: IPerson = object;
@@ -198,12 +208,10 @@ export async function updatePerson(value: string | IObject, resolver?: Resolver)
const object = await resolver.resolve(value) as any;
- if (
- object == null ||
- object.type !== 'Person'
- ) {
- log(`invalid person: ${JSON.stringify(object, null, 2)}`);
- throw new Error('invalid person');
+ const err = validatePerson(object);
+
+ if (err) {
+ throw err;
}
const person: IPerson = object;