2017-11-09 10:51:58 -06:00
|
|
|
import * as validator from 'validator'
|
2017-11-14 03:57:56 -06:00
|
|
|
import { CONSTRAINTS_FIELDS } from '../../../initializers/constants'
|
2017-11-14 10:31:26 -06:00
|
|
|
import { isAccountNameValid } from '../accounts'
|
|
|
|
import { exists, isUUIDValid } from '../misc'
|
|
|
|
import { isActivityPubUrlValid, isBaseActivityValid } from './misc'
|
2017-11-09 10:51:58 -06:00
|
|
|
|
|
|
|
function isAccountEndpointsObjectValid (endpointObject: any) {
|
|
|
|
return isAccountSharedInboxValid(endpointObject.sharedInbox)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountSharedInboxValid (sharedInbox: string) {
|
|
|
|
return isActivityPubUrlValid(sharedInbox)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPublicKeyObjectValid (publicKeyObject: any) {
|
|
|
|
return isAccountPublicKeyIdValid(publicKeyObject.id) &&
|
|
|
|
isAccountPublicKeyOwnerValid(publicKeyObject.owner) &&
|
|
|
|
isAccountPublicKeyValid(publicKeyObject.publicKeyPem)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPublicKeyIdValid (id: string) {
|
|
|
|
return isActivityPubUrlValid(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountTypeValid (type: string) {
|
|
|
|
return type === 'Person' || type === 'Application'
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPublicKeyOwnerValid (owner: string) {
|
|
|
|
return isActivityPubUrlValid(owner)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPublicKeyValid (publicKey: string) {
|
|
|
|
return exists(publicKey) &&
|
|
|
|
typeof publicKey === 'string' &&
|
|
|
|
publicKey.startsWith('-----BEGIN PUBLIC KEY-----') &&
|
2017-11-14 03:57:56 -06:00
|
|
|
publicKey.endsWith('-----END PUBLIC KEY-----') &&
|
|
|
|
validator.isLength(publicKey, CONSTRAINTS_FIELDS.ACCOUNTS.PUBLIC_KEY)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountIdValid (id: string) {
|
|
|
|
return isActivityPubUrlValid(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountFollowingValid (id: string) {
|
|
|
|
return isActivityPubUrlValid(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountFollowersValid (id: string) {
|
|
|
|
return isActivityPubUrlValid(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountInboxValid (inbox: string) {
|
|
|
|
return isActivityPubUrlValid(inbox)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountOutboxValid (outbox: string) {
|
|
|
|
return isActivityPubUrlValid(outbox)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPreferredUsernameValid (preferredUsername: string) {
|
|
|
|
return isAccountNameValid(preferredUsername)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountUrlValid (url: string) {
|
|
|
|
return isActivityPubUrlValid(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountPrivateKeyValid (privateKey: string) {
|
|
|
|
return exists(privateKey) &&
|
|
|
|
typeof privateKey === 'string' &&
|
|
|
|
privateKey.startsWith('-----BEGIN RSA PRIVATE KEY-----') &&
|
2017-11-14 03:57:56 -06:00
|
|
|
privateKey.endsWith('-----END RSA PRIVATE KEY-----') &&
|
|
|
|
validator.isLength(privateKey, CONSTRAINTS_FIELDS.ACCOUNTS.PRIVATE_KEY)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isRemoteAccountValid (remoteAccount: any) {
|
|
|
|
return isAccountIdValid(remoteAccount.id) &&
|
|
|
|
isUUIDValid(remoteAccount.uuid) &&
|
|
|
|
isAccountTypeValid(remoteAccount.type) &&
|
|
|
|
isAccountFollowingValid(remoteAccount.following) &&
|
|
|
|
isAccountFollowersValid(remoteAccount.followers) &&
|
|
|
|
isAccountInboxValid(remoteAccount.inbox) &&
|
|
|
|
isAccountOutboxValid(remoteAccount.outbox) &&
|
|
|
|
isAccountPreferredUsernameValid(remoteAccount.preferredUsername) &&
|
|
|
|
isAccountUrlValid(remoteAccount.url) &&
|
|
|
|
isAccountPublicKeyObjectValid(remoteAccount.publicKey) &&
|
2017-11-14 10:31:26 -06:00
|
|
|
isAccountEndpointsObjectValid(remoteAccount.endpoints)
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountFollowingCountValid (value: string) {
|
|
|
|
return exists(value) && validator.isInt('' + value, { min: 0 })
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountFollowersCountValid (value: string) {
|
|
|
|
return exists(value) && validator.isInt('' + value, { min: 0 })
|
|
|
|
}
|
|
|
|
|
2017-11-14 10:31:26 -06:00
|
|
|
function isAccountDeleteActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Delete')
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountFollowActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Follow') &&
|
|
|
|
isActivityPubUrlValid(activity.object)
|
|
|
|
}
|
|
|
|
|
|
|
|
function isAccountAcceptActivityValid (activity: any) {
|
|
|
|
return isBaseActivityValid(activity, 'Accept')
|
|
|
|
}
|
|
|
|
|
2017-11-09 10:51:58 -06:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
isAccountEndpointsObjectValid,
|
|
|
|
isAccountSharedInboxValid,
|
|
|
|
isAccountPublicKeyObjectValid,
|
|
|
|
isAccountPublicKeyIdValid,
|
|
|
|
isAccountTypeValid,
|
|
|
|
isAccountPublicKeyOwnerValid,
|
|
|
|
isAccountPublicKeyValid,
|
|
|
|
isAccountIdValid,
|
|
|
|
isAccountFollowingValid,
|
|
|
|
isAccountFollowersValid,
|
|
|
|
isAccountInboxValid,
|
|
|
|
isAccountOutboxValid,
|
|
|
|
isAccountPreferredUsernameValid,
|
|
|
|
isAccountUrlValid,
|
|
|
|
isAccountPrivateKeyValid,
|
|
|
|
isRemoteAccountValid,
|
|
|
|
isAccountFollowingCountValid,
|
|
|
|
isAccountFollowersCountValid,
|
2017-11-14 10:31:26 -06:00
|
|
|
isAccountNameValid,
|
|
|
|
isAccountFollowActivityValid,
|
|
|
|
isAccountAcceptActivityValid,
|
|
|
|
isAccountDeleteActivityValid
|
2017-11-09 10:51:58 -06:00
|
|
|
}
|