From c55e3d7227fe1453869e309025996b9d75256d5d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 17 Dec 2021 11:58:15 +0100 Subject: Move test functions outside extra-utils --- server/controllers/api/users/token.ts | 2 +- server/controllers/api/video-playlist.ts | 2 +- server/controllers/api/videos/live.ts | 2 +- server/controllers/api/videos/upload.ts | 3 +- server/helpers/custom-validators/misc.ts | 2 +- server/helpers/image-utils.ts | 3 +- server/helpers/peertube-crypto.ts | 2 +- server/helpers/utils.ts | 2 +- server/helpers/webtorrent.ts | 2 +- server/initializers/constants.ts | 3 +- .../initializers/migrations/0080-video-channels.ts | 2 +- .../migrations/0345-video-playlists.ts | 2 +- .../migrations/0560-user-feed-token.ts | 2 +- .../actors/shared/object-to-model-attributes.ts | 3 +- server/lib/auth/oauth.ts | 2 +- server/lib/client-html.ts | 2 +- server/lib/hls.ts | 2 +- server/lib/local-actor.ts | 3 +- server/lib/paths.ts | 3 +- server/lib/user.ts | 2 +- server/lib/video-path-manager.ts | 2 +- server/models/user/user-notification.ts | 2 +- .../models/video/formatter/video-format-utils.ts | 2 +- server/models/video/video-caption.ts | 2 +- server/models/video/video-playlist.ts | 3 +- server/models/video/video-streaming-playlist.ts | 2 +- server/models/video/video.ts | 3 +- server/tests/api/activitypub/cleaner.ts | 2 +- server/tests/api/activitypub/fetch.ts | 9 +- server/tests/api/activitypub/helpers.ts | 3 +- server/tests/api/activitypub/refresher.ts | 4 +- server/tests/api/activitypub/security.ts | 3 +- server/tests/api/check-params/abuses.ts | 6 +- server/tests/api/check-params/accounts.ts | 10 +- server/tests/api/check-params/blocklist.ts | 6 +- server/tests/api/check-params/contact-form.ts | 10 +- server/tests/api/check-params/follows.ts | 6 +- server/tests/api/check-params/jobs.ts | 12 +- server/tests/api/check-params/live.ts | 4 +- server/tests/api/check-params/my-user.ts | 9 +- server/tests/api/check-params/plugins.ts | 6 +- server/tests/api/check-params/redundancy.ts | 6 +- server/tests/api/check-params/search.ts | 12 +- server/tests/api/check-params/transcoding.ts | 9 +- server/tests/api/check-params/upload-quota.ts | 4 +- .../tests/api/check-params/user-notifications.ts | 10 +- .../tests/api/check-params/user-subscriptions.ts | 4 +- server/tests/api/check-params/users-admin.ts | 7 +- server/tests/api/check-params/users.ts | 10 +- server/tests/api/check-params/video-blacklist.ts | 6 +- server/tests/api/check-params/video-captions.ts | 4 +- server/tests/api/check-params/video-channels.ts | 8 +- server/tests/api/check-params/video-comments.ts | 6 +- server/tests/api/check-params/video-files.ts | 9 +- server/tests/api/check-params/video-imports.ts | 9 +- server/tests/api/check-params/video-playlists.ts | 22 +- server/tests/api/check-params/videos-history.ts | 5 +- server/tests/api/check-params/videos.ts | 10 +- server/tests/api/live/live-constraints.ts | 6 +- server/tests/api/live/live-permanent.ts | 4 +- server/tests/api/live/live-rtmps.ts | 4 +- server/tests/api/live/live-save-replay.ts | 6 +- server/tests/api/live/live-socket-messages.ts | 4 +- server/tests/api/live/live-views.ts | 4 +- server/tests/api/live/live.ts | 25 +- .../tests/api/moderation/blocklist-notification.ts | 9 +- server/tests/api/moderation/video-blacklist.ts | 4 +- .../tests/api/notifications/admin-notifications.ts | 9 +- .../api/notifications/comments-notifications.ts | 8 +- .../api/notifications/moderation-notifications.ts | 11 +- .../tests/api/notifications/notifications-api.ts | 8 +- .../tests/api/notifications/user-notifications.ts | 11 +- server/tests/api/object-storage/live.ts | 6 +- server/tests/api/object-storage/video-imports.ts | 7 +- server/tests/api/object-storage/videos.ts | 9 +- .../tests/api/redundancy/redundancy-constraints.ts | 9 +- server/tests/api/redundancy/redundancy.ts | 23 +- .../search/search-activitypub-video-channels.ts | 4 +- .../search/search-activitypub-video-playlists.ts | 4 +- .../tests/api/search/search-activitypub-videos.ts | 4 +- server/tests/api/search/search-videos.ts | 4 +- server/tests/api/server/auto-follows.ts | 12 +- server/tests/api/server/config-defaults.ts | 10 +- server/tests/api/server/config.ts | 4 +- server/tests/api/server/contact-form.ts | 6 +- server/tests/api/server/email.ts | 3 +- server/tests/api/server/follows.ts | 14 +- server/tests/api/server/handle-down.ts | 6 +- server/tests/api/server/jobs.ts | 2 +- server/tests/api/server/plugins.ts | 8 +- server/tests/api/server/proxy.ts | 5 +- server/tests/api/server/reverse-proxy.ts | 3 +- server/tests/api/server/slow-follows.ts | 9 +- server/tests/api/server/stats.ts | 4 +- server/tests/api/users/users-multiple-servers.ts | 8 +- server/tests/api/users/users-verification.ts | 3 +- server/tests/api/users/users.ts | 4 +- server/tests/api/videos/audio-only.ts | 9 +- server/tests/api/videos/multiple-servers.ts | 15 +- server/tests/api/videos/resumable-upload.ts | 10 +- server/tests/api/videos/single-server.ts | 13 +- server/tests/api/videos/video-captions.ts | 5 +- server/tests/api/videos/video-channels.ts | 7 +- server/tests/api/videos/video-comments.ts | 11 +- .../tests/api/videos/video-create-transcoding.ts | 6 +- server/tests/api/videos/video-description.ts | 9 +- server/tests/api/videos/video-files.ts | 9 +- server/tests/api/videos/video-hls.ts | 11 +- server/tests/api/videos/video-imports.ts | 8 +- .../tests/api/videos/video-playlist-thumbnails.ts | 6 +- server/tests/api/videos/video-playlists.ts | 23 +- server/tests/api/videos/video-privacy.ts | 11 +- server/tests/api/videos/video-schedule-update.ts | 4 +- server/tests/api/videos/video-transcoder.ts | 18 +- server/tests/api/videos/videos-history.ts | 6 +- server/tests/api/videos/videos-overview.ts | 3 +- server/tests/api/videos/videos-views-cleaner.ts | 4 +- server/tests/cli/create-import-video-file-job.ts | 6 +- server/tests/cli/create-move-video-storage-job.ts | 7 +- server/tests/cli/create-transcoding-job.ts | 6 +- server/tests/cli/peertube.ts | 8 +- server/tests/cli/plugins.ts | 2 +- server/tests/cli/print-transcode-command.ts | 3 +- server/tests/cli/prune-storage.ts | 5 +- server/tests/cli/reset-password.ts | 2 +- server/tests/external-plugins/auto-block-videos.ts | 8 +- server/tests/external-plugins/auto-mute.ts | 8 +- server/tests/helpers/image.ts | 2 +- server/tests/helpers/request.ts | 4 +- server/tests/plugins/external-auth.ts | 6 +- server/tests/plugins/filter-hooks.ts | 4 +- server/tests/plugins/html-injection.ts | 2 +- server/tests/plugins/id-and-pass-auth.ts | 3 +- server/tests/plugins/plugin-helpers.ts | 4 +- server/tests/shared/actors.ts | 73 ++ server/tests/shared/captions.ts | 21 + server/tests/shared/checks.ts | 98 +++ server/tests/shared/directories.ts | 34 + server/tests/shared/generate.ts | 74 ++ server/tests/shared/index.ts | 15 +- server/tests/shared/live.ts | 41 ++ server/tests/shared/mock-servers/index.ts | 7 + server/tests/shared/mock-servers/mock-429.ts | 33 + server/tests/shared/mock-servers/mock-email.ts | 62 ++ .../shared/mock-servers/mock-instances-index.ts | 46 ++ .../mock-servers/mock-joinpeertube-versions.ts | 34 + .../shared/mock-servers/mock-object-storage.ts | 41 ++ .../shared/mock-servers/mock-plugin-blocklist.ts | 36 + server/tests/shared/mock-servers/mock-proxy.ts | 24 + server/tests/shared/mock-servers/shared.ts | 33 + server/tests/shared/notifications.ts | 798 +++++++++++++++++++++ server/tests/shared/playlists.ts | 25 + server/tests/shared/plugins.ts | 18 + server/tests/shared/requests.ts | 12 +- server/tests/shared/streaming-playlists.ts | 77 ++ server/tests/shared/tests.ts | 37 + server/tests/shared/tracker.ts | 27 + server/tests/shared/video.ts | 150 ---- server/tests/shared/videos.ts | 251 +++++++ shared/core-utils/common/array.ts | 13 + shared/core-utils/common/crypto.ts | 20 + shared/core-utils/common/env.ts | 30 + shared/core-utils/common/index.ts | 8 +- shared/core-utils/common/miscs.ts | 41 -- shared/core-utils/common/object.ts | 30 + shared/core-utils/common/path.ts | 46 ++ shared/core-utils/common/time.ts | 7 + shared/core-utils/common/version.ts | 20 + shared/core-utils/crypto.ts | 14 - shared/core-utils/index.ts | 3 - shared/core-utils/path.ts | 34 - shared/core-utils/utils/array.ts | 13 - shared/core-utils/utils/index.ts | 2 - shared/core-utils/utils/object.ts | 15 - shared/core-utils/uuid.ts | 32 - shared/core-utils/videos/index.ts | 1 + shared/core-utils/videos/uuid.ts | 32 + shared/extra-utils/file.ts | 11 + shared/extra-utils/index.ts | 1 + shared/models/users/index.ts | 1 + shared/server-commands/index.ts | 1 - shared/server-commands/logs/logs-command.ts | 3 +- shared/server-commands/miscs/checks.ts | 58 -- shared/server-commands/miscs/generate.ts | 75 -- shared/server-commands/miscs/index.ts | 3 - shared/server-commands/miscs/sql-command.ts | 2 +- shared/server-commands/miscs/tests.ts | 101 --- shared/server-commands/mock-servers/index.ts | 5 - shared/server-commands/mock-servers/mock-429.ts | 33 - shared/server-commands/mock-servers/mock-email.ts | 63 -- .../mock-servers/mock-instances-index.ts | 46 -- .../mock-servers/mock-joinpeertube-versions.ts | 34 - .../mock-servers/mock-object-storage.ts | 41 -- .../mock-servers/mock-plugin-blocklist.ts | 36 - shared/server-commands/mock-servers/mock-proxy.ts | 25 - shared/server-commands/mock-servers/utils.ts | 33 - .../server-commands/requests/check-api-params.ts | 48 -- shared/server-commands/requests/index.ts | 2 - shared/server-commands/requests/requests.ts | 2 +- shared/server-commands/server/config-command.ts | 5 +- shared/server-commands/server/directories.ts | 34 - shared/server-commands/server/index.ts | 3 - shared/server-commands/server/jobs-command.ts | 3 +- shared/server-commands/server/jobs.ts | 2 +- shared/server-commands/server/plugins.ts | 18 - shared/server-commands/server/server.ts | 8 +- shared/server-commands/server/servers-command.ts | 4 +- shared/server-commands/server/servers.ts | 2 +- shared/server-commands/server/tracker.ts | 27 - shared/server-commands/shared/abstract-command.ts | 2 +- shared/server-commands/users/accounts-command.ts | 4 +- shared/server-commands/users/actors.ts | 73 -- shared/server-commands/users/index.ts | 2 - .../server-commands/users/notifications-command.ts | 3 +- shared/server-commands/users/notifications.ts | 795 -------------------- shared/server-commands/users/users-command.ts | 2 +- shared/server-commands/videos/blacklist-command.ts | 3 +- shared/server-commands/videos/captions-command.ts | 2 +- shared/server-commands/videos/captions.ts | 21 - shared/server-commands/videos/channels-command.ts | 12 +- shared/server-commands/videos/index.ts | 4 - shared/server-commands/videos/live-command.ts | 2 +- shared/server-commands/videos/live.ts | 41 +- shared/server-commands/videos/playlists.ts | 25 - .../server-commands/videos/streaming-playlists.ts | 77 -- shared/server-commands/videos/videos-command.ts | 4 +- shared/server-commands/videos/videos.ts | 104 --- 227 files changed, 2541 insertions(+), 2638 deletions(-) create mode 100644 server/tests/shared/actors.ts create mode 100644 server/tests/shared/captions.ts create mode 100644 server/tests/shared/checks.ts create mode 100644 server/tests/shared/directories.ts create mode 100644 server/tests/shared/generate.ts create mode 100644 server/tests/shared/live.ts create mode 100644 server/tests/shared/mock-servers/index.ts create mode 100644 server/tests/shared/mock-servers/mock-429.ts create mode 100644 server/tests/shared/mock-servers/mock-email.ts create mode 100644 server/tests/shared/mock-servers/mock-instances-index.ts create mode 100644 server/tests/shared/mock-servers/mock-joinpeertube-versions.ts create mode 100644 server/tests/shared/mock-servers/mock-object-storage.ts create mode 100644 server/tests/shared/mock-servers/mock-plugin-blocklist.ts create mode 100644 server/tests/shared/mock-servers/mock-proxy.ts create mode 100644 server/tests/shared/mock-servers/shared.ts create mode 100644 server/tests/shared/notifications.ts create mode 100644 server/tests/shared/playlists.ts create mode 100644 server/tests/shared/plugins.ts create mode 100644 server/tests/shared/streaming-playlists.ts create mode 100644 server/tests/shared/tests.ts create mode 100644 server/tests/shared/tracker.ts delete mode 100644 server/tests/shared/video.ts create mode 100644 server/tests/shared/videos.ts create mode 100644 shared/core-utils/common/array.ts create mode 100644 shared/core-utils/common/crypto.ts create mode 100644 shared/core-utils/common/env.ts delete mode 100644 shared/core-utils/common/miscs.ts create mode 100644 shared/core-utils/common/object.ts create mode 100644 shared/core-utils/common/path.ts create mode 100644 shared/core-utils/common/time.ts create mode 100644 shared/core-utils/common/version.ts delete mode 100644 shared/core-utils/crypto.ts delete mode 100644 shared/core-utils/path.ts delete mode 100644 shared/core-utils/utils/array.ts delete mode 100644 shared/core-utils/utils/index.ts delete mode 100644 shared/core-utils/utils/object.ts delete mode 100644 shared/core-utils/uuid.ts create mode 100644 shared/core-utils/videos/uuid.ts create mode 100644 shared/extra-utils/file.ts delete mode 100644 shared/server-commands/miscs/checks.ts delete mode 100644 shared/server-commands/miscs/generate.ts delete mode 100644 shared/server-commands/miscs/tests.ts delete mode 100644 shared/server-commands/mock-servers/index.ts delete mode 100644 shared/server-commands/mock-servers/mock-429.ts delete mode 100644 shared/server-commands/mock-servers/mock-email.ts delete mode 100644 shared/server-commands/mock-servers/mock-instances-index.ts delete mode 100644 shared/server-commands/mock-servers/mock-joinpeertube-versions.ts delete mode 100644 shared/server-commands/mock-servers/mock-object-storage.ts delete mode 100644 shared/server-commands/mock-servers/mock-plugin-blocklist.ts delete mode 100644 shared/server-commands/mock-servers/mock-proxy.ts delete mode 100644 shared/server-commands/mock-servers/utils.ts delete mode 100644 shared/server-commands/requests/check-api-params.ts delete mode 100644 shared/server-commands/server/directories.ts delete mode 100644 shared/server-commands/server/plugins.ts delete mode 100644 shared/server-commands/server/tracker.ts delete mode 100644 shared/server-commands/users/actors.ts delete mode 100644 shared/server-commands/users/notifications.ts delete mode 100644 shared/server-commands/videos/captions.ts delete mode 100644 shared/server-commands/videos/playlists.ts delete mode 100644 shared/server-commands/videos/streaming-playlists.ts delete mode 100644 shared/server-commands/videos/videos.ts diff --git a/server/controllers/api/users/token.ts b/server/controllers/api/users/token.ts index 42f4f6096..5ada4a805 100644 --- a/server/controllers/api/users/token.ts +++ b/server/controllers/api/users/token.ts @@ -1,13 +1,13 @@ import express from 'express' import RateLimit from 'express-rate-limit' import { logger } from '@server/helpers/logger' -import { buildUUID } from '@shared/core-utils/uuid' import { CONFIG } from '@server/initializers/config' import { getAuthNameFromRefreshGrant, getBypassFromExternalAuth, getBypassFromPasswordGrant } from '@server/lib/auth/external-auth' import { handleOAuthToken } from '@server/lib/auth/oauth' import { BypassLogin, revokeToken } from '@server/lib/auth/oauth-model' import { Hooks } from '@server/lib/plugins/hooks' import { asyncMiddleware, authenticate, openapiOperationDoc } from '@server/middlewares' +import { buildUUID } from '@shared/core-utils' import { ScopedToken } from '@shared/models/users/user-scoped-token' const tokensRouter = express.Router() diff --git a/server/controllers/api/video-playlist.ts b/server/controllers/api/video-playlist.ts index f8f07b1c6..dc1947764 100644 --- a/server/controllers/api/video-playlist.ts +++ b/server/controllers/api/video-playlist.ts @@ -1,10 +1,10 @@ import express from 'express' import { join } from 'path' -import { uuidToShort } from '@shared/core-utils/uuid' import { scheduleRefreshIfNeeded } from '@server/lib/activitypub/playlists' import { Hooks } from '@server/lib/plugins/hooks' import { getServerActor } from '@server/models/application/application' import { MVideoPlaylistFull, MVideoPlaylistThumbnail, MVideoThumbnail } from '@server/types/models' +import { uuidToShort } from '@shared/core-utils' import { VideoPlaylistCreateResult, VideoPlaylistElementCreateResult } from '@shared/models' import { HttpStatusCode } from '../../../shared/models/http/http-error-codes' import { VideoPlaylistCreate } from '../../../shared/models/videos/playlist/video-playlist-create.model' diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts index e466d041b..4ee39aa4f 100644 --- a/server/controllers/api/videos/live.ts +++ b/server/controllers/api/videos/live.ts @@ -1,6 +1,5 @@ import express from 'express' import { createReqFiles } from '@server/helpers/express-utils' -import { buildUUID, uuidToShort } from '@shared/core-utils/uuid' import { CONFIG } from '@server/initializers/config' import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' @@ -10,6 +9,7 @@ import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } fro import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live' import { VideoLiveModel } from '@server/models/video/video-live' import { MVideoDetails, MVideoFullLight } from '@server/types/models' +import { buildUUID, uuidToShort } from '@shared/core-utils' import { LiveVideoCreate, LiveVideoUpdate, VideoState } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/models/http/http-error-codes' import { logger } from '../../../helpers/logger' diff --git a/server/controllers/api/videos/upload.ts b/server/controllers/api/videos/upload.ts index a4d0f980f..9f620c04d 100644 --- a/server/controllers/api/videos/upload.ts +++ b/server/controllers/api/videos/upload.ts @@ -1,9 +1,7 @@ import express from 'express' import { move } from 'fs-extra' import { basename } from 'path' -import { getLowercaseExtension } from '@shared/core-utils' import { getResumableUploadPath } from '@server/helpers/upload' -import { uuidToShort } from '@shared/core-utils/uuid' import { createTorrentAndSetInfoHash } from '@server/helpers/webtorrent' import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' import { generateWebTorrentVideoFilename } from '@server/lib/paths' @@ -20,6 +18,7 @@ import { VideoPathManager } from '@server/lib/video-path-manager' import { buildNextVideoState } from '@server/lib/video-state' import { openapiOperationDoc } from '@server/middlewares/doc' import { MVideo, MVideoFile, MVideoFullLight } from '@server/types/models' +import { getLowercaseExtension, uuidToShort } from '@shared/core-utils' import { VideoCreate, VideoState } from '../../../../shared' import { HttpStatusCode } from '../../../../shared/models' import { auditLoggerFactory, getAuditIdFromRes, VideoAuditView } from '../../../helpers/audit-logger' diff --git a/server/helpers/custom-validators/misc.ts b/server/helpers/custom-validators/misc.ts index eaabdbbea..65578c143 100644 --- a/server/helpers/custom-validators/misc.ts +++ b/server/helpers/custom-validators/misc.ts @@ -2,7 +2,7 @@ import 'multer' import { UploadFilesForCheck } from 'express' import { sep } from 'path' import validator from 'validator' -import { isShortUUID, shortToUUID } from '@shared/core-utils/uuid' +import { isShortUUID, shortToUUID } from '@shared/core-utils' function exists (value: any) { return value !== undefined && value !== null diff --git a/server/helpers/image-utils.ts b/server/helpers/image-utils.ts index ced288045..c4704b189 100644 --- a/server/helpers/image-utils.ts +++ b/server/helpers/image-utils.ts @@ -1,9 +1,8 @@ import { copy, readFile, remove, rename } from 'fs-extra' import Jimp, { read } from 'jimp' -import { getLowercaseExtension } from '@shared/core-utils' +import { buildUUID, getLowercaseExtension } from '@shared/core-utils' import { convertWebPToJPG, processGIF } from './ffmpeg-utils' import { logger } from './logger' -import { buildUUID } from '@shared/core-utils/uuid' function generateImageFilename (extension = '.jpg') { return buildUUID() + extension diff --git a/server/helpers/peertube-crypto.ts b/server/helpers/peertube-crypto.ts index 31705e7fa..66a353204 100644 --- a/server/helpers/peertube-crypto.ts +++ b/server/helpers/peertube-crypto.ts @@ -4,7 +4,7 @@ import { Request } from 'express' import { cloneDeep } from 'lodash' import { BCRYPT_SALT_SIZE, HTTP_SIGNATURE, PRIVATE_RSA_KEY_SIZE } from '../initializers/constants' import { MActor } from '../types/models' -import { sha256 } from '@shared/core-utils/crypto' +import { sha256 } from '@shared/core-utils/common/crypto' import { createPrivateKey, getPublicKey, promisify1, promisify2 } from './core-utils' import { jsonld } from './custom-jsonld-signature' import { logger } from './logger' diff --git a/server/helpers/utils.ts b/server/helpers/utils.ts index 882f808ab..d6a3dae95 100644 --- a/server/helpers/utils.ts +++ b/server/helpers/utils.ts @@ -3,7 +3,7 @@ import { Instance as ParseTorrent } from 'parse-torrent' import { join } from 'path' import { ResultList } from '../../shared' import { CONFIG } from '../initializers/config' -import { sha256 } from '@shared/core-utils/crypto' +import { sha256 } from '@shared/core-utils/common/crypto' import { execPromise, execPromise2, randomBytesPromise } from './core-utils' import { logger } from './logger' diff --git a/server/helpers/webtorrent.ts b/server/helpers/webtorrent.ts index 67cb3971d..03663d73c 100644 --- a/server/helpers/webtorrent.ts +++ b/server/helpers/webtorrent.ts @@ -15,7 +15,7 @@ import { MVideoFile, MVideoFileRedundanciesOpt } from '@server/types/models/vide import { MStreamingPlaylistVideo } from '@server/types/models/video/video-streaming-playlist' import { CONFIG } from '../initializers/config' import { promisify2 } from './core-utils' -import { sha1 } from '@shared/core-utils/crypto' +import { sha1 } from '@shared/core-utils/common/crypto' import { logger } from './logger' import { generateVideoImportTmpPath } from './utils' import { extractVideo } from './video' diff --git a/server/initializers/constants.ts b/server/initializers/constants.ts index 258ccdb51..57f7af789 100644 --- a/server/initializers/constants.ts +++ b/server/initializers/constants.ts @@ -2,7 +2,7 @@ import { CronRepeatOptions, EveryRepeatOptions } from 'bull' import { randomBytes } from 'crypto' import { invert } from 'lodash' import { join } from 'path' -import { randomInt } from '../../shared/core-utils/common/miscs' +import { randomInt, root } from '@shared/core-utils' import { AbuseState, JobType, @@ -18,7 +18,6 @@ import { FollowState } from '../../shared/models/actors' import { NSFWPolicyType } from '../../shared/models/videos/nsfw-policy.type' import { VideoPlaylistPrivacy } from '../../shared/models/videos/playlist/video-playlist-privacy.model' import { VideoPlaylistType } from '../../shared/models/videos/playlist/video-playlist-type.model' -import { root } from '../../shared/core-utils' // Do not use barrels, remain constants as independent as possible import { isTestInstance, sanitizeHost, sanitizeUrl } from '../helpers/core-utils' import { CONFIG, registerConfigChangedHandler } from './config' diff --git a/server/initializers/migrations/0080-video-channels.ts b/server/initializers/migrations/0080-video-channels.ts index 82971c9f5..221475bb1 100644 --- a/server/initializers/migrations/0080-video-channels.ts +++ b/server/initializers/migrations/0080-video-channels.ts @@ -1,4 +1,4 @@ -import { buildUUID } from '@shared/core-utils/uuid' +import { buildUUID } from '@shared/core-utils' import * as Sequelize from 'sequelize' async function up (utils: { diff --git a/server/initializers/migrations/0345-video-playlists.ts b/server/initializers/migrations/0345-video-playlists.ts index 5cc52e7ee..fb27c9301 100644 --- a/server/initializers/migrations/0345-video-playlists.ts +++ b/server/initializers/migrations/0345-video-playlists.ts @@ -1,5 +1,5 @@ import * as Sequelize from 'sequelize' -import { buildUUID } from '@shared/core-utils/uuid' +import { buildUUID } from '@shared/core-utils' import { VideoPlaylistPrivacy, VideoPlaylistType } from '../../../shared/models/videos' import { WEBSERVER } from '../constants' diff --git a/server/initializers/migrations/0560-user-feed-token.ts b/server/initializers/migrations/0560-user-feed-token.ts index 961777e35..4ed4d9681 100644 --- a/server/initializers/migrations/0560-user-feed-token.ts +++ b/server/initializers/migrations/0560-user-feed-token.ts @@ -1,5 +1,5 @@ import * as Sequelize from 'sequelize' -import { buildUUID } from '@shared/core-utils/uuid' +import { buildUUID } from '@shared/core-utils' async function up (utils: { transaction: Sequelize.Transaction diff --git a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts index 1ad89ac56..38d93c108 100644 --- a/server/lib/activitypub/actors/shared/object-to-model-attributes.ts +++ b/server/lib/activitypub/actors/shared/object-to-model-attributes.ts @@ -1,9 +1,8 @@ -import { getLowercaseExtension } from '@shared/core-utils' import { isActivityPubUrlValid } from '@server/helpers/custom-validators/activitypub/misc' -import { buildUUID } from '@shared/core-utils/uuid' import { MIMETYPES } from '@server/initializers/constants' import { ActorModel } from '@server/models/actor/actor' import { FilteredModelAttributes } from '@server/types' +import { buildUUID, getLowercaseExtension } from '@shared/core-utils' import { ActivityPubActor, ActorImageType } from '@shared/models' function getActorAttributesFromObject ( diff --git a/server/lib/auth/oauth.ts b/server/lib/auth/oauth.ts index 47bc8c055..dc0022852 100644 --- a/server/lib/auth/oauth.ts +++ b/server/lib/auth/oauth.ts @@ -8,7 +8,7 @@ import { UnauthorizedClientError, UnsupportedGrantTypeError } from 'oauth2-server' -import { sha1 } from '@shared/core-utils/crypto' +import { sha1 } from '@shared/core-utils/common/crypto' import { randomBytesPromise } from '@server/helpers/core-utils' import { MOAuthClient } from '@server/types/models' import { OAUTH_LIFETIME } from '../../initializers/constants' diff --git a/server/lib/client-html.ts b/server/lib/client-html.ts index dee7ca8ed..91708839b 100644 --- a/server/lib/client-html.ts +++ b/server/lib/client-html.ts @@ -9,7 +9,7 @@ import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from import { HttpStatusCode } from '../../shared/models/http/http-error-codes' import { VideoPlaylistPrivacy, VideoPrivacy } from '../../shared/models/videos' import { isTestInstance } from '../helpers/core-utils' -import { sha256 } from '@shared/core-utils/crypto' +import { sha256 } from '@shared/core-utils/common/crypto' import { logger } from '../helpers/logger' import { mdToPlainText } from '../helpers/markdown' import { CONFIG } from '../initializers/config' diff --git a/server/lib/hls.ts b/server/lib/hls.ts index 220b7733b..e4904be5f 100644 --- a/server/lib/hls.ts +++ b/server/lib/hls.ts @@ -2,7 +2,7 @@ import { close, ensureDir, move, open, outputJSON, read, readFile, remove, stat, import { flatten, uniq } from 'lodash' import { basename, dirname, join } from 'path' import { MStreamingPlaylistFilesVideo, MVideo, MVideoUUID } from '@server/types/models' -import { sha256 } from '@shared/core-utils/crypto' +import { sha256 } from '@shared/core-utils/common/crypto' import { getAudioStreamCodec, getVideoStreamCodec, getVideoStreamSize } from '../helpers/ffprobe-utils' import { logger } from '../helpers/logger' import { doRequest, doRequestAndSaveToFile } from '../helpers/requests' diff --git a/server/lib/local-actor.ts b/server/lib/local-actor.ts index 572696f2a..04ad98f3e 100644 --- a/server/lib/local-actor.ts +++ b/server/lib/local-actor.ts @@ -2,9 +2,8 @@ import 'multer' import { queue } from 'async' import LRUCache from 'lru-cache' import { join } from 'path' -import { getLowercaseExtension } from '@shared/core-utils' -import { buildUUID } from '@shared/core-utils/uuid' import { ActorModel } from '@server/models/actor/actor' +import { buildUUID, getLowercaseExtension } from '@shared/core-utils' import { ActivityPubActorType, ActorImageType } from '@shared/models' import { retryTransactionWrapper } from '../helpers/database-utils' import { processImage } from '../helpers/image-utils' diff --git a/server/lib/paths.ts b/server/lib/paths.ts index d8cf812e3..bf0c3a86b 100644 --- a/server/lib/paths.ts +++ b/server/lib/paths.ts @@ -1,9 +1,8 @@ import { join } from 'path' -import { buildUUID } from '@shared/core-utils/uuid' import { CONFIG } from '@server/initializers/config' import { HLS_REDUNDANCY_DIRECTORY, HLS_STREAMING_PLAYLIST_DIRECTORY } from '@server/initializers/constants' import { isStreamingPlaylist, MStreamingPlaylistVideo, MVideo, MVideoFile, MVideoUUID } from '@server/types/models' -import { removeFragmentedMP4Ext } from '@shared/core-utils' +import { buildUUID, removeFragmentedMP4Ext } from '@shared/core-utils' // ################## Video file name ################## diff --git a/server/lib/user.ts b/server/lib/user.ts index 230bf37d0..3ba0c0ca4 100644 --- a/server/lib/user.ts +++ b/server/lib/user.ts @@ -1,7 +1,7 @@ import { Transaction } from 'sequelize/types' -import { buildUUID } from '@shared/core-utils/uuid' import { UserModel } from '@server/models/user/user' import { MActorDefault } from '@server/types/models/actor' +import { buildUUID } from '@shared/core-utils' import { ActivityPubActorType } from '../../shared/models/activitypub' import { UserNotificationSetting, UserNotificationSettingValue } from '../../shared/models/users' import { SERVER_ACTOR_NAME, WEBSERVER } from '../initializers/constants' diff --git a/server/lib/video-path-manager.ts b/server/lib/video-path-manager.ts index 429b36df9..4027f885d 100644 --- a/server/lib/video-path-manager.ts +++ b/server/lib/video-path-manager.ts @@ -1,6 +1,5 @@ import { remove } from 'fs-extra' import { extname, join } from 'path' -import { buildUUID } from '@shared/core-utils/uuid' import { extractVideo } from '@server/helpers/video' import { CONFIG } from '@server/initializers/config' import { @@ -11,6 +10,7 @@ import { MVideoFileVideo, MVideoUUID } from '@server/types/models' +import { buildUUID } from '@shared/core-utils' import { VideoStorage } from '@shared/models' import { makeHLSFileAvailable, makeWebTorrentFileAvailable } from './object-storage' import { getHLSDirectory, getHLSRedundancyDirectory, getHlsResolutionPlaylistFilename } from './paths' diff --git a/server/models/user/user-notification.ts b/server/models/user/user-notification.ts index 4a9a84a5b..d71bb4d56 100644 --- a/server/models/user/user-notification.ts +++ b/server/models/user/user-notification.ts @@ -1,7 +1,7 @@ import { FindOptions, ModelIndexesOptions, Op, WhereOptions } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, Default, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' -import { uuidToShort } from '@shared/core-utils/uuid' import { UserNotificationIncludes, UserNotificationModelForApi } from '@server/types/models/user' +import { uuidToShort } from '@shared/core-utils' import { AttributesOnly } from '@shared/typescript-utils' import { UserNotification, UserNotificationType } from '../../../shared' import { isBooleanValid } from '../../helpers/custom-validators/misc' diff --git a/server/models/video/formatter/video-format-utils.ts b/server/models/video/formatter/video-format-utils.ts index f6c750ccf..99a4818ab 100644 --- a/server/models/video/formatter/video-format-utils.ts +++ b/server/models/video/formatter/video-format-utils.ts @@ -1,7 +1,7 @@ -import { uuidToShort } from '@shared/core-utils/uuid' import { generateMagnetUri } from '@server/helpers/webtorrent' import { getLocalVideoFileMetadataUrl } from '@server/lib/video-urls' import { VideoViews } from '@server/lib/video-views' +import { uuidToShort } from '@shared/core-utils' import { VideoFile, VideosCommonQueryAfterSanitize } from '@shared/models' import { ActivityTagObject, ActivityUrlObject, VideoObject } from '../../../../shared/models/activitypub/objects' import { Video, VideoDetails, VideoInclude } from '../../../../shared/models/videos' diff --git a/server/models/video/video-caption.ts b/server/models/video/video-caption.ts index 642613cfe..20741ea64 100644 --- a/server/models/video/video-caption.ts +++ b/server/models/video/video-caption.ts @@ -15,8 +15,8 @@ import { Table, UpdatedAt } from 'sequelize-typescript' -import { buildUUID } from '@shared/core-utils/uuid' import { MVideo, MVideoCaption, MVideoCaptionFormattable, MVideoCaptionVideo } from '@server/types/models' +import { buildUUID } from '@shared/core-utils' import { AttributesOnly } from '@shared/typescript-utils' import { VideoCaption } from '../../../shared/models/videos/caption/video-caption.model' import { isVideoCaptionLanguageValid } from '../../helpers/custom-validators/video-captions' diff --git a/server/models/video/video-playlist.ts b/server/models/video/video-playlist.ts index 132fa0e68..07bb64810 100644 --- a/server/models/video/video-playlist.ts +++ b/server/models/video/video-playlist.ts @@ -18,8 +18,7 @@ import { UpdatedAt } from 'sequelize-typescript' import { MAccountId, MChannelId } from '@server/types/models' -import { buildPlaylistEmbedPath, buildPlaylistWatchPath, pick } from '@shared/core-utils' -import { buildUUID, uuidToShort } from '@shared/core-utils/uuid' +import { buildPlaylistEmbedPath, buildPlaylistWatchPath, buildUUID, pick, uuidToShort } from '@shared/core-utils' import { AttributesOnly } from '@shared/typescript-utils' import { ActivityIconObject } from '../../../shared/models/activitypub/objects' import { PlaylistObject } from '../../../shared/models/activitypub/objects/playlist-object' diff --git a/server/models/video/video-streaming-playlist.ts b/server/models/video/video-streaming-playlist.ts index d813f89b5..7b410f8ee 100644 --- a/server/models/video/video-streaming-playlist.ts +++ b/server/models/video/video-streaming-playlist.ts @@ -21,7 +21,7 @@ import { MStreamingPlaylist, MVideo } from '@server/types/models' import { AttributesOnly } from '@shared/typescript-utils' import { VideoStorage } from '@shared/models' import { VideoStreamingPlaylistType } from '../../../shared/models/videos/video-streaming-playlist.type' -import { sha1 } from '@shared/core-utils/crypto' +import { sha1 } from '@shared/core-utils/common/crypto' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' import { isArrayOf } from '../../helpers/custom-validators/misc' import { isVideoFileInfoHashValid } from '../../helpers/custom-validators/videos' diff --git a/server/models/video/video.ts b/server/models/video/video.ts index a99b012b9..66a9a28fa 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts @@ -32,8 +32,7 @@ import { getHLSDirectory, getHLSRedundancyDirectory } from '@server/lib/paths' import { VideoPathManager } from '@server/lib/video-path-manager' import { getServerActor } from '@server/models/application/application' import { ModelCache } from '@server/models/model-cache' -import { buildVideoEmbedPath, buildVideoWatchPath, pick } from '@shared/core-utils' -import { uuidToShort } from '@shared/core-utils/uuid' +import { buildVideoEmbedPath, buildVideoWatchPath, pick, uuidToShort } from '@shared/core-utils' import { VideoFile, VideoInclude } from '@shared/models' import { AttributesOnly } from '@shared/typescript-utils' import { ResultList, UserRight, VideoPrivacy, VideoState } from '../../../shared' diff --git a/server/tests/api/activitypub/cleaner.ts b/server/tests/api/activitypub/cleaner.ts index c3368c7eb..7a443b553 100644 --- a/server/tests/api/activitypub/cleaner.ts +++ b/server/tests/api/activitypub/cleaner.ts @@ -2,13 +2,13 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' diff --git a/server/tests/api/activitypub/fetch.ts b/server/tests/api/activitypub/fetch.ts index 93bf01842..cc71e82ea 100644 --- a/server/tests/api/activitypub/fetch.ts +++ b/server/tests/api/activitypub/fetch.ts @@ -2,7 +2,14 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/activitypub/helpers.ts b/server/tests/api/activitypub/helpers.ts index 5aa94af5d..25e1d9823 100644 --- a/server/tests/api/activitypub/helpers.ts +++ b/server/tests/api/activitypub/helpers.ts @@ -3,7 +3,8 @@ import 'mocha' import { expect } from 'chai' import { cloneDeep } from 'lodash' -import { buildAbsoluteFixturePath, buildRequestStub } from '@shared/server-commands' +import { buildRequestStub } from '@server/tests/shared' +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { buildSignedActivity } from '../../../helpers/activitypub' import { isHTTPSignatureVerified, isJsonLDSignatureVerified, parseHTTPSignature } from '../../../helpers/peertube-crypto' diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts index 669a86fca..71e1c40ba 100644 --- a/server/tests/api/activitypub/refresher.ts +++ b/server/tests/api/activitypub/refresher.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -9,10 +11,8 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - wait, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' describe('Test AP refresher', function () { let servers: PeerTubeServer[] = [] diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index 3b871ae12..c4cb5ea0d 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -6,9 +6,10 @@ import { activityPubContextify, buildSignedActivity } from '@server/helpers/acti import { buildDigest } from '@server/helpers/peertube-crypto' import { HTTP_SIGNATURE } from '@server/initializers/constants' import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' -import { buildAbsoluteFixturePath, cleanupTests, createMultipleServers, killallServers, PeerTubeServer, wait } from '@shared/server-commands' import { makeFollowRequest, makePOSTAPRequest } from '@server/tests/shared' +import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createMultipleServers, killallServers, PeerTubeServer } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 58167cbab..c4b051723 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,11 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models' import { AbusesCommand, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, doubleFollow, @@ -15,7 +14,6 @@ import { setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts index fc8e63ed4..07f879e0e 100644 --- a/server/tests/api/check-params/accounts.ts +++ b/server/tests/api/check-params/accounts.ts @@ -1,15 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - cleanupTests, - createSingleServer, - PeerTubeServer -} from '@shared/server-commands' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/server-commands' describe('Test accounts API validators', function () { const path = '/api/v1/accounts/' diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 2dc3a166d..36526d494 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createMultipleServers, doubleFollow, @@ -14,7 +13,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' describe('Test blocklist API validators', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts index a2e51e14d..9db442b0b 100644 --- a/server/tests/api/check-params/contact-form.ts +++ b/server/tests/api/check-params/contact-form.ts @@ -1,15 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { MockSmtpServer } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' -import { - cleanupTests, - ContactFormCommand, - createSingleServer, - killallServers, - MockSmtpServer, - PeerTubeServer -} from '@shared/server-commands' +import { cleanupTests, ContactFormCommand, createSingleServer, killallServers, PeerTubeServer } from '@shared/server-commands' describe('Test contact form API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 6121d2202..d4dae5a75 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeDeleteRequest, @@ -13,7 +12,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' describe('Test server follows API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index b7c603755..d85961d62 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -1,17 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/server-commands' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' describe('Test jobs API validators', function () { const path = '/api/v1/jobs/failed' diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 8b79d97e0..8aee6164c 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -2,8 +2,9 @@ import 'mocha' import { omit } from 'lodash' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' import { - buildAbsoluteFixturePath, cleanupTests, createSingleServer, LiveCommand, @@ -14,7 +15,6 @@ import { setAccessTokensToServers, stopFfmpeg } from '@shared/server-commands' -import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' describe('Test video lives API validator', function () { const path = '/api/v1/videos/live' diff --git a/server/tests/api/check-params/my-user.ts b/server/tests/api/check-params/my-user.ts index c8ac71476..95f2122ae 100644 --- a/server/tests/api/check-params/my-user.ts +++ b/server/tests/api/check-params/my-user.ts @@ -1,22 +1,19 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, MockSmtpServer } from '@server/tests/shared' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { HttpStatusCode, UserRole, VideoCreateResult } from '@shared/models' import { - buildAbsoluteFixturePath, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeGetRequest, makePutBodyRequest, makeUploadRequest, - MockSmtpServer, PeerTubeServer, setAccessTokensToServers, UsersCommand } from '@shared/server-commands' -import { HttpStatusCode, UserRole, VideoCreateResult } from '@shared/models' describe('Test my user API validators', function () { const path = '/api/v1/users/' diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 79e487590..c3f15b86e 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeGetRequest, @@ -13,7 +12,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models' describe('Test server plugins API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index f3bfcb16c..04519cf23 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -1,10 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createMultipleServers, doubleFollow, @@ -16,7 +15,6 @@ import { setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoCreateResult } from '@shared/models' describe('Test server redundancy API validators', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index edeeed571..ca0fbf31d 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -1,17 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/server-commands' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) { return server.config.updateCustomSubConfig({ diff --git a/server/tests/api/check-params/transcoding.ts b/server/tests/api/check-params/transcoding.ts index 11ade9071..333012940 100644 --- a/server/tests/api/check-params/transcoding.ts +++ b/server/tests/api/check-params/transcoding.ts @@ -1,8 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' import { HttpStatusCode, UserRole } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' describe('Test transcoding API validators', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index 02898bb87..deb4a7aa3 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -2,18 +2,18 @@ import 'mocha' import { expect } from 'chai' +import { FIXTURE_URLS } from '@server/tests/shared' import { randomInt } from '@shared/core-utils' +import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, createSingleServer, - FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, VideosCommand, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models' describe('Test upload quota', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 912d4a992..4bc8084a1 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -2,20 +2,18 @@ import 'mocha' import { io } from 'socket.io-client' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeGetRequest, makePostBodyRequest, makePutBodyRequest, PeerTubeServer, - setAccessTokensToServers, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models' describe('Test user notifications API validators', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 95226dff5..a13ed5aa3 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -2,9 +2,6 @@ import 'mocha' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeDeleteRequest, @@ -15,6 +12,7 @@ import { waitJobs } from '@shared/server-commands' import { HttpStatusCode } from '@shared/models' +import { checkBadStartPagination, checkBadCountPagination, checkBadSortPagination } from '@server/tests/shared' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' diff --git a/server/tests/api/check-params/users-admin.ts b/server/tests/api/check-params/users-admin.ts index c98b5e189..d8353f83b 100644 --- a/server/tests/api/check-params/users-admin.ts +++ b/server/tests/api/check-params/users-admin.ts @@ -2,21 +2,18 @@ import 'mocha' import { omit } from 'lodash' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, MockSmtpServer } from '@server/tests/shared' +import { HttpStatusCode, UserAdminFlag, UserRole } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, killallServers, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - MockSmtpServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, UserAdminFlag, UserRole } from '@shared/models' describe('Test users admin API validators', function () { const path = '/api/v1/users/' diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 254177afd..84254945c 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -2,15 +2,9 @@ import 'mocha' import { omit } from 'lodash' -import { - cleanupTests, - createSingleServer, - makePostBodyRequest, - MockSmtpServer, - PeerTubeServer, - setAccessTokensToServers -} from '@shared/server-commands' +import { MockSmtpServer } from '@server/tests/shared' import { HttpStatusCode, UserRole } from '@shared/models' +import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' describe('Test users API validators', function () { const path = '/api/v1/users/' diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 7eb3c1cae..1aab60826 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -2,11 +2,10 @@ import 'mocha' import { expect } from 'chai' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode, VideoBlacklistType } from '@shared/models' import { BlacklistCommand, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createMultipleServers, doubleFollow, @@ -16,7 +15,6 @@ import { setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoBlacklistType } from '@shared/models' describe('Test video blacklist API validators', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index 34c1a9673..8a8840793 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' import { - buildAbsoluteFixturePath, cleanupTests, createSingleServer, makeDeleteRequest, @@ -11,7 +12,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, VideoCreateResult } from '@shared/models' describe('Test video captions API validator', function () { const path = '/api/v1/videos/' diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 747a5d3ec..1e9732fe9 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -3,12 +3,11 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' import { - buildAbsoluteFixturePath, ChannelsCommand, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeGetRequest, @@ -18,7 +17,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 05cf61cba..63c3582e9 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -2,10 +2,9 @@ import 'mocha' import * as chai from 'chai' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeDeleteRequest, @@ -14,7 +13,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, VideoCreateResult } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/check-params/video-files.ts b/server/tests/api/check-params/video-files.ts index 90ab4460c..8c0795092 100644 --- a/server/tests/api/check-params/video-files.ts +++ b/server/tests/api/check-params/video-files.ts @@ -1,8 +1,15 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' import { HttpStatusCode, UserRole } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' describe('Test videos files', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index 7cefb2a54..ddea68db4 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -2,21 +2,18 @@ import 'mocha' import { omit } from 'lodash' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { - buildAbsoluteFixturePath, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, createSingleServer, - FIXTURE_URLS, makeGetRequest, makePostBodyRequest, makeUploadRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, VideoPrivacy } from '@shared/models' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index ac3c13f78..4b17ce7db 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -1,18 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - cleanupTests, - createSingleServer, - makeGetRequest, - PeerTubeServer, - PlaylistsCommand, - setAccessTokensToServers, - setDefaultVideoChannel -} from '@shared/server-commands' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' import { HttpStatusCode, VideoPlaylistCreate, @@ -23,6 +12,15 @@ import { VideoPlaylistReorder, VideoPlaylistType } from '@shared/models' +import { + cleanupTests, + createSingleServer, + makeGetRequest, + PeerTubeServer, + PlaylistsCommand, + setAccessTokensToServers, + setDefaultVideoChannel +} from '@shared/server-commands' describe('Test video playlists API validator', function () { let server: PeerTubeServer diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index e4b4c4b2a..31a0752c7 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' +import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode } from '@shared/models' import { - checkBadCountPagination, - checkBadStartPagination, cleanupTests, createSingleServer, makeGetRequest, @@ -12,7 +12,6 @@ import { PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 3b2607eed..4cc70f5cc 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -4,12 +4,10 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' import { join } from 'path' -import { randomInt } from '@shared/core-utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, checkUploadVideoParam } from '@server/tests/shared' +import { randomInt, root } from '@shared/core-utils' +import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, - checkUploadVideoParam, cleanupTests, createSingleServer, makeDeleteRequest, @@ -17,10 +15,8 @@ import { makePutBodyRequest, makeUploadRequest, PeerTubeServer, - root, setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 89880c46b..909399836 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -2,9 +2,9 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' import { VideoPrivacy } from '@shared/models' import { - checkLiveCleanupAfterSave, cleanupTests, ConfigCommand, createMultipleServers, @@ -12,9 +12,9 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - wait, waitJobs -} from '../../../../shared/server-commands' +} from '@shared/server-commands' +import { checkLiveCleanupAfterSave } from '../../shared' const expect = chai.expect diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index 12a4d64d8..c2392603b 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' import { LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, @@ -12,9 +13,8 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - wait, waitJobs -} from '../../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/live/live-rtmps.ts b/server/tests/api/live/live-rtmps.ts index 31e8f906e..935061971 100644 --- a/server/tests/api/live/live-rtmps.ts +++ b/server/tests/api/live/live-rtmps.ts @@ -2,9 +2,9 @@ import 'mocha' import * as chai from 'chai' +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { VideoPrivacy } from '@shared/models' import { - buildAbsoluteFixturePath, cleanupTests, createSingleServer, PeerTubeServer, @@ -14,7 +14,7 @@ import { stopFfmpeg, testFfmpegStreamError, waitUntilLivePublishedOnAllServers -} from '../../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 9fb6b4e54..95a342b01 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -3,8 +3,10 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' +import { checkLiveCleanupAfterSave } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' import { - checkLiveCleanupAfterSave, cleanupTests, ConfigCommand, createMultipleServers, @@ -14,12 +16,10 @@ import { setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - wait, waitJobs, waitUntilLivePublishedOnAllServers, waitUntilLiveSavedOnAllServers } from '@shared/server-commands' -import { HttpStatusCode, LiveVideoCreate, VideoPrivacy, VideoState } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/live/live-socket-messages.ts b/server/tests/api/live/live-socket-messages.ts index 42cf9c5f6..50b16443e 100644 --- a/server/tests/api/live/live-socket-messages.ts +++ b/server/tests/api/live/live-socket-messages.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' import { VideoPrivacy, VideoState } from '@shared/models' import { cleanupTests, @@ -11,10 +12,9 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - wait, waitJobs, waitUntilLivePublishedOnAllServers -} from '../../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/live/live-views.ts b/server/tests/api/live/live-views.ts index 5de4436be..446d0913c 100644 --- a/server/tests/api/live/live-views.ts +++ b/server/tests/api/live/live-views.ts @@ -3,6 +3,7 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' +import { wait } from '@shared/core-utils' import { VideoPrivacy } from '@shared/models' import { cleanupTests, @@ -12,10 +13,9 @@ import { setAccessTokensToServers, setDefaultVideoChannel, stopFfmpeg, - wait, waitJobs, waitUntilLivePublishedOnAllServers -} from '../../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/live/live.ts b/server/tests/api/live/live.ts index 3869fd6c7..3f9355d2d 100644 --- a/server/tests/api/live/live.ts +++ b/server/tests/api/live/live.ts @@ -4,10 +4,18 @@ import 'mocha' import * as chai from 'chai' import { basename, join } from 'path' import { ffprobePromise, getVideoStreamFromFile } from '@server/helpers/ffprobe-utils' +import { checkLiveCleanupAfterSave, checkLiveSegmentHash, checkResolutionsInMasterPlaylist, testImage } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { + HttpStatusCode, + LiveVideo, + LiveVideoCreate, + VideoDetails, + VideoPrivacy, + VideoState, + VideoStreamingPlaylistType +} from '@shared/models' import { - checkLiveCleanupAfterSave, - checkLiveSegmentHash, - checkResolutionsInMasterPlaylist, cleanupTests, createMultipleServers, doubleFollow, @@ -20,20 +28,9 @@ import { setDefaultVideoChannel, stopFfmpeg, testFfmpegStreamError, - testImage, - wait, waitJobs, waitUntilLivePublishedOnAllServers } from '@shared/server-commands' -import { - HttpStatusCode, - LiveVideo, - LiveVideoCreate, - VideoDetails, - VideoPrivacy, - VideoState, - VideoStreamingPlaylistType -} from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/moderation/blocklist-notification.ts b/server/tests/api/moderation/blocklist-notification.ts index d1e2ea56e..87d147998 100644 --- a/server/tests/api/moderation/blocklist-notification.ts +++ b/server/tests/api/moderation/blocklist-notification.ts @@ -2,8 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' import { UserNotificationType } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts index 4e2887fa0..322e93815 100644 --- a/server/tests/api/moderation/video-blacklist.ts +++ b/server/tests/api/moderation/video-blacklist.ts @@ -3,18 +3,18 @@ import 'mocha' import * as chai from 'chai' import { orderBy } from 'lodash' +import { FIXTURE_URLS } from '@server/tests/shared' +import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { BlacklistCommand, cleanupTests, createMultipleServers, doubleFollow, - FIXTURE_URLS, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts index 18962a71e..f037e7aae 100644 --- a/server/tests/api/notifications/admin-notifications.ts +++ b/server/tests/api/notifications/admin-notifications.ts @@ -6,14 +6,13 @@ import { CheckerBaseParams, checkNewPeerTubeVersion, checkNewPluginVersion, - cleanupTests, MockJoinPeerTubeVersions, MockSmtpServer, - PeerTubeServer, - prepareNotificationsTest, - wait -} from '@shared/server-commands' + prepareNotificationsTest +} from '@server/tests/shared' +import { wait } from '@shared/core-utils' import { PluginType, UserNotification, UserNotificationType } from '@shared/models' +import { cleanupTests, PeerTubeServer } from '@shared/server-commands' describe('Test admin notifications', function () { let server: PeerTubeServer diff --git a/server/tests/api/notifications/comments-notifications.ts b/server/tests/api/notifications/comments-notifications.ts index 919be4bca..b82f1712a 100644 --- a/server/tests/api/notifications/comments-notifications.ts +++ b/server/tests/api/notifications/comments-notifications.ts @@ -6,13 +6,11 @@ import { checkCommentMention, CheckerBaseParams, checkNewCommentOnMyVideo, - cleanupTests, MockSmtpServer, - PeerTubeServer, - prepareNotificationsTest, - waitJobs -} from '@shared/server-commands' + prepareNotificationsTest +} from '@server/tests/shared' import { UserNotification } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index 4da9d2684..e6e1d5f7b 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { buildUUID } from '@shared/core-utils/uuid' import { checkAbuseStateChange, checkAutoInstanceFollowing, @@ -16,15 +15,13 @@ import { checkUserRegistered, checkVideoAutoBlacklistForModerators, checkVideoIsPublished, - cleanupTests, MockInstancesIndex, MockSmtpServer, - PeerTubeServer, - prepareNotificationsTest, - wait, - waitJobs -} from '@shared/server-commands' + prepareNotificationsTest +} from '@server/tests/shared' +import { buildUUID, wait } from '@shared/core-utils' import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' describe('Test moderation notifications', function () { let servers: PeerTubeServer[] = [] diff --git a/server/tests/api/notifications/notifications-api.ts b/server/tests/api/notifications/notifications-api.ts index aeb73350b..ac08449f8 100644 --- a/server/tests/api/notifications/notifications-api.ts +++ b/server/tests/api/notifications/notifications-api.ts @@ -5,14 +5,12 @@ import * as chai from 'chai' import { CheckerBaseParams, checkNewVideoFromSubscription, - cleanupTests, getAllNotificationsSettings, MockSmtpServer, - PeerTubeServer, - prepareNotificationsTest, - waitJobs -} from '@shared/server-commands' + prepareNotificationsTest +} from '@server/tests/shared' import { UserNotification, UserNotificationSettingValue } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/notifications/user-notifications.ts b/server/tests/api/notifications/user-notifications.ts index a2fcdf2ef..bb3024617 100644 --- a/server/tests/api/notifications/user-notifications.ts +++ b/server/tests/api/notifications/user-notifications.ts @@ -2,23 +2,20 @@ import 'mocha' import * as chai from 'chai' -import { buildUUID } from '@shared/core-utils/uuid' import { CheckerBaseParams, checkMyVideoImportIsFinished, checkNewActorFollow, checkNewVideoFromSubscription, checkVideoIsPublished, - cleanupTests, FIXTURE_URLS, MockSmtpServer, - PeerTubeServer, prepareNotificationsTest, - uploadRandomVideoOnServers, - wait, - waitJobs -} from '@shared/server-commands' + uploadRandomVideoOnServers +} from '@server/tests/shared' +import { buildUUID, wait } from '@shared/core-utils' import { UserNotification, UserNotificationType, VideoPrivacy } from '@shared/models' +import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/object-storage/live.ts b/server/tests/api/object-storage/live.ts index 2c341c139..0cb0a6e34 100644 --- a/server/tests/api/object-storage/live.ts +++ b/server/tests/api/object-storage/live.ts @@ -3,11 +3,12 @@ import 'mocha' import * as chai from 'chai' import { FfmpegCommand } from 'fluent-ffmpeg' +import { expectStartWith } from '@server/tests/shared' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' import { - areObjectStorageTestsDisabled, createMultipleServers, doubleFollow, - expectStartWith, killallServers, makeRawRequest, ObjectStorageCommand, @@ -19,7 +20,6 @@ import { waitUntilLivePublishedOnAllServers, waitUntilLiveSavedOnAllServers } from '@shared/server-commands' -import { HttpStatusCode, LiveVideoCreate, VideoFile, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/object-storage/video-imports.ts b/server/tests/api/object-storage/video-imports.ts index adca16e8f..fb81832af 100644 --- a/server/tests/api/object-storage/video-imports.ts +++ b/server/tests/api/object-storage/video-imports.ts @@ -2,11 +2,11 @@ import 'mocha' import * as chai from 'chai' +import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { - areObjectStorageTestsDisabled, createSingleServer, - expectStartWith, - FIXTURE_URLS, killallServers, makeRawRequest, ObjectStorageCommand, @@ -15,7 +15,6 @@ import { setDefaultVideoChannel, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/object-storage/videos.ts b/server/tests/api/object-storage/videos.ts index bf469015f..498efcb17 100644 --- a/server/tests/api/object-storage/videos.ts +++ b/server/tests/api/object-storage/videos.ts @@ -3,25 +3,22 @@ import 'mocha' import * as chai from 'chai' import { merge } from 'lodash' +import { checkTmpIsEmpty, expectLogDoesNotContain, expectStartWith, MockObjectStorage } from '@server/tests/shared' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, VideoDetails } from '@shared/models' import { - areObjectStorageTestsDisabled, - checkTmpIsEmpty, cleanupTests, createMultipleServers, createSingleServer, doubleFollow, - expectLogDoesNotContain, - expectStartWith, killallServers, makeRawRequest, - MockObjectStorage, ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd } from '@shared/server-commands' -import { HttpStatusCode, VideoDetails } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/redundancy/redundancy-constraints.ts b/server/tests/api/redundancy/redundancy-constraints.ts index 1a8d8183b..17c6b25a5 100644 --- a/server/tests/api/redundancy/redundancy-constraints.ts +++ b/server/tests/api/redundancy/redundancy-constraints.ts @@ -2,8 +2,15 @@ import 'mocha' import { expect } from 'chai' -import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' import { VideoPrivacy } from '@shared/models' +import { + cleanupTests, + createSingleServer, + killallServers, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' describe('Test redundancy constraints', function () { let remoteServer: PeerTubeServer diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index 556cfbc31..3f2286278 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -5,29 +5,26 @@ import * as chai from 'chai' import { readdir } from 'fs-extra' import magnetUtil from 'magnet-uri' import { basename, join } from 'path' +import { checkSegmentHash, checkVideoFilesWereRemoved, saveVideoInServers } from '@server/tests/shared' +import { root, wait } from '@shared/core-utils' +import { + HttpStatusCode, + VideoDetails, + VideoFile, + VideoPrivacy, + VideoRedundancyStrategy, + VideoRedundancyStrategyWithManual +} from '@shared/models' import { - checkSegmentHash, - checkVideoFilesWereRemoved, cleanupTests, createMultipleServers, doubleFollow, killallServers, makeRawRequest, PeerTubeServer, - root, - saveVideoInServers, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { - HttpStatusCode, - VideoDetails, - VideoFile, - VideoPrivacy, - VideoRedundancyStrategy, - VideoRedundancyStrategyWithManual -} from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-activitypub-video-channels.ts b/server/tests/api/search/search-activitypub-video-channels.ts index 1f29f840a..2e0abc6ba 100644 --- a/server/tests/api/search/search-activitypub-video-channels.ts +++ b/server/tests/api/search/search-activitypub-video-channels.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { VideoChannel } from '@shared/models' import { cleanupTests, createMultipleServers, PeerTubeServer, SearchCommand, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { VideoChannel } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 550af8ed2..d9243ac53 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts @@ -2,6 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -9,10 +11,8 @@ import { SearchCommand, setAccessTokensToServers, setDefaultVideoChannel, - wait, waitJobs } from '@shared/server-commands' -import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-activitypub-videos.ts b/server/tests/api/search/search-activitypub-videos.ts index 5aa3738c9..60b95ae4c 100644 --- a/server/tests/api/search/search-activitypub-videos.ts +++ b/server/tests/api/search/search-activitypub-videos.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, PeerTubeServer, SearchCommand, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/search/search-videos.ts b/server/tests/api/search/search-videos.ts index bf2375ffa..c544705d3 100644 --- a/server/tests/api/search/search-videos.ts +++ b/server/tests/api/search/search-videos.ts @@ -10,10 +10,10 @@ import { SearchCommand, setAccessTokensToServers, setDefaultVideoChannel, - stopFfmpeg, - wait + stopFfmpeg } from '@shared/server-commands' import { VideoPrivacy } from '@shared/models' +import { wait } from '@shared/core-utils' const expect = chai.expect diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 74bb96040..6d2333a6b 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts @@ -2,15 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - createMultipleServers, - MockInstancesIndex, - PeerTubeServer, - setAccessTokensToServers, - wait, - waitJobs -} from '@shared/server-commands' +import { MockInstancesIndex } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts index 4ceda7de3..3ff09bf7e 100644 --- a/server/tests/api/server/config-defaults.ts +++ b/server/tests/api/server/config-defaults.ts @@ -2,15 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - createSingleServer, - FIXTURE_URLS, - PeerTubeServer, - setAccessTokensToServers, - setDefaultVideoChannel -} from '@shared/server-commands' +import { FIXTURE_URLS } from '@server/tests/shared' import { VideoDetails, VideoPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index 2e6617a15..2356f701c 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { parallelTests } from '@shared/core-utils' +import { CustomConfig, HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, killallServers, makeGetRequest, - parallelTests, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' -import { CustomConfig, HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/contact-form.ts b/server/tests/api/server/contact-form.ts index 109251453..f3facb04a 100644 --- a/server/tests/api/server/contact-form.ts +++ b/server/tests/api/server/contact-form.ts @@ -2,17 +2,17 @@ import 'mocha' import * as chai from 'chai' +import { MockSmtpServer } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, ContactFormCommand, createSingleServer, - MockSmtpServer, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index 6fa6053cb..20b5e378c 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts @@ -2,8 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { MockSmtpServer } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts index e128c36a5..cd34df15d 100644 --- a/server/tests/api/server/follows.ts +++ b/server/tests/api/server/follows.ts @@ -2,19 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - createMultipleServers, - dateIsValid, - expectAccountFollows, - expectChannelsFollows, - PeerTubeServer, - setAccessTokensToServers, - testCaptionFile, - waitJobs -} from '@shared/server-commands' +import { completeVideoCheck, dateIsValid, expectAccountFollows, expectChannelsFollows, testCaptionFile } from '@server/tests/shared' import { VideoCreateResult, VideoPrivacy } from '@shared/models' -import { completeVideoCheck } from '@server/tests/shared/video' +import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts index b134e074b..7c3836681 100644 --- a/server/tests/api/server/handle-down.ts +++ b/server/tests/api/server/handle-down.ts @@ -2,6 +2,9 @@ import 'mocha' import * as chai from 'chai' +import { completeVideoCheck } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' import { cleanupTests, CommentsCommand, @@ -9,11 +12,8 @@ import { killallServers, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, JobState, VideoCreateResult, VideoPrivacy } from '@shared/models' -import { completeVideoCheck } from '@server/tests/shared/video' const expect = chai.expect diff --git a/server/tests/api/server/jobs.ts b/server/tests/api/server/jobs.ts index 5b38f6741..4294e1fd5 100644 --- a/server/tests/api/server/jobs.ts +++ b/server/tests/api/server/jobs.ts @@ -2,10 +2,10 @@ import 'mocha' import * as chai from 'chai' +import { dateIsValid } from '@server/tests/shared' import { cleanupTests, createMultipleServers, - dateIsValid, doubleFollow, PeerTubeServer, setAccessTokensToServers, diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index fbcd89101..e82096c48 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -2,17 +2,17 @@ import 'mocha' import * as chai from 'chai' +import { testHelloWorldRegisteredSettings } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, PluginType } from '@shared/models' import { cleanupTests, createSingleServer, killallServers, PeerTubeServer, PluginsCommand, - setAccessTokensToServers, - testHelloWorldRegisteredSettings, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, PluginType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts index 626a0d860..c40a4f9b8 100644 --- a/server/tests/api/server/proxy.ts +++ b/server/tests/api/server/proxy.ts @@ -2,18 +2,17 @@ import 'mocha' import * as chai from 'chai' +import { FIXTURE_URLS, MockProxy } from '@server/tests/shared' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, - FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, waitJobs } from '@shared/server-commands' -import { MockProxy } from '@shared/server-commands/mock-servers/mock-proxy' -import { HttpStatusCode, VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/server/reverse-proxy.ts b/server/tests/api/server/reverse-proxy.ts index fc9b88a6a..968d98e96 100644 --- a/server/tests/api/server/reverse-proxy.ts +++ b/server/tests/api/server/reverse-proxy.ts @@ -1,8 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import { expect } from 'chai' -import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/server-commands' +import { wait } from '@shared/core-utils' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' describe('Test application behind a reverse proxy', function () { let server: PeerTubeServer diff --git a/server/tests/api/server/slow-follows.ts b/server/tests/api/server/slow-follows.ts index 5f24c351b..666a7c2e6 100644 --- a/server/tests/api/server/slow-follows.ts +++ b/server/tests/api/server/slow-follows.ts @@ -2,8 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' import { Job } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/server/stats.ts b/server/tests/api/server/stats.ts index 65ef4607b..f0334532b 100644 --- a/server/tests/api/server/stats.ts +++ b/server/tests/api/server/stats.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { ActivityType, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index e6699a059..5b2bbc520 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -6,16 +6,18 @@ import { checkActorFilesWereRemoved, checkTmpIsEmpty, checkVideoFilesWereRemoved, + saveVideoInServers, + testImage +} from '@server/tests/shared' +import { MyUser } from '@shared/models' +import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, - saveVideoInServers, setAccessTokensToServers, - testImage, waitJobs } from '@shared/server-commands' -import { MyUser } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 9b23ba797..0f3cc401a 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,8 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { MockSmtpServer } from '@server/tests/shared' import { HttpStatusCode } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index fc44a6acd..ff9172a82 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,6 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { testImage } from '@server/tests/shared' +import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' import { cleanupTests, createSingleServer, @@ -9,10 +11,8 @@ import { makePutBodyRequest, PeerTubeServer, setAccessTokensToServers, - testImage, waitJobs } from '@shared/server-commands' -import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/audio-only.ts b/server/tests/api/videos/audio-only.ts index 4b27f2fbe..e58360ffe 100644 --- a/server/tests/api/videos/audio-only.ts +++ b/server/tests/api/videos/audio-only.ts @@ -3,7 +3,14 @@ import 'mocha' import * as chai from 'chai' import { getAudioStream, getVideoStreamSize } from '@server/helpers/ffprobe-utils' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts index cb83fa0f0..9fa03f1a9 100644 --- a/server/tests/api/videos/multiple-servers.ts +++ b/server/tests/api/videos/multiple-servers.ts @@ -4,23 +4,24 @@ import 'mocha' import * as chai from 'chai' import request from 'supertest' import { - buildAbsoluteFixturePath, checkTmpIsEmpty, checkVideoFilesWereRemoved, + completeVideoCheck, + dateIsValid, + saveVideoInServers, + testImage +} from '@server/tests/shared' +import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' +import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' +import { cleanupTests, createMultipleServers, - dateIsValid, doubleFollow, PeerTubeServer, - saveVideoInServers, setAccessTokensToServers, - testImage, - wait, waitJobs, webtorrentAdd } from '@shared/server-commands' -import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models' -import { completeVideoCheck } from '@server/tests/shared/video' const expect = chai.expect diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts index 0842817dc..d6f4da630 100644 --- a/server/tests/api/videos/resumable-upload.ts +++ b/server/tests/api/videos/resumable-upload.ts @@ -4,15 +4,9 @@ import 'mocha' import * as chai from 'chai' import { pathExists, readdir, stat } from 'fs-extra' import { join } from 'path' -import { - buildAbsoluteFixturePath, - cleanupTests, - createSingleServer, - PeerTubeServer, - setAccessTokensToServers, - setDefaultVideoChannel -} from '@shared/server-commands' +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { HttpStatusCode, VideoPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts index e5e12dd19..28bf018c5 100644 --- a/server/tests/api/videos/single-server.ts +++ b/server/tests/api/videos/single-server.ts @@ -2,17 +2,10 @@ import 'mocha' import * as chai from 'chai' -import { - checkVideoFilesWereRemoved, - cleanupTests, - createSingleServer, - PeerTubeServer, - setAccessTokensToServers, - testImage, - wait -} from '@shared/server-commands' +import { checkVideoFilesWereRemoved, completeVideoCheck, testImage } from '@server/tests/shared' +import { wait } from '@shared/core-utils' import { Video, VideoPrivacy } from '@shared/models' -import { completeVideoCheck } from '@server/tests/shared/video' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts index 9f00312aa..b7f26c35f 100644 --- a/server/tests/api/videos/video-captions.ts +++ b/server/tests/api/videos/video-captions.ts @@ -2,15 +2,14 @@ import 'mocha' import * as chai from 'chai' +import { checkVideoFilesWereRemoved, testCaptionFile } from '@server/tests/shared' +import { wait } from '@shared/core-utils' import { - checkVideoFilesWereRemoved, cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, - testCaptionFile, - wait, waitJobs } from '@shared/server-commands' diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts index 2ac577a59..d435f3682 100644 --- a/server/tests/api/videos/video-channels.ts +++ b/server/tests/api/videos/video-channels.ts @@ -4,6 +4,9 @@ import 'mocha' import * as chai from 'chai' import { basename } from 'path' import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' +import { testFileExistsOrNot, testImage } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { User, VideoChannel } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -11,12 +14,8 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - testFileExistsOrNot, - testImage, - wait, waitJobs } from '@shared/server-commands' -import { User, VideoChannel } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-comments.ts b/server/tests/api/videos/video-comments.ts index bb4f92a9b..2ae523970 100644 --- a/server/tests/api/videos/video-comments.ts +++ b/server/tests/api/videos/video-comments.ts @@ -2,15 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - CommentsCommand, - createSingleServer, - dateIsValid, - PeerTubeServer, - setAccessTokensToServers, - testImage -} from '@shared/server-commands' +import { dateIsValid, testImage } from '@server/tests/shared' +import { cleanupTests, CommentsCommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/video-create-transcoding.ts b/server/tests/api/videos/video-create-transcoding.ts index e81f54714..62a6bab0d 100644 --- a/server/tests/api/videos/video-create-transcoding.ts +++ b/server/tests/api/videos/video-create-transcoding.ts @@ -2,20 +2,20 @@ import 'mocha' import * as chai from 'chai' +import { expectStartWith } from '@server/tests/shared' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, VideoDetails } from '@shared/models' import { - areObjectStorageTestsDisabled, cleanupTests, createMultipleServers, doubleFollow, expectNoFailedTranscodingJob, - expectStartWith, makeRawRequest, ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoDetails } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-description.ts b/server/tests/api/videos/video-description.ts index 23c55f728..20b20488f 100644 --- a/server/tests/api/videos/video-description.ts +++ b/server/tests/api/videos/video-description.ts @@ -2,7 +2,14 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/video-files.ts b/server/tests/api/videos/video-files.ts index 0b5121740..b0ef4a2e9 100644 --- a/server/tests/api/videos/video-files.ts +++ b/server/tests/api/videos/video-files.ts @@ -2,7 +2,14 @@ import 'mocha' import { expect } from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + waitJobs +} from '@shared/server-commands' describe('Test videos files', function () { let servers: PeerTubeServer[] diff --git a/server/tests/api/videos/video-hls.ts b/server/tests/api/videos/video-hls.ts index d050a7a7e..218ec08ae 100644 --- a/server/tests/api/videos/video-hls.ts +++ b/server/tests/api/videos/video-hls.ts @@ -3,18 +3,20 @@ import 'mocha' import * as chai from 'chai' import { basename, join } from 'path' -import { removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' import { - areObjectStorageTestsDisabled, checkDirectoryIsEmpty, checkResolutionsInMasterPlaylist, checkSegmentHash, checkTmpIsEmpty, + expectStartWith, + hlsInfohashExist +} from '@server/tests/shared' +import { areObjectStorageTestsDisabled, removeFragmentedMP4Ext, uuidRegex } from '@shared/core-utils' +import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' +import { cleanupTests, createMultipleServers, doubleFollow, - expectStartWith, - hlsInfohashExist, makeRawRequest, ObjectStorageCommand, PeerTubeServer, @@ -22,7 +24,6 @@ import { waitJobs, webtorrentAdd } from '@shared/server-commands' -import { HttpStatusCode, VideoStreamingPlaylistType } from '@shared/models' import { DEFAULT_AUDIO_RESOLUTION } from '../../../initializers/constants' const expect = chai.expect diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts index 2518743f7..e8e0f01f1 100644 --- a/server/tests/api/videos/video-imports.ts +++ b/server/tests/api/videos/video-imports.ts @@ -4,21 +4,19 @@ import 'mocha' import { expect } from 'chai' import { pathExists, readdir, remove } from 'fs-extra' import { join } from 'path' +import { FIXTURE_URLS, testCaptionFile, testImage } from '@server/tests/shared' +import { areHttpImportTestsDisabled } from '@shared/core-utils' +import { VideoPrivacy, VideoResolution } from '@shared/models' import { - areHttpImportTestsDisabled, cleanupTests, createMultipleServers, createSingleServer, doubleFollow, - FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - testCaptionFile, - testImage, waitJobs } from '@shared/server-commands' -import { VideoPrivacy, VideoResolution } from '@shared/models' async function checkVideosServer1 (server: PeerTubeServer, idHttp: string, idMagnet: string, idTorrent: string) { const videoHttp = await server.videos.get({ id: idHttp }) diff --git a/server/tests/api/videos/video-playlist-thumbnails.ts b/server/tests/api/videos/video-playlist-thumbnails.ts index e6b6c34eb..5fdb0fc03 100644 --- a/server/tests/api/videos/video-playlist-thumbnails.ts +++ b/server/tests/api/videos/video-playlist-thumbnails.ts @@ -2,6 +2,8 @@ import 'mocha' import * as chai from 'chai' +import { testImage } from '@server/tests/shared' +import { VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, @@ -9,10 +11,8 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - testImage, waitJobs -} from '../../../../shared/server-commands' -import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/video-playlists.ts b/server/tests/api/videos/video-playlists.ts index 6279f5cd0..34327334f 100644 --- a/server/tests/api/videos/video-playlists.ts +++ b/server/tests/api/videos/video-playlists.ts @@ -2,8 +2,18 @@ import 'mocha' import * as chai from 'chai' +import { checkPlaylistFilesWereRemoved, testImage } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { + HttpStatusCode, + VideoPlaylist, + VideoPlaylistCreateResult, + VideoPlaylistElementType, + VideoPlaylistPrivacy, + VideoPlaylistType, + VideoPrivacy +} from '@shared/models' import { - checkPlaylistFilesWereRemoved, cleanupTests, createMultipleServers, doubleFollow, @@ -11,19 +21,8 @@ import { PlaylistsCommand, setAccessTokensToServers, setDefaultVideoChannel, - testImage, - wait, waitJobs } from '@shared/server-commands' -import { - HttpStatusCode, - VideoPlaylist, - VideoPlaylistCreateResult, - VideoPlaylistElementType, - VideoPlaylistPrivacy, - VideoPlaylistType, - VideoPrivacy -} from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-privacy.ts b/server/tests/api/videos/video-privacy.ts index 13eb941ea..3051a443d 100644 --- a/server/tests/api/videos/video-privacy.ts +++ b/server/tests/api/videos/video-privacy.ts @@ -2,16 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { - cleanupTests, - createSingleServer, - doubleFollow, - PeerTubeServer, - setAccessTokensToServers, - wait, - waitJobs -} from '@shared/server-commands' +import { wait } from '@shared/core-utils' import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models' +import { cleanupTests, createSingleServer, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/video-schedule-update.ts b/server/tests/api/videos/video-schedule-update.ts index 9408574ad..00b4f6cbc 100644 --- a/server/tests/api/videos/video-schedule-update.ts +++ b/server/tests/api/videos/video-schedule-update.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { VideoPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs } from '@shared/server-commands' -import { VideoPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index f4b0bc53a..d24a8f4e1 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -3,29 +3,21 @@ import 'mocha' import * as chai from 'chai' import { omit } from 'lodash' -import { getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils' +import { canDoQuickTranscode } from '@server/helpers/ffprobe-utils' +import { generateHighBitrateVideo, generateVideoWithFramerate } from '@server/tests/shared' +import { buildAbsoluteFixturePath, getMaxBitrate, getMinLimitBitrate } from '@shared/core-utils' +import { getAudioStream, getMetadataFromFile, getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils' +import { HttpStatusCode, VideoState } from '@shared/models' import { - buildAbsoluteFixturePath, cleanupTests, createMultipleServers, doubleFollow, - generateHighBitrateVideo, - generateVideoWithFramerate, makeGetRequest, PeerTubeServer, setAccessTokensToServers, waitJobs, webtorrentAdd } from '@shared/server-commands' -import { HttpStatusCode, VideoState } from '@shared/models' -import { - canDoQuickTranscode, - getAudioStream, - getMetadataFromFile, - getVideoFileBitrate, - getVideoFileFPS, - getVideoFileResolution -} from '../../../helpers/ffprobe-utils' const expect = chai.expect diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 813fc4f45..4e5ba13aa 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts @@ -2,16 +2,16 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, Video } from '@shared/models' import { cleanupTests, createSingleServer, HistoryCommand, killallServers, PeerTubeServer, - setAccessTokensToServers, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, Video } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index 08a4efb63..61fc0cb20 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts @@ -2,8 +2,9 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/server-commands' +import { wait } from '@shared/core-utils' import { VideosOverview } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/api/videos/videos-views-cleaner.ts b/server/tests/api/videos/videos-views-cleaner.ts index 7f7597af4..e6815a4a8 100644 --- a/server/tests/api/videos/videos-views-cleaner.ts +++ b/server/tests/api/videos/videos-views-cleaner.ts @@ -2,6 +2,7 @@ import 'mocha' import * as chai from 'chai' +import { wait } from '@shared/core-utils' import { cleanupTests, createMultipleServers, @@ -9,9 +10,8 @@ import { killallServers, PeerTubeServer, setAccessTokensToServers, - wait, waitJobs -} from '../../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts index 5973272e5..8ef0545d0 100644 --- a/server/tests/cli/create-import-video-file-job.ts +++ b/server/tests/cli/create-import-video-file-job.ts @@ -2,19 +2,19 @@ import 'mocha' import * as chai from 'chai' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models' import { - areObjectStorageTestsDisabled, cleanupTests, createMultipleServers, doubleFollow, - expectStartWith, makeRawRequest, ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models' +import { expectStartWith } from '../shared' const expect = chai.expect diff --git a/server/tests/cli/create-move-video-storage-job.ts b/server/tests/cli/create-move-video-storage-job.ts index 8b66f24bf..c674d28d2 100644 --- a/server/tests/cli/create-move-video-storage-job.ts +++ b/server/tests/cli/create-move-video-storage-job.ts @@ -1,20 +1,19 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' - +import { areObjectStorageTestsDisabled } from '@shared/core-utils' +import { HttpStatusCode, VideoDetails } from '@shared/models' import { - areObjectStorageTestsDisabled, cleanupTests, createMultipleServers, doubleFollow, - expectStartWith, makeRawRequest, ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoDetails } from '@shared/models' +import { expectStartWith } from '../shared' async function checkFiles (origin: PeerTubeServer, video: VideoDetails, inObjectStorage: boolean) { for (const file of video.files) { diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts index ea3428662..c85130fef 100644 --- a/server/tests/cli/create-transcoding-job.ts +++ b/server/tests/cli/create-transcoding-job.ts @@ -2,19 +2,19 @@ import 'mocha' import * as chai from 'chai' +import { areObjectStorageTestsDisabled } from '@shared/core-utils' import { HttpStatusCode, VideoFile } from '@shared/models' import { - areObjectStorageTestsDisabled, cleanupTests, createMultipleServers, doubleFollow, - expectStartWith, makeRawRequest, ObjectStorageCommand, PeerTubeServer, setAccessTokensToServers, waitJobs -} from '../../../shared/server-commands' +} from '@shared/server-commands' +import { expectStartWith } from '../shared' const expect = chai.expect diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index 72213473b..034d216e3 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts @@ -2,19 +2,17 @@ import 'mocha' import { expect } from 'chai' +import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' import { - areHttpImportTestsDisabled, - buildAbsoluteFixturePath, cleanupTests, CLICommand, createSingleServer, doubleFollow, - FIXTURE_URLS, PeerTubeServer, setAccessTokensToServers, - testHelloWorldRegisteredSettings, waitJobs -} from '../../../shared/server-commands' +} from '@shared/server-commands' +import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared' describe('Test CLI wrapper', function () { let server: PeerTubeServer diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts index d9cf9465c..cd9f4e1c3 100644 --- a/server/tests/cli/plugins.ts +++ b/server/tests/cli/plugins.ts @@ -9,7 +9,7 @@ import { PeerTubeServer, PluginsCommand, setAccessTokensToServers -} from '../../../shared/server-commands' +} from '@shared/server-commands' describe('Test plugin scripts', function () { let server: PeerTubeServer diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts index 36c43c6df..27896f031 100644 --- a/server/tests/cli/print-transcode-command.ts +++ b/server/tests/cli/print-transcode-command.ts @@ -2,7 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { buildAbsoluteFixturePath, CLICommand } from '@shared/server-commands' +import { buildAbsoluteFixturePath } from '@shared/core-utils' +import { CLICommand } from '@shared/server-commands' import { VideoResolution } from '../../../shared/models/videos' const expect = chai.expect diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index e0bc6a589..8e8fc7e20 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts @@ -4,7 +4,8 @@ import 'mocha' import * as chai from 'chai' import { createFile, readdir } from 'fs-extra' import { join } from 'path' -import { buildUUID } from '@shared/core-utils/uuid' +import { buildUUID, wait } from '@shared/core-utils' +import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' import { cleanupTests, CLICommand, @@ -15,10 +16,8 @@ import { PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - wait, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts index 34dedb113..018e9d788 100644 --- a/server/tests/cli/reset-password.ts +++ b/server/tests/cli/reset-password.ts @@ -1,5 +1,5 @@ import 'mocha' -import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '../../../shared/server-commands' +import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' describe('Test reset password scripts', function () { let server: PeerTubeServer diff --git a/server/tests/external-plugins/auto-block-videos.ts b/server/tests/external-plugins/auto-block-videos.ts index 2f75ad25b..bc5c93621 100644 --- a/server/tests/external-plugins/auto-block-videos.ts +++ b/server/tests/external-plugins/auto-block-videos.ts @@ -2,17 +2,17 @@ import 'mocha' import { expect } from 'chai' +import { wait } from '@shared/core-utils' +import { Video } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, killallServers, - MockBlocklist, PeerTubeServer, - setAccessTokensToServers, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { Video } from '@shared/models' +import { MockBlocklist } from '../shared' async function check (server: PeerTubeServer, videoUUID: string, exists = true) { const { data } = await server.videos.list() diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts index bfa67e7ad..375ccf91a 100644 --- a/server/tests/external-plugins/auto-mute.ts +++ b/server/tests/external-plugins/auto-mute.ts @@ -2,18 +2,18 @@ import 'mocha' import { expect } from 'chai' +import { wait } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, killallServers, makeGetRequest, - MockBlocklist, PeerTubeServer, - setAccessTokensToServers, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode } from '@shared/models' +import { MockBlocklist } from '../shared' describe('Official plugin auto-mute', function () { const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' diff --git a/server/tests/helpers/image.ts b/server/tests/helpers/image.ts index 330139ee4..64bd373cc 100644 --- a/server/tests/helpers/image.ts +++ b/server/tests/helpers/image.ts @@ -4,8 +4,8 @@ import 'mocha' import { expect } from 'chai' import { readFile, remove } from 'fs-extra' import { join } from 'path' +import { buildAbsoluteFixturePath, root } from '@shared/core-utils' import { processImage } from '../../../server/helpers/image-utils' -import { buildAbsoluteFixturePath, root } from '../../../shared/server-commands' async function checkBuffers (path1: string, path2: string, equals: boolean) { const [ buf1, buf2 ] = await Promise.all([ diff --git a/server/tests/helpers/request.ts b/server/tests/helpers/request.ts index db0cca390..de507ba35 100644 --- a/server/tests/helpers/request.ts +++ b/server/tests/helpers/request.ts @@ -4,9 +4,9 @@ import 'mocha' import { expect } from 'chai' import { pathExists, remove } from 'fs-extra' import { join } from 'path' -import { Mock429 } from '@shared/server-commands/mock-servers/mock-429' -import { FIXTURE_URLS, root, wait } from '../../../shared/server-commands' +import { root, wait } from '@shared/core-utils' import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' +import { FIXTURE_URLS, Mock429 } from '../shared' describe('Request helpers', function () { const destPath1 = join(root(), 'test-output-1.txt') diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts index a4a3764f5..583100671 100644 --- a/server/tests/plugins/external-auth.ts +++ b/server/tests/plugins/external-auth.ts @@ -2,16 +2,16 @@ import 'mocha' import { expect } from 'chai' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, UserRole } from '@shared/models' import { cleanupTests, createSingleServer, decodeQueryString, PeerTubeServer, PluginsCommand, - setAccessTokensToServers, - wait + setAccessTokensToServers } from '@shared/server-commands' -import { HttpStatusCode, UserRole } from '@shared/models' async function loginExternal (options: { server: PeerTubeServer diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index a84edfac6..52ba396e5 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -2,11 +2,11 @@ import 'mocha' import * as chai from 'chai' +import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' import { cleanupTests, createMultipleServers, doubleFollow, - FIXTURE_URLS, makeRawRequest, PeerTubeServer, PluginsCommand, @@ -14,7 +14,7 @@ import { setDefaultVideoChannel, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, VideoDetails, VideoImportState, VideoPlaylist, VideoPlaylistPrivacy, VideoPrivacy } from '@shared/models' +import { FIXTURE_URLS } from '../shared' const expect = chai.expect diff --git a/server/tests/plugins/html-injection.ts b/server/tests/plugins/html-injection.ts index 9e10d3302..0a3a9c25f 100644 --- a/server/tests/plugins/html-injection.ts +++ b/server/tests/plugins/html-injection.ts @@ -9,7 +9,7 @@ import { PeerTubeServer, PluginsCommand, setAccessTokensToServers -} from '../../../shared/server-commands' +} from '@shared/server-commands' const expect = chai.expect diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts index ea3b0f6ab..e72046ce2 100644 --- a/server/tests/plugins/id-and-pass-auth.ts +++ b/server/tests/plugins/id-and-pass-auth.ts @@ -2,8 +2,9 @@ import 'mocha' import { expect } from 'chai' -import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers, wait } from '@shared/server-commands' +import { wait } from '@shared/core-utils' import { HttpStatusCode, UserRole } from '@shared/models' +import { cleanupTests, createSingleServer, PeerTubeServer, PluginsCommand, setAccessTokensToServers } from '@shared/server-commands' describe('Test id and pass auth plugins', function () { let server: PeerTubeServer diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 4ab4acd58..167429ef4 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -3,8 +3,8 @@ import 'mocha' import { expect } from 'chai' import { pathExists } from 'fs-extra' +import { HttpStatusCode, ThumbnailType } from '@shared/models' import { - checkVideoFilesWereRemoved, cleanupTests, createMultipleServers, doubleFollow, @@ -16,7 +16,7 @@ import { setAccessTokensToServers, waitJobs } from '@shared/server-commands' -import { HttpStatusCode, ThumbnailType } from '@shared/models' +import { checkVideoFilesWereRemoved } from '../shared' function postCommand (server: PeerTubeServer, command: string, bodyArg?: object) { const body = { command } diff --git a/server/tests/shared/actors.ts b/server/tests/shared/actors.ts new file mode 100644 index 000000000..f8f4a5137 --- /dev/null +++ b/server/tests/shared/actors.ts @@ -0,0 +1,73 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { pathExists, readdir } from 'fs-extra' +import { join } from 'path' +import { root } from '@shared/core-utils' +import { Account, VideoChannel } from '@shared/models' +import { PeerTubeServer } from '@shared/server-commands' + +async function expectChannelsFollows (options: { + server: PeerTubeServer + handle: string + followers: number + following: number +}) { + const { server } = options + const { data } = await server.channels.list() + + return expectActorFollow({ ...options, data }) +} + +async function expectAccountFollows (options: { + server: PeerTubeServer + handle: string + followers: number + following: number +}) { + const { server } = options + const { data } = await server.accounts.list() + + return expectActorFollow({ ...options, data }) +} + +async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { + const testDirectory = 'test' + serverNumber + + for (const directory of [ 'avatars' ]) { + const directoryPath = join(root(), testDirectory, directory) + + const directoryExists = await pathExists(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdir(directoryPath) + for (const file of files) { + expect(file).to.not.contain(filename) + } + } +} + +export { + expectAccountFollows, + expectChannelsFollows, + checkActorFilesWereRemoved +} + +// --------------------------------------------------------------------------- + +function expectActorFollow (options: { + server: PeerTubeServer + data: (Account | VideoChannel)[] + handle: string + followers: number + following: number +}) { + const { server, data, handle, followers, following } = options + + const actor = data.find(a => a.name + '@' + a.host === handle) + const message = `${handle} on ${server.url}` + + expect(actor, message).to.exist + expect(actor.followersCount).to.equal(followers, message) + expect(actor.followingCount).to.equal(following, message) +} diff --git a/server/tests/shared/captions.ts b/server/tests/shared/captions.ts new file mode 100644 index 000000000..35e722408 --- /dev/null +++ b/server/tests/shared/captions.ts @@ -0,0 +1,21 @@ +import { expect } from 'chai' +import request from 'supertest' +import { HttpStatusCode } from '@shared/models' + +async function testCaptionFile (url: string, captionPath: string, toTest: RegExp | string) { + const res = await request(url) + .get(captionPath) + .expect(HttpStatusCode.OK_200) + + if (toTest instanceof RegExp) { + expect(res.text).to.match(toTest) + } else { + expect(res.text).to.contain(toTest) + } +} + +// --------------------------------------------------------------------------- + +export { + testCaptionFile +} diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts new file mode 100644 index 000000000..9ecc84b5d --- /dev/null +++ b/server/tests/shared/checks.ts @@ -0,0 +1,98 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ + +import { expect } from 'chai' +import { pathExists, readFile } from 'fs-extra' +import { join } from 'path' +import { root } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' +import { makeGetRequest, PeerTubeServer } from '@shared/server-commands' + +// Default interval -> 5 minutes +function dateIsValid (dateString: string, interval = 300000) { + const dateToCheck = new Date(dateString) + const now = new Date() + + return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval +} + +function expectStartWith (str: string, start: string) { + expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true +} + +async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { + const content = await server.servers.getLogContent() + + expect(content.toString()).to.not.contain(str) +} + +async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { + const res = await makeGetRequest({ + url, + path: imagePath, + expectedStatus: HttpStatusCode.OK_200 + }) + + const body = res.body + + const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) + const minLength = body.length - ((30 * body.length) / 100) + const maxLength = body.length + ((30 * body.length) / 100) + + expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') + expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') +} + +async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { + const base = server.servers.buildDirectory(directory) + + expect(await pathExists(join(base, filePath))).to.equal(exist) +} + +function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { + return makeGetRequest({ + url, + path, + token, + query: { ...query, start: 'hello' }, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) +} + +async function checkBadCountPagination (url: string, path: string, token?: string, query = {}) { + await makeGetRequest({ + url, + path, + token, + query: { ...query, count: 'hello' }, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) + + await makeGetRequest({ + url, + path, + token, + query: { ...query, count: 2000 }, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) +} + +function checkBadSortPagination (url: string, path: string, token?: string, query = {}) { + return makeGetRequest({ + url, + path, + token, + query: { ...query, sort: 'hello' }, + expectedStatus: HttpStatusCode.BAD_REQUEST_400 + }) +} + +export { + dateIsValid, + testImage, + expectLogDoesNotContain, + testFileExistsOrNot, + expectStartWith, + checkBadStartPagination, + checkBadCountPagination, + checkBadSortPagination +} diff --git a/server/tests/shared/directories.ts b/server/tests/shared/directories.ts new file mode 100644 index 000000000..c7065a767 --- /dev/null +++ b/server/tests/shared/directories.ts @@ -0,0 +1,34 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { pathExists, readdir } from 'fs-extra' +import { join } from 'path' +import { root } from '@shared/core-utils' +import { PeerTubeServer } from '@shared/server-commands' + +async function checkTmpIsEmpty (server: PeerTubeServer) { + await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) + + if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { + await checkDirectoryIsEmpty(server, 'tmp/hls') + } +} + +async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { + const testDirectory = 'test' + server.internalServerNumber + + const directoryPath = join(root(), testDirectory, directory) + + const directoryExists = await pathExists(directoryPath) + expect(directoryExists).to.be.true + + const files = await readdir(directoryPath) + const filtered = files.filter(f => exceptions.includes(f) === false) + + expect(filtered).to.have.lengthOf(0) +} + +export { + checkTmpIsEmpty, + checkDirectoryIsEmpty +} diff --git a/server/tests/shared/generate.ts b/server/tests/shared/generate.ts new file mode 100644 index 000000000..f806df2f5 --- /dev/null +++ b/server/tests/shared/generate.ts @@ -0,0 +1,74 @@ +import { expect } from 'chai' +import ffmpeg from 'fluent-ffmpeg' +import { ensureDir, pathExists } from 'fs-extra' +import { dirname } from 'path' +import { buildAbsoluteFixturePath, getMaxBitrate } from '@shared/core-utils' +import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils' + +async function ensureHasTooBigBitrate (fixturePath: string) { + const bitrate = await getVideoFileBitrate(fixturePath) + const dataResolution = await getVideoFileResolution(fixturePath) + const fps = await getVideoFileFPS(fixturePath) + + const maxBitrate = getMaxBitrate({ ...dataResolution, fps }) + expect(bitrate).to.be.above(maxBitrate) +} + +async function generateHighBitrateVideo () { + const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true) + + await ensureDir(dirname(tempFixturePath)) + + const exists = await pathExists(tempFixturePath) + if (!exists) { + console.log('Generating high bitrate video.') + + // Generate a random, high bitrate video on the fly, so we don't have to include + // a large file in the repo. The video needs to have a certain minimum length so + // that FFmpeg properly applies bitrate limits. + // https://stackoverflow.com/a/15795112 + return new Promise((res, rej) => { + ffmpeg() + .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ]) + .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) + .outputOptions([ '-maxrate 10M', '-bufsize 10M' ]) + .output(tempFixturePath) + .on('error', rej) + .on('end', () => res(tempFixturePath)) + .run() + }) + } + + await ensureHasTooBigBitrate(tempFixturePath) + + return tempFixturePath +} + +async function generateVideoWithFramerate (fps = 60) { + const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true) + + await ensureDir(dirname(tempFixturePath)) + + const exists = await pathExists(tempFixturePath) + if (!exists) { + console.log('Generating video with framerate %d.', fps) + + return new Promise((res, rej) => { + ffmpeg() + .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ]) + .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) + .outputOptions([ `-r ${fps}` ]) + .output(tempFixturePath) + .on('error', rej) + .on('end', () => res(tempFixturePath)) + .run() + }) + } + + return tempFixturePath +} + +export { + generateHighBitrateVideo, + generateVideoWithFramerate +} diff --git a/server/tests/shared/index.ts b/server/tests/shared/index.ts index 938817268..47019d6a8 100644 --- a/server/tests/shared/index.ts +++ b/server/tests/shared/index.ts @@ -1,2 +1,15 @@ +export * from './mock-servers' +export * from './actors' +export * from './captions' +export * from './checks' +export * from './directories' +export * from './generate' +export * from './live' +export * from './notifications' +export * from './playlists' +export * from './plugins' export * from './requests' -export * from './video' +export * from './streaming-playlists' +export * from './tests' +export * from './tracker' +export * from './videos' diff --git a/server/tests/shared/live.ts b/server/tests/shared/live.ts new file mode 100644 index 000000000..72e3e27f6 --- /dev/null +++ b/server/tests/shared/live.ts @@ -0,0 +1,41 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { pathExists, readdir } from 'fs-extra' +import { join } from 'path' +import { PeerTubeServer } from '@shared/server-commands' + +async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { + const basePath = server.servers.buildDirectory('streaming-playlists') + const hlsPath = join(basePath, 'hls', videoUUID) + + if (resolutions.length === 0) { + const result = await pathExists(hlsPath) + expect(result).to.be.false + + return + } + + const files = await readdir(hlsPath) + + // fragmented file and playlist per resolution + master playlist + segments sha256 json file + expect(files).to.have.lengthOf(resolutions.length * 2 + 2) + + for (const resolution of resolutions) { + const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) + expect(fragmentedFile).to.exist + + const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) + expect(playlistFile).to.exist + } + + const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) + expect(masterPlaylistFile).to.exist + + const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) + expect(shaFile).to.exist +} + +export { + checkLiveCleanupAfterSave +} diff --git a/server/tests/shared/mock-servers/index.ts b/server/tests/shared/mock-servers/index.ts new file mode 100644 index 000000000..abf4a8203 --- /dev/null +++ b/server/tests/shared/mock-servers/index.ts @@ -0,0 +1,7 @@ +export * from './mock-429' +export * from './mock-email' +export * from './mock-instances-index' +export * from './mock-joinpeertube-versions' +export * from './mock-object-storage' +export * from './mock-plugin-blocklist' +export * from './mock-proxy' diff --git a/server/tests/shared/mock-servers/mock-429.ts b/server/tests/shared/mock-servers/mock-429.ts new file mode 100644 index 000000000..1fc20b079 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-429.ts @@ -0,0 +1,33 @@ +import express from 'express' +import { Server } from 'http' +import { getPort, randomListen, terminateServer } from './shared' + +export class Mock429 { + private server: Server + private responseSent = false + + async initialize () { + const app = express() + + app.get('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { + + if (!this.responseSent) { + this.responseSent = true + + // Retry after 5 seconds + res.header('retry-after', '2') + return res.sendStatus(429) + } + + return res.sendStatus(200) + }) + + this.server = await randomListen(app) + + return getPort(this.server) + } + + terminate () { + return terminateServer(this.server) + } +} diff --git a/server/tests/shared/mock-servers/mock-email.ts b/server/tests/shared/mock-servers/mock-email.ts new file mode 100644 index 000000000..c518679c9 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-email.ts @@ -0,0 +1,62 @@ +import { ChildProcess } from 'child_process' +import MailDev from '@peertube/maildev' +import { parallelTests, randomInt } from '@shared/core-utils' + +class MockSmtpServer { + + private static instance: MockSmtpServer + private started = false + private emailChildProcess: ChildProcess + private emails: object[] + + private constructor () { } + + collectEmails (emailsCollection: object[]) { + return new Promise((res, rej) => { + const port = parallelTests() ? randomInt(1000, 2000) : 1025 + this.emails = emailsCollection + + if (this.started) { + return res(undefined) + } + + const maildev = new MailDev({ + ip: '127.0.0.1', + smtp: port, + disableWeb: true, + silent: true + }) + + maildev.on('new', email => { + this.emails.push(email) + }) + + maildev.listen(err => { + if (err) return rej(err) + + this.started = true + + return res(port) + }) + }) + } + + kill () { + if (!this.emailChildProcess) return + + process.kill(this.emailChildProcess.pid) + + this.emailChildProcess = null + MockSmtpServer.instance = null + } + + static get Instance () { + return this.instance || (this.instance = new this()) + } +} + +// --------------------------------------------------------------------------- + +export { + MockSmtpServer +} diff --git a/server/tests/shared/mock-servers/mock-instances-index.ts b/server/tests/shared/mock-servers/mock-instances-index.ts new file mode 100644 index 000000000..598b007f1 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-instances-index.ts @@ -0,0 +1,46 @@ +import express from 'express' +import { Server } from 'http' +import { getPort, randomListen, terminateServer } from './shared' + +export class MockInstancesIndex { + private server: Server + + private readonly indexInstances: { host: string, createdAt: string }[] = [] + + async initialize () { + const app = express() + + app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) + + return next() + }) + + app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => { + const since = req.query.since + + const filtered = this.indexInstances.filter(i => { + if (!since) return true + + return i.createdAt > since + }) + + return res.json({ + total: filtered.length, + data: filtered + }) + }) + + this.server = await randomListen(app) + + return getPort(this.server) + } + + addInstance (host: string) { + this.indexInstances.push({ host, createdAt: new Date().toISOString() }) + } + + terminate () { + return terminateServer(this.server) + } +} diff --git a/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts b/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts new file mode 100644 index 000000000..502f4e2f5 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-joinpeertube-versions.ts @@ -0,0 +1,34 @@ +import express from 'express' +import { Server } from 'http' +import { getPort, randomListen } from './shared' + +export class MockJoinPeerTubeVersions { + private server: Server + private latestVersion: string + + async initialize () { + const app = express() + + app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) + + return next() + }) + + app.get('/versions.json', (req: express.Request, res: express.Response) => { + return res.json({ + peertube: { + latestVersion: this.latestVersion + } + }) + }) + + this.server = await randomListen(app) + + return getPort(this.server) + } + + setLatestVersion (latestVersion: string) { + this.latestVersion = latestVersion + } +} diff --git a/server/tests/shared/mock-servers/mock-object-storage.ts b/server/tests/shared/mock-servers/mock-object-storage.ts new file mode 100644 index 000000000..99d68e014 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-object-storage.ts @@ -0,0 +1,41 @@ +import express from 'express' +import got, { RequestError } from 'got' +import { Server } from 'http' +import { pipeline } from 'stream' +import { ObjectStorageCommand } from '@shared/server-commands' +import { getPort, randomListen, terminateServer } from './shared' + +export class MockObjectStorage { + private server: Server + + async initialize () { + const app = express() + + app.get('/:bucketName/:path(*)', (req: express.Request, res: express.Response, next: express.NextFunction) => { + const url = `http://${req.params.bucketName}.${ObjectStorageCommand.getEndpointHost()}/${req.params.path}` + + if (process.env.DEBUG) { + console.log('Receiving request on mocked server %s.', req.url) + console.log('Proxifying request to %s', url) + } + + return pipeline( + got.stream(url, { throwHttpErrors: false }), + res, + (err: RequestError) => { + if (!err) return + + console.error('Pipeline failed.', err) + } + ) + }) + + this.server = await randomListen(app) + + return getPort(this.server) + } + + terminate () { + return terminateServer(this.server) + } +} diff --git a/server/tests/shared/mock-servers/mock-plugin-blocklist.ts b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts new file mode 100644 index 000000000..5d6e01816 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-plugin-blocklist.ts @@ -0,0 +1,36 @@ +import express, { Request, Response } from 'express' +import { Server } from 'http' +import { getPort, randomListen, terminateServer } from './shared' + +type BlocklistResponse = { + data: { + value: string + action?: 'add' | 'remove' + updatedAt?: string + }[] +} + +export class MockBlocklist { + private body: BlocklistResponse + private server: Server + + async initialize () { + const app = express() + + app.get('/blocklist', (req: Request, res: Response) => { + return res.json(this.body) + }) + + this.server = await randomListen(app) + + return getPort(this.server) + } + + replace (body: BlocklistResponse) { + this.body = body + } + + terminate () { + return terminateServer(this.server) + } +} diff --git a/server/tests/shared/mock-servers/mock-proxy.ts b/server/tests/shared/mock-servers/mock-proxy.ts new file mode 100644 index 000000000..cbc7c4466 --- /dev/null +++ b/server/tests/shared/mock-servers/mock-proxy.ts @@ -0,0 +1,24 @@ +import { createServer, Server } from 'http' +import proxy from 'proxy' +import { getPort, terminateServer } from './shared' + +class MockProxy { + private server: Server + + initialize () { + return new Promise(res => { + this.server = proxy(createServer()) + this.server.listen(0, () => res(getPort(this.server))) + }) + } + + terminate () { + return terminateServer(this.server) + } +} + +// --------------------------------------------------------------------------- + +export { + MockProxy +} diff --git a/server/tests/shared/mock-servers/shared.ts b/server/tests/shared/mock-servers/shared.ts new file mode 100644 index 000000000..235642439 --- /dev/null +++ b/server/tests/shared/mock-servers/shared.ts @@ -0,0 +1,33 @@ +import { Express } from 'express' +import { Server } from 'http' +import { AddressInfo } from 'net' + +function randomListen (app: Express) { + return new Promise(res => { + const server = app.listen(0, () => res(server)) + }) +} + +function getPort (server: Server) { + const address = server.address() as AddressInfo + + return address.port +} + +function terminateServer (server: Server) { + if (!server) return Promise.resolve() + + return new Promise((res, rej) => { + server.close(err => { + if (err) return rej(err) + + return res() + }) + }) +} + +export { + randomListen, + getPort, + terminateServer +} diff --git a/server/tests/shared/notifications.ts b/server/tests/shared/notifications.ts new file mode 100644 index 000000000..cdc21fdc8 --- /dev/null +++ b/server/tests/shared/notifications.ts @@ -0,0 +1,798 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { inspect } from 'util' +import { + AbuseState, + PluginType, + UserNotification, + UserNotificationSetting, + UserNotificationSettingValue, + UserNotificationType +} from '@shared/models' +import { createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands' +import { MockSmtpServer } from './mock-servers' + +type CheckerBaseParams = { + server: PeerTubeServer + emails: any[] + socketNotifications: UserNotification[] + token: string + check?: { web: boolean, mail: boolean } +} + +type CheckerType = 'presence' | 'absence' + +function getAllNotificationsSettings (): UserNotificationSetting { + return { + newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, + newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL + } +} + +async function checkNewVideoFromSubscription (options: CheckerBaseParams & { + videoName: string + shortUUID: string + checkType: CheckerType +}) { + const { videoName, shortUUID } = options + const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkVideo(notification.video, videoName, shortUUID) + checkActor(notification.video.channel) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkVideoIsPublished (options: CheckerBaseParams & { + videoName: string + shortUUID: string + checkType: CheckerType +}) { + const { videoName, shortUUID } = options + const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkVideo(notification.video, videoName, shortUUID) + checkActor(notification.video.channel) + } else { + expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + return text.includes(shortUUID) && text.includes('Your video') + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkMyVideoImportIsFinished (options: CheckerBaseParams & { + videoName: string + shortUUID: string + url: string + success: boolean + checkType: CheckerType +}) { + const { videoName, shortUUID, url, success } = options + + const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.videoImport.targetUrl).to.equal(url) + + if (success) checkVideo(notification.videoImport.video, videoName, shortUUID) + } else { + expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + const toFind = success ? ' finished' : ' error' + + return text.includes(url) && text.includes(toFind) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkUserRegistered (options: CheckerBaseParams & { + username: string + checkType: CheckerType +}) { + const { username } = options + const notificationType = UserNotificationType.NEW_USER_REGISTRATION + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkActor(notification.account) + expect(notification.account.name).to.equal(username) + } else { + expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + + return text.includes(' registered.') && text.includes(username) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewActorFollow (options: CheckerBaseParams & { + followType: 'channel' | 'account' + followerName: string + followerDisplayName: string + followingDisplayName: string + checkType: CheckerType +}) { + const { followType, followerName, followerDisplayName, followingDisplayName } = options + const notificationType = UserNotificationType.NEW_FOLLOW + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkActor(notification.actorFollow.follower) + expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName) + expect(notification.actorFollow.follower.name).to.equal(followerName) + expect(notification.actorFollow.follower.host).to.not.be.undefined + + const following = notification.actorFollow.following + expect(following.displayName).to.equal(followingDisplayName) + expect(following.type).to.equal(followType) + } else { + expect(notification).to.satisfy(n => { + return n.type !== notificationType || + (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName) + }) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + + return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewInstanceFollower (options: CheckerBaseParams & { + followerHost: string + checkType: CheckerType +}) { + const { followerHost } = options + const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkActor(notification.actorFollow.follower) + expect(notification.actorFollow.follower.name).to.equal('peertube') + expect(notification.actorFollow.follower.host).to.equal(followerHost) + + expect(notification.actorFollow.following.name).to.equal('peertube') + } else { + expect(notification).to.satisfy(n => { + return n.type !== notificationType || n.actorFollow.follower.host !== followerHost + }) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + + return text.includes('instance has a new follower') && text.includes(followerHost) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkAutoInstanceFollowing (options: CheckerBaseParams & { + followerHost: string + followingHost: string + checkType: CheckerType +}) { + const { followerHost, followingHost } = options + const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + const following = notification.actorFollow.following + checkActor(following) + expect(following.name).to.equal('peertube') + expect(following.host).to.equal(followingHost) + + expect(notification.actorFollow.follower.name).to.equal('peertube') + expect(notification.actorFollow.follower.host).to.equal(followerHost) + } else { + expect(notification).to.satisfy(n => { + return n.type !== notificationType || n.actorFollow.following.host !== followingHost + }) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + + return text.includes(' automatically followed a new instance') && text.includes(followingHost) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkCommentMention (options: CheckerBaseParams & { + shortUUID: string + commentId: number + threadId: number + byAccountDisplayName: string + checkType: CheckerType +}) { + const { shortUUID, commentId, threadId, byAccountDisplayName } = options + const notificationType = UserNotificationType.COMMENT_MENTION + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkComment(notification.comment, commentId, threadId) + checkActor(notification.comment.account) + expect(notification.comment.account.displayName).to.equal(byAccountDisplayName) + + checkVideo(notification.comment.video, undefined, shortUUID) + } else { + expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId) + } + } + + function emailNotificationFinder (email: object) { + const text: string = email['text'] + + return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +let lastEmailCount = 0 + +async function checkNewCommentOnMyVideo (options: CheckerBaseParams & { + shortUUID: string + commentId: number + threadId: number + checkType: CheckerType +}) { + const { server, shortUUID, commentId, threadId, checkType, emails } = options + const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + checkComment(notification.comment, commentId, threadId) + checkActor(notification.comment.account) + checkVideo(notification.comment.video, undefined, shortUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.comment === undefined || n.comment.id !== commentId + }) + } + } + + const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}` + + function emailNotificationFinder (email: object) { + return email['text'].indexOf(commentUrl) !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) + + if (checkType === 'presence') { + // We cannot detect email duplicates, so check we received another email + expect(emails).to.have.length.above(lastEmailCount) + lastEmailCount = emails.length + } +} + +async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & { + shortUUID: string + videoName: string + checkType: CheckerType +}) { + const { shortUUID, videoName } = options + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.be.a('number') + checkVideo(notification.abuse.video, videoName, shortUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewAbuseMessage (options: CheckerBaseParams & { + abuseId: number + message: string + toEmail: string + checkType: CheckerType +}) { + const { abuseId, message, toEmail } = options + const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.equal(abuseId) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + const to = email['to'].filter(t => t.address === toEmail) + + return text.indexOf(message) !== -1 && to.length !== 0 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkAbuseStateChange (options: CheckerBaseParams & { + abuseId: number + state: AbuseState + checkType: CheckerType +}) { + const { abuseId, state } = options + const notificationType = UserNotificationType.ABUSE_STATE_CHANGE + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.equal(abuseId) + expect(notification.abuse.state).to.equal(state) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + + const contains = state === AbuseState.ACCEPTED + ? ' accepted' + : ' rejected' + + return text.indexOf(contains) !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & { + shortUUID: string + videoName: string + checkType: CheckerType +}) { + const { shortUUID, videoName } = options + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.be.a('number') + checkVideo(notification.abuse.comment.video, videoName, shortUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & { + displayName: string + checkType: CheckerType +}) { + const { displayName } = options + const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.abuse.id).to.be.a('number') + expect(notification.abuse.account.displayName).to.equal(displayName) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & { + shortUUID: string + videoName: string + checkType: CheckerType +}) { + const { shortUUID, videoName } = options + const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.videoBlacklist.video.id).to.be.a('number') + checkVideo(notification.videoBlacklist.video, videoName, shortUUID) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1 + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & { + shortUUID: string + videoName: string + blacklistType: 'blacklist' | 'unblacklist' +}) { + const { videoName, shortUUID, blacklistType } = options + const notificationType = blacklistType === 'blacklist' + ? UserNotificationType.BLACKLIST_ON_MY_VIDEO + : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO + + function notificationChecker (notification: UserNotification) { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video + + checkVideo(video, videoName, shortUUID) + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + const blacklistText = blacklistType === 'blacklist' + ? 'blacklisted' + : 'unblacklisted' + + return text.includes(shortUUID) && text.includes(blacklistText) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' }) +} + +async function checkNewPeerTubeVersion (options: CheckerBaseParams & { + latestVersion: string + checkType: CheckerType +}) { + const { latestVersion } = options + const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.peertube).to.exist + expect(notification.peertube.latestVersion).to.equal(latestVersion) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + + return text.includes(latestVersion) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function checkNewPluginVersion (options: CheckerBaseParams & { + pluginType: PluginType + pluginName: string + checkType: CheckerType +}) { + const { pluginName, pluginType } = options + const notificationType = UserNotificationType.NEW_PLUGIN_VERSION + + function notificationChecker (notification: UserNotification, checkType: CheckerType) { + if (checkType === 'presence') { + expect(notification).to.not.be.undefined + expect(notification.type).to.equal(notificationType) + + expect(notification.plugin.name).to.equal(pluginName) + expect(notification.plugin.type).to.equal(pluginType) + } else { + expect(notification).to.satisfy((n: UserNotification) => { + return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName + }) + } + } + + function emailNotificationFinder (email: object) { + const text = email['text'] + + return text.includes(pluginName) + } + + await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) +} + +async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { + const userNotifications: UserNotification[] = [] + const adminNotifications: UserNotification[] = [] + const adminNotificationsServer2: UserNotification[] = [] + const emails: object[] = [] + + const port = await MockSmtpServer.Instance.collectEmails(emails) + + const overrideConfig = { + smtp: { + hostname: 'localhost', + port + }, + signup: { + limit: 20 + } + } + const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) + + await setAccessTokensToServers(servers) + + if (serversCount > 1) { + await doubleFollow(servers[0], servers[1]) + } + + const user = { username: 'user_1', password: 'super password' } + await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 }) + const userAccessToken = await servers[0].login.getAccessToken(user) + + await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() }) + await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() }) + + if (serversCount > 1) { + await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() }) + } + + { + const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken }) + socket.on('new-notification', n => userNotifications.push(n)) + } + { + const socket = servers[0].socketIO.getUserNotificationSocket() + socket.on('new-notification', n => adminNotifications.push(n)) + } + + if (serversCount > 1) { + const socket = servers[1].socketIO.getUserNotificationSocket() + socket.on('new-notification', n => adminNotificationsServer2.push(n)) + } + + const { videoChannels } = await servers[0].users.getMyInfo() + const channelId = videoChannels[0].id + + return { + userNotifications, + adminNotifications, + adminNotificationsServer2, + userAccessToken, + emails, + servers, + channelId + } +} + +// --------------------------------------------------------------------------- + +export { + getAllNotificationsSettings, + + CheckerBaseParams, + CheckerType, + checkMyVideoImportIsFinished, + checkUserRegistered, + checkAutoInstanceFollowing, + checkVideoIsPublished, + checkNewVideoFromSubscription, + checkNewActorFollow, + checkNewCommentOnMyVideo, + checkNewBlacklistOnMyVideo, + checkCommentMention, + checkNewVideoAbuseForModerators, + checkVideoAutoBlacklistForModerators, + checkNewAbuseMessage, + checkAbuseStateChange, + checkNewInstanceFollower, + prepareNotificationsTest, + checkNewCommentAbuseForModerators, + checkNewAccountAbuseForModerators, + checkNewPeerTubeVersion, + checkNewPluginVersion +} + +// --------------------------------------------------------------------------- + +async function checkNotification (options: CheckerBaseParams & { + notificationChecker: (notification: UserNotification, checkType: CheckerType) => void + emailNotificationFinder: (email: object) => boolean + checkType: CheckerType +}) { + const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options + + const check = options.check || { web: true, mail: true } + + if (check.web) { + const notification = await server.notifications.getLatest({ token: token }) + + if (notification || checkType !== 'absence') { + notificationChecker(notification, checkType) + } + + const socketNotification = socketNotifications.find(n => { + try { + notificationChecker(n, 'presence') + return true + } catch { + return false + } + }) + + if (checkType === 'presence') { + const obj = inspect(socketNotifications, { depth: 5 }) + expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined + } else { + const obj = inspect(socketNotification, { depth: 5 }) + expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined + } + } + + if (check.mail) { + // Last email + const email = emails + .slice() + .reverse() + .find(e => emailNotificationFinder(e)) + + if (checkType === 'presence') { + const texts = emails.map(e => e.text) + expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined + } else { + expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined + } + } +} + +function checkVideo (video: any, videoName?: string, shortUUID?: string) { + if (videoName) { + expect(video.name).to.be.a('string') + expect(video.name).to.not.be.empty + expect(video.name).to.equal(videoName) + } + + if (shortUUID) { + expect(video.shortUUID).to.be.a('string') + expect(video.shortUUID).to.not.be.empty + expect(video.shortUUID).to.equal(shortUUID) + } + + expect(video.id).to.be.a('number') +} + +function checkActor (actor: any) { + expect(actor.displayName).to.be.a('string') + expect(actor.displayName).to.not.be.empty + expect(actor.host).to.not.be.undefined +} + +function checkComment (comment: any, commentId: number, threadId: number) { + expect(comment.id).to.equal(commentId) + expect(comment.threadId).to.equal(threadId) +} diff --git a/server/tests/shared/playlists.ts b/server/tests/shared/playlists.ts new file mode 100644 index 000000000..fdd541d20 --- /dev/null +++ b/server/tests/shared/playlists.ts @@ -0,0 +1,25 @@ +import { expect } from 'chai' +import { readdir } from 'fs-extra' +import { join } from 'path' +import { root } from '@shared/core-utils' + +async function checkPlaylistFilesWereRemoved ( + playlistUUID: string, + internalServerNumber: number, + directories = [ 'thumbnails' ] +) { + const testDirectory = 'test' + internalServerNumber + + for (const directory of directories) { + const directoryPath = join(root(), testDirectory, directory) + + const files = await readdir(directoryPath) + for (const file of files) { + expect(file).to.not.contain(playlistUUID) + } + } +} + +export { + checkPlaylistFilesWereRemoved +} diff --git a/server/tests/shared/plugins.ts b/server/tests/shared/plugins.ts new file mode 100644 index 000000000..036fce2ff --- /dev/null +++ b/server/tests/shared/plugins.ts @@ -0,0 +1,18 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import { expect } from 'chai' +import { PeerTubeServer } from '@shared/server-commands' + +async function testHelloWorldRegisteredSettings (server: PeerTubeServer) { + const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) + + const registeredSettings = body.registeredSettings + expect(registeredSettings).to.have.length.at.least(1) + + const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') + expect(adminNameSettings).to.not.be.undefined +} + +export { + testHelloWorldRegisteredSettings +} diff --git a/server/tests/shared/requests.ts b/server/tests/shared/requests.ts index 9eb596029..7f1acc0e1 100644 --- a/server/tests/shared/requests.ts +++ b/server/tests/shared/requests.ts @@ -1,7 +1,7 @@ -import { doRequest } from '@server/helpers/requests' import { activityPubContextify } from '@server/helpers/activitypub' -import { HTTP_SIGNATURE } from '@server/initializers/constants' -import { buildGlobalHeaders } from '@server/lib/job-queue/handlers/utils/activitypub-http-utils' +import { buildDigest } from '@server/helpers/peertube-crypto' +import { doRequest } from '@server/helpers/requests' +import { ACTIVITY_PUB, HTTP_SIGNATURE } from '@server/initializers/constants' export function makePOSTAPRequest (url: string, body: any, httpSignature: any, headers: any) { const options = { @@ -31,7 +31,11 @@ export async function makeFollowRequest (to: { url: string }, by: { url: string, key: by.privateKey, headers: HTTP_SIGNATURE.HEADERS_TO_SIGN } - const headers = buildGlobalHeaders(body) + const headers = { + 'digest': buildDigest(body), + 'content-type': 'application/activity+json', + 'accept': ACTIVITY_PUB.ACCEPT_HEADER + } return makePOSTAPRequest(to.url + '/inbox', body, httpSignature, headers) } diff --git a/server/tests/shared/streaming-playlists.ts b/server/tests/shared/streaming-playlists.ts new file mode 100644 index 000000000..738dc90e1 --- /dev/null +++ b/server/tests/shared/streaming-playlists.ts @@ -0,0 +1,77 @@ +import { expect } from 'chai' +import { basename } from 'path' +import { removeFragmentedMP4Ext } from '@shared/core-utils' +import { sha256 } from '@shared/core-utils/common/crypto' +import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' +import { PeerTubeServer } from '@shared/server-commands' + +async function checkSegmentHash (options: { + server: PeerTubeServer + baseUrlPlaylist: string + baseUrlSegment: string + resolution: number + hlsPlaylist: VideoStreamingPlaylist +}) { + const { server, baseUrlPlaylist, baseUrlSegment, resolution, hlsPlaylist } = options + const command = server.streamingPlaylists + + const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) + const videoName = basename(file.fileUrl) + + const playlist = await command.get({ url: `${baseUrlPlaylist}/${removeFragmentedMP4Ext(videoName)}.m3u8` }) + + const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) + + const length = parseInt(matches[1], 10) + const offset = parseInt(matches[2], 10) + const range = `${offset}-${offset + length - 1}` + + const segmentBody = await command.getSegment({ + url: `${baseUrlSegment}/${videoName}`, + expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206, + range: `bytes=${range}` + }) + + const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) + expect(sha256(segmentBody)).to.equal(shaBody[videoName][range]) +} + +async function checkLiveSegmentHash (options: { + server: PeerTubeServer + baseUrlSegment: string + videoUUID: string + segmentName: string + hlsPlaylist: VideoStreamingPlaylist +}) { + const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options + const command = server.streamingPlaylists + + const segmentBody = await command.getSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` }) + const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) + + expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) +} + +async function checkResolutionsInMasterPlaylist (options: { + server: PeerTubeServer + playlistUrl: string + resolutions: number[] +}) { + const { server, playlistUrl, resolutions } = options + + const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl }) + + for (const resolution of resolutions) { + const reg = new RegExp( + '#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"' + ) + + expect(masterPlaylist).to.match(reg) + } +} + +export { + checkSegmentHash, + checkLiveSegmentHash, + checkResolutionsInMasterPlaylist +} diff --git a/server/tests/shared/tests.ts b/server/tests/shared/tests.ts new file mode 100644 index 000000000..3abaf833d --- /dev/null +++ b/server/tests/shared/tests.ts @@ -0,0 +1,37 @@ +const FIXTURE_URLS = { + peertube_long: 'https://peertube2.cpy.re/videos/watch/122d093a-1ede-43bd-bd34-59d2931ffc5e', + peertube_short: 'https://peertube2.cpy.re/w/3fbif9S3WmtTP8gGsC5HBd', + + youtube: 'https://www.youtube.com/watch?v=msX3jv1XdvM', + + /** + * The video is used to check format-selection correctness wrt. HDR, + * which brings its own set of oddities outside of a MediaSource. + * + * The video needs to have the following format_ids: + * (which you can check by using `youtube-dl -F`): + * - (webm vp9) + * - (mp4 avc1) + * - (webm vp9.2 HDR) + */ + youtubeHDR: 'https://www.youtube.com/watch?v=RQgnBB9z_N4', + + // eslint-disable-next-line max-len + magnet: 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Flazy-static%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4', + + badVideo: 'https://download.cpy.re/peertube/bad_video.mp4', + goodVideo: 'https://download.cpy.re/peertube/good_video.mp4', + goodVideo720: 'https://download.cpy.re/peertube/good_video_720.mp4', + + file4K: 'https://download.cpy.re/peertube/4k_file.txt' +} + +function buildRequestStub (): any { + return { } +} + +export { + FIXTURE_URLS, + + buildRequestStub +} diff --git a/server/tests/shared/tracker.ts b/server/tests/shared/tracker.ts new file mode 100644 index 000000000..699895d5f --- /dev/null +++ b/server/tests/shared/tracker.ts @@ -0,0 +1,27 @@ +import { expect } from 'chai' +import { sha1 } from '@shared/core-utils' +import { makeGetRequest } from '@shared/server-commands' + +async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) { + const path = '/tracker/announce' + + const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`) + + // From bittorrent-tracker + const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) { + return '%' + char.charCodeAt(0).toString(16).toUpperCase() + }) + + const res = await makeGetRequest({ + url: serverUrl, + path, + rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`, + expectedStatus: 200 + }) + + expect(res.text).to.not.contain('failure') +} + +export { + hlsInfohashExist +} diff --git a/server/tests/shared/video.ts b/server/tests/shared/video.ts deleted file mode 100644 index cf923d4cd..000000000 --- a/server/tests/shared/video.ts +++ /dev/null @@ -1,150 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions */ -import { dateIsValid, makeRawRequest, PeerTubeServer, testImage, webtorrentAdd } from '@shared/server-commands' -import { expect } from 'chai' -import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '@server/initializers/constants' -import { getLowercaseExtension, uuidRegex } from '@shared/core-utils' - -loadLanguages() - -export async function completeVideoCheck ( - server: PeerTubeServer, - video: any, - attributes: { - name: string - category: number - licence: number - language: string - nsfw: boolean - commentsEnabled: boolean - downloadEnabled: boolean - description: string - publishedAt?: string - support: string - originallyPublishedAt?: string - account: { - name: string - host: string - } - isLocal: boolean - tags: string[] - privacy: number - likes?: number - dislikes?: number - duration: number - channel: { - displayName: string - name: string - description: string - isLocal: boolean - } - fixture: string - files: { - resolution: number - size: number - }[] - thumbnailfile?: string - previewfile?: string - } -) { - if (!attributes.likes) attributes.likes = 0 - if (!attributes.dislikes) attributes.dislikes = 0 - - const host = new URL(server.url).host - const originHost = attributes.account.host - - expect(video.name).to.equal(attributes.name) - expect(video.category.id).to.equal(attributes.category) - expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc') - expect(video.licence.id).to.equal(attributes.licence) - expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown') - expect(video.language.id).to.equal(attributes.language) - expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown') - expect(video.privacy.id).to.deep.equal(attributes.privacy) - expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) - expect(video.nsfw).to.equal(attributes.nsfw) - expect(video.description).to.equal(attributes.description) - expect(video.account.id).to.be.a('number') - expect(video.account.host).to.equal(attributes.account.host) - expect(video.account.name).to.equal(attributes.account.name) - expect(video.channel.displayName).to.equal(attributes.channel.displayName) - expect(video.channel.name).to.equal(attributes.channel.name) - expect(video.likes).to.equal(attributes.likes) - expect(video.dislikes).to.equal(attributes.dislikes) - expect(video.isLocal).to.equal(attributes.isLocal) - expect(video.duration).to.equal(attributes.duration) - expect(video.url).to.contain(originHost) - expect(dateIsValid(video.createdAt)).to.be.true - expect(dateIsValid(video.publishedAt)).to.be.true - expect(dateIsValid(video.updatedAt)).to.be.true - - if (attributes.publishedAt) { - expect(video.publishedAt).to.equal(attributes.publishedAt) - } - - if (attributes.originallyPublishedAt) { - expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt) - } else { - expect(video.originallyPublishedAt).to.be.null - } - - const videoDetails = await server.videos.get({ id: video.uuid }) - - expect(videoDetails.files).to.have.lengthOf(attributes.files.length) - expect(videoDetails.tags).to.deep.equal(attributes.tags) - expect(videoDetails.account.name).to.equal(attributes.account.name) - expect(videoDetails.account.host).to.equal(attributes.account.host) - expect(video.channel.displayName).to.equal(attributes.channel.displayName) - expect(video.channel.name).to.equal(attributes.channel.name) - expect(videoDetails.channel.host).to.equal(attributes.account.host) - expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) - expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true - expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true - expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) - expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled) - - for (const attributeFile of attributes.files) { - const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) - expect(file).not.to.be.undefined - - let extension = getLowercaseExtension(attributes.fixture) - // Transcoding enabled: extension will always be .mp4 - if (attributes.files.length > 1) extension = '.mp4' - - expect(file.magnetUri).to.have.lengthOf.above(2) - - expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`)) - expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`)) - - expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`)) - expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`)) - - await Promise.all([ - makeRawRequest(file.torrentUrl, 200), - makeRawRequest(file.torrentDownloadUrl, 200), - makeRawRequest(file.metadataUrl, 200) - ]) - - expect(file.resolution.id).to.equal(attributeFile.resolution) - expect(file.resolution.label).to.equal(attributeFile.resolution + 'p') - - const minSize = attributeFile.size - ((10 * attributeFile.size) / 100) - const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) - expect( - file.size, - 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')' - ).to.be.above(minSize).and.below(maxSize) - - const torrent = await webtorrentAdd(file.magnetUri, true) - expect(torrent.files).to.be.an('array') - expect(torrent.files.length).to.equal(1) - expect(torrent.files[0].path).to.exist.and.to.not.equal('') - } - - expect(videoDetails.thumbnailPath).to.exist - await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) - - if (attributes.previewfile) { - expect(videoDetails.previewPath).to.exist - await testImage(server.url, attributes.previewfile, videoDetails.previewPath) - } -} diff --git a/server/tests/shared/videos.ts b/server/tests/shared/videos.ts new file mode 100644 index 000000000..6be094f2b --- /dev/null +++ b/server/tests/shared/videos.ts @@ -0,0 +1,251 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ + +import { expect } from 'chai' +import { pathExists, readdir } from 'fs-extra' +import { basename, join } from 'path' +import { loadLanguages, VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '@server/initializers/constants' +import { getLowercaseExtension, uuidRegex } from '@shared/core-utils' +import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models' +import { makeRawRequest, PeerTubeServer, VideoEdit, waitJobs, webtorrentAdd } from '@shared/server-commands' +import { dateIsValid, testImage } from './checks' + +loadLanguages() + +async function completeVideoCheck ( + server: PeerTubeServer, + video: any, + attributes: { + name: string + category: number + licence: number + language: string + nsfw: boolean + commentsEnabled: boolean + downloadEnabled: boolean + description: string + publishedAt?: string + support: string + originallyPublishedAt?: string + account: { + name: string + host: string + } + isLocal: boolean + tags: string[] + privacy: number + likes?: number + dislikes?: number + duration: number + channel: { + displayName: string + name: string + description: string + isLocal: boolean + } + fixture: string + files: { + resolution: number + size: number + }[] + thumbnailfile?: string + previewfile?: string + } +) { + if (!attributes.likes) attributes.likes = 0 + if (!attributes.dislikes) attributes.dislikes = 0 + + const host = new URL(server.url).host + const originHost = attributes.account.host + + expect(video.name).to.equal(attributes.name) + expect(video.category.id).to.equal(attributes.category) + expect(video.category.label).to.equal(attributes.category !== null ? VIDEO_CATEGORIES[attributes.category] : 'Misc') + expect(video.licence.id).to.equal(attributes.licence) + expect(video.licence.label).to.equal(attributes.licence !== null ? VIDEO_LICENCES[attributes.licence] : 'Unknown') + expect(video.language.id).to.equal(attributes.language) + expect(video.language.label).to.equal(attributes.language !== null ? VIDEO_LANGUAGES[attributes.language] : 'Unknown') + expect(video.privacy.id).to.deep.equal(attributes.privacy) + expect(video.privacy.label).to.deep.equal(VIDEO_PRIVACIES[attributes.privacy]) + expect(video.nsfw).to.equal(attributes.nsfw) + expect(video.description).to.equal(attributes.description) + expect(video.account.id).to.be.a('number') + expect(video.account.host).to.equal(attributes.account.host) + expect(video.account.name).to.equal(attributes.account.name) + expect(video.channel.displayName).to.equal(attributes.channel.displayName) + expect(video.channel.name).to.equal(attributes.channel.name) + expect(video.likes).to.equal(attributes.likes) + expect(video.dislikes).to.equal(attributes.dislikes) + expect(video.isLocal).to.equal(attributes.isLocal) + expect(video.duration).to.equal(attributes.duration) + expect(video.url).to.contain(originHost) + expect(dateIsValid(video.createdAt)).to.be.true + expect(dateIsValid(video.publishedAt)).to.be.true + expect(dateIsValid(video.updatedAt)).to.be.true + + if (attributes.publishedAt) { + expect(video.publishedAt).to.equal(attributes.publishedAt) + } + + if (attributes.originallyPublishedAt) { + expect(video.originallyPublishedAt).to.equal(attributes.originallyPublishedAt) + } else { + expect(video.originallyPublishedAt).to.be.null + } + + const videoDetails = await server.videos.get({ id: video.uuid }) + + expect(videoDetails.files).to.have.lengthOf(attributes.files.length) + expect(videoDetails.tags).to.deep.equal(attributes.tags) + expect(videoDetails.account.name).to.equal(attributes.account.name) + expect(videoDetails.account.host).to.equal(attributes.account.host) + expect(video.channel.displayName).to.equal(attributes.channel.displayName) + expect(video.channel.name).to.equal(attributes.channel.name) + expect(videoDetails.channel.host).to.equal(attributes.account.host) + expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) + expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true + expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true + expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) + expect(videoDetails.downloadEnabled).to.equal(attributes.downloadEnabled) + + for (const attributeFile of attributes.files) { + const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution) + expect(file).not.to.be.undefined + + let extension = getLowercaseExtension(attributes.fixture) + // Transcoding enabled: extension will always be .mp4 + if (attributes.files.length > 1) extension = '.mp4' + + expect(file.magnetUri).to.have.lengthOf.above(2) + + expect(file.torrentDownloadUrl).to.match(new RegExp(`http://${host}/download/torrents/${uuidRegex}-${file.resolution.id}.torrent`)) + expect(file.torrentUrl).to.match(new RegExp(`http://${host}/lazy-static/torrents/${uuidRegex}-${file.resolution.id}.torrent`)) + + expect(file.fileUrl).to.match(new RegExp(`http://${originHost}/static/webseed/${uuidRegex}-${file.resolution.id}${extension}`)) + expect(file.fileDownloadUrl).to.match(new RegExp(`http://${originHost}/download/videos/${uuidRegex}-${file.resolution.id}${extension}`)) + + await Promise.all([ + makeRawRequest(file.torrentUrl, 200), + makeRawRequest(file.torrentDownloadUrl, 200), + makeRawRequest(file.metadataUrl, 200) + ]) + + expect(file.resolution.id).to.equal(attributeFile.resolution) + expect(file.resolution.label).to.equal(attributeFile.resolution + 'p') + + const minSize = attributeFile.size - ((10 * attributeFile.size) / 100) + const maxSize = attributeFile.size + ((10 * attributeFile.size) / 100) + expect( + file.size, + 'File size for resolution ' + file.resolution.label + ' outside confidence interval (' + minSize + '> size <' + maxSize + ')' + ).to.be.above(minSize).and.below(maxSize) + + const torrent = await webtorrentAdd(file.magnetUri, true) + expect(torrent.files).to.be.an('array') + expect(torrent.files.length).to.equal(1) + expect(torrent.files[0].path).to.exist.and.to.not.equal('') + } + + expect(videoDetails.thumbnailPath).to.exist + await testImage(server.url, attributes.thumbnailfile || attributes.fixture, videoDetails.thumbnailPath) + + if (attributes.previewfile) { + expect(videoDetails.previewPath).to.exist + await testImage(server.url, attributes.previewfile, videoDetails.previewPath) + } +} + +async function checkVideoFilesWereRemoved (options: { + server: PeerTubeServer + video: VideoDetails + captions?: VideoCaption[] + onlyVideoFiles?: boolean // default false +}) { + const { video, server, captions = [], onlyVideoFiles = false } = options + + const webtorrentFiles = video.files || [] + const hlsFiles = video.streamingPlaylists[0]?.files || [] + + const thumbnailName = basename(video.thumbnailPath) + const previewName = basename(video.previewPath) + + const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl)) + + const captionNames = captions.map(c => basename(c.captionPath)) + + const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl)) + const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl)) + + let directories: { [ directory: string ]: string[] } = { + videos: webtorrentFilenames, + redundancy: webtorrentFilenames, + [join('playlists', 'hls')]: hlsFilenames, + [join('redundancy', 'hls')]: hlsFilenames + } + + if (onlyVideoFiles !== true) { + directories = { + ...directories, + + thumbnails: [ thumbnailName ], + previews: [ previewName ], + torrents: torrentNames, + captions: captionNames + } + } + + for (const directory of Object.keys(directories)) { + const directoryPath = server.servers.buildDirectory(directory) + + const directoryExists = await pathExists(directoryPath) + if (directoryExists === false) continue + + const existingFiles = await readdir(directoryPath) + for (const existingFile of existingFiles) { + for (const shouldNotExist of directories[directory]) { + expect(existingFile, `File ${existingFile} should not exist in ${directoryPath}`).to.not.contain(shouldNotExist) + } + } + } +} + +async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) { + for (const server of servers) { + server.store.videoDetails = await server.videos.get({ id: uuid }) + } +} + +function checkUploadVideoParam ( + server: PeerTubeServer, + token: string, + attributes: Partial, + expectedStatus = HttpStatusCode.OK_200, + mode: 'legacy' | 'resumable' = 'legacy' +) { + return mode === 'legacy' + ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus }) + : server.videos.buildResumeUpload({ token, attributes, expectedStatus }) +} + +// serverNumber starts from 1 +async function uploadRandomVideoOnServers ( + servers: PeerTubeServer[], + serverNumber: number, + additionalParams?: VideoEdit & { prefixName?: string } +) { + const server = servers.find(s => s.serverNumber === serverNumber) + const res = await server.videos.randomUpload({ wait: false, additionalParams }) + + await waitJobs(servers) + + return res +} + +// --------------------------------------------------------------------------- + +export { + completeVideoCheck, + checkUploadVideoParam, + uploadRandomVideoOnServers, + checkVideoFilesWereRemoved, + saveVideoInServers +} diff --git a/shared/core-utils/common/array.ts b/shared/core-utils/common/array.ts new file mode 100644 index 000000000..9e326a5aa --- /dev/null +++ b/shared/core-utils/common/array.ts @@ -0,0 +1,13 @@ +function findCommonElement (array1: T[], array2: T[]) { + for (const a of array1) { + for (const b of array2) { + if (a === b) return a + } + } + + return null +} + +export { + findCommonElement +} diff --git a/shared/core-utils/common/crypto.ts b/shared/core-utils/common/crypto.ts new file mode 100644 index 000000000..1a583f1a0 --- /dev/null +++ b/shared/core-utils/common/crypto.ts @@ -0,0 +1,20 @@ +import { BinaryToTextEncoding, createHash } from 'crypto' + +function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { + return createHash('sha256').update(str).digest(encoding) +} + +function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { + return createHash('sha1').update(str).digest(encoding) +} + +// high excluded +function randomInt (low: number, high: number) { + return Math.floor(Math.random() * (high - low) + low) +} + +export { + randomInt, + sha256, + sha1 +} diff --git a/shared/core-utils/common/env.ts b/shared/core-utils/common/env.ts new file mode 100644 index 000000000..38c96b152 --- /dev/null +++ b/shared/core-utils/common/env.ts @@ -0,0 +1,30 @@ +function parallelTests () { + return process.env.MOCHA_PARALLEL === 'true' +} + +function isGithubCI () { + return !!process.env.GITHUB_WORKSPACE +} + +function areHttpImportTestsDisabled () { + const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true' + + if (disabled) console.log('DISABLE_HTTP_IMPORT_TESTS env set to "true" so import tests are disabled') + + return disabled +} + +function areObjectStorageTestsDisabled () { + const disabled = process.env.ENABLE_OBJECT_STORAGE_TESTS !== 'true' + + if (disabled) console.log('ENABLE_OBJECT_STORAGE_TESTS env is not set to "true" so object storage tests are disabled') + + return disabled +} + +export { + parallelTests, + isGithubCI, + areHttpImportTestsDisabled, + areObjectStorageTestsDisabled +} diff --git a/shared/core-utils/common/index.ts b/shared/core-utils/common/index.ts index 5d3512148..f9ba10d5e 100644 --- a/shared/core-utils/common/index.ts +++ b/shared/core-utils/common/index.ts @@ -1,5 +1,11 @@ +export * from './array' +export * from './crypto' export * from './date' -export * from './miscs' +export * from './env' +export * from './object' +export * from './path' export * from './regexp' +export * from './time' export * from './promises' export * from './url' +export * from './version' diff --git a/shared/core-utils/common/miscs.ts b/shared/core-utils/common/miscs.ts deleted file mode 100644 index bc65dc338..000000000 --- a/shared/core-utils/common/miscs.ts +++ /dev/null @@ -1,41 +0,0 @@ -// high excluded -function randomInt (low: number, high: number) { - return Math.floor(Math.random() * (high - low) + low) -} - -// Thanks https://stackoverflow.com/a/16187766 -function compareSemVer (a: string, b: string) { - const regExStrip0 = /(\.0+)+$/ - const segmentsA = a.replace(regExStrip0, '').split('.') - const segmentsB = b.replace(regExStrip0, '').split('.') - - const l = Math.min(segmentsA.length, segmentsB.length) - - for (let i = 0; i < l; i++) { - const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10) - - if (diff) return diff - } - - return segmentsA.length - segmentsB.length -} - -function sortObjectComparator (key: string, order: 'asc' | 'desc') { - return (a: any, b: any) => { - if (a[key] < b[key]) { - return order === 'asc' ? -1 : 1 - } - - if (a[key] > b[key]) { - return order === 'asc' ? 1 : -1 - } - - return 0 - } -} - -export { - randomInt, - compareSemVer, - sortObjectComparator -} diff --git a/shared/core-utils/common/object.ts b/shared/core-utils/common/object.ts new file mode 100644 index 000000000..88d6b7514 --- /dev/null +++ b/shared/core-utils/common/object.ts @@ -0,0 +1,30 @@ +function pick (object: O, keys: K[]): Pick { + const result: any = {} + + for (const key of keys) { + if (Object.prototype.hasOwnProperty.call(object, key)) { + result[key] = object[key] + } + } + + return result +} + +function sortObjectComparator (key: string, order: 'asc' | 'desc') { + return (a: any, b: any) => { + if (a[key] < b[key]) { + return order === 'asc' ? -1 : 1 + } + + if (a[key] > b[key]) { + return order === 'asc' ? 1 : -1 + } + + return 0 + } +} + +export { + pick, + sortObjectComparator +} diff --git a/shared/core-utils/common/path.ts b/shared/core-utils/common/path.ts new file mode 100644 index 000000000..ec507538b --- /dev/null +++ b/shared/core-utils/common/path.ts @@ -0,0 +1,46 @@ +import { basename, extname, isAbsolute, join, resolve } from 'path' + +let rootPath: string + +function root () { + if (rootPath) return rootPath + + rootPath = __dirname + + if (basename(rootPath) === 'common') rootPath = resolve(rootPath, '..') + if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..') + if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..') + if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..') + if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..') + + return rootPath +} + +function buildPath (path: string) { + if (isAbsolute(path)) return path + + return join(root(), path) +} + +function getLowercaseExtension (filename: string) { + const ext = extname(filename) || '' + + return ext.toLowerCase() +} + +function buildAbsoluteFixturePath (path: string, customCIPath = false) { + if (isAbsolute(path)) return path + + if (customCIPath && process.env.GITHUB_WORKSPACE) { + return join(process.env.GITHUB_WORKSPACE, 'fixtures', path) + } + + return join(root(), 'server', 'tests', 'fixtures', path) +} + +export { + root, + buildPath, + buildAbsoluteFixturePath, + getLowercaseExtension +} diff --git a/shared/core-utils/common/time.ts b/shared/core-utils/common/time.ts new file mode 100644 index 000000000..2992609ca --- /dev/null +++ b/shared/core-utils/common/time.ts @@ -0,0 +1,7 @@ +function wait (milliseconds: number) { + return new Promise(resolve => setTimeout(resolve, milliseconds)) +} + +export { + wait +} diff --git a/shared/core-utils/common/version.ts b/shared/core-utils/common/version.ts new file mode 100644 index 000000000..8a64f8c4d --- /dev/null +++ b/shared/core-utils/common/version.ts @@ -0,0 +1,20 @@ +// Thanks https://stackoverflow.com/a/16187766 +function compareSemVer (a: string, b: string) { + const regExStrip0 = /(\.0+)+$/ + const segmentsA = a.replace(regExStrip0, '').split('.') + const segmentsB = b.replace(regExStrip0, '').split('.') + + const l = Math.min(segmentsA.length, segmentsB.length) + + for (let i = 0; i < l; i++) { + const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10) + + if (diff) return diff + } + + return segmentsA.length - segmentsB.length +} + +export { + compareSemVer +} diff --git a/shared/core-utils/crypto.ts b/shared/core-utils/crypto.ts deleted file mode 100644 index d6d1150d0..000000000 --- a/shared/core-utils/crypto.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { BinaryToTextEncoding, createHash } from 'crypto' - -function sha256 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { - return createHash('sha256').update(str).digest(encoding) -} - -function sha1 (str: string | Buffer, encoding: BinaryToTextEncoding = 'hex') { - return createHash('sha1').update(str).digest(encoding) -} - -export { - sha256, - sha1 -} diff --git a/shared/core-utils/index.ts b/shared/core-utils/index.ts index ee5cd4412..8daaa2d04 100644 --- a/shared/core-utils/index.ts +++ b/shared/core-utils/index.ts @@ -1,10 +1,7 @@ export * from './abuse' export * from './common' export * from './i18n' -export * from './path' export * from './plugins' export * from './renderer' export * from './users' -export * from './utils' export * from './videos' -export * from './uuid' diff --git a/shared/core-utils/path.ts b/shared/core-utils/path.ts deleted file mode 100644 index b1a45d69b..000000000 --- a/shared/core-utils/path.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { basename, extname, isAbsolute, join, resolve } from 'path' - -let rootPath: string - -function root () { - if (rootPath) return rootPath - - rootPath = __dirname - - if (basename(rootPath) === 'core-utils') rootPath = resolve(rootPath, '..') - if (basename(rootPath) === 'shared') rootPath = resolve(rootPath, '..') - if (basename(rootPath) === 'server') rootPath = resolve(rootPath, '..') - if (basename(rootPath) === 'dist') rootPath = resolve(rootPath, '..') - - return rootPath -} - -function buildPath (path: string) { - if (isAbsolute(path)) return path - - return join(root(), path) -} - -function getLowercaseExtension (filename: string) { - const ext = extname(filename) || '' - - return ext.toLowerCase() -} - -export { - root, - buildPath, - getLowercaseExtension -} diff --git a/shared/core-utils/utils/array.ts b/shared/core-utils/utils/array.ts deleted file mode 100644 index 9e326a5aa..000000000 --- a/shared/core-utils/utils/array.ts +++ /dev/null @@ -1,13 +0,0 @@ -function findCommonElement (array1: T[], array2: T[]) { - for (const a of array1) { - for (const b of array2) { - if (a === b) return a - } - } - - return null -} - -export { - findCommonElement -} diff --git a/shared/core-utils/utils/index.ts b/shared/core-utils/utils/index.ts deleted file mode 100644 index 8d16365a8..000000000 --- a/shared/core-utils/utils/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './array' -export * from './object' diff --git a/shared/core-utils/utils/object.ts b/shared/core-utils/utils/object.ts deleted file mode 100644 index 9a8a98f9b..000000000 --- a/shared/core-utils/utils/object.ts +++ /dev/null @@ -1,15 +0,0 @@ -function pick (object: O, keys: K[]): Pick { - const result: any = {} - - for (const key of keys) { - if (Object.prototype.hasOwnProperty.call(object, key)) { - result[key] = object[key] - } - } - - return result -} - -export { - pick -} diff --git a/shared/core-utils/uuid.ts b/shared/core-utils/uuid.ts deleted file mode 100644 index f3c80e046..000000000 --- a/shared/core-utils/uuid.ts +++ /dev/null @@ -1,32 +0,0 @@ -import short, { uuid } from 'short-uuid' - -const translator = short() - -function buildUUID () { - return uuid() -} - -function uuidToShort (uuid: string) { - if (!uuid) return uuid - - return translator.fromUUID(uuid) -} - -function shortToUUID (shortUUID: string) { - if (!shortUUID) return shortUUID - - return translator.toUUID(shortUUID) -} - -function isShortUUID (value: string) { - if (!value) return false - - return value.length === translator.maxLength -} - -export { - buildUUID, - uuidToShort, - shortToUUID, - isShortUUID -} diff --git a/shared/core-utils/videos/index.ts b/shared/core-utils/videos/index.ts index 620e3a716..8f6736d39 100644 --- a/shared/core-utils/videos/index.ts +++ b/shared/core-utils/videos/index.ts @@ -1,2 +1,3 @@ export * from './bitrate' export * from './privacy' +export * from './uuid' diff --git a/shared/core-utils/videos/uuid.ts b/shared/core-utils/videos/uuid.ts new file mode 100644 index 000000000..f3c80e046 --- /dev/null +++ b/shared/core-utils/videos/uuid.ts @@ -0,0 +1,32 @@ +import short, { uuid } from 'short-uuid' + +const translator = short() + +function buildUUID () { + return uuid() +} + +function uuidToShort (uuid: string) { + if (!uuid) return uuid + + return translator.fromUUID(uuid) +} + +function shortToUUID (shortUUID: string) { + if (!shortUUID) return shortUUID + + return translator.toUUID(shortUUID) +} + +function isShortUUID (value: string) { + if (!value) return false + + return value.length === translator.maxLength +} + +export { + buildUUID, + uuidToShort, + shortToUUID, + isShortUUID +} diff --git a/shared/extra-utils/file.ts b/shared/extra-utils/file.ts new file mode 100644 index 000000000..8060ab520 --- /dev/null +++ b/shared/extra-utils/file.ts @@ -0,0 +1,11 @@ +import { stat } from 'fs-extra' + +async function getFileSize (path: string) { + const stats = await stat(path) + + return stats.size +} + +export { + getFileSize +} diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 5710c5ab5..38303cf1f 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts @@ -1 +1,2 @@ export * from './ffprobe' +export * from './file' diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts index b61a8cd40..a24ffee96 100644 --- a/shared/models/users/index.ts +++ b/shared/models/users/index.ts @@ -8,6 +8,7 @@ export * from './user-refresh-token.model' export * from './user-register.model' export * from './user-right.enum' export * from './user-role' +export * from './user-scoped-token' export * from './user-update-me.model' export * from './user-update.model' export * from './user-video-quota.model' diff --git a/shared/server-commands/index.ts b/shared/server-commands/index.ts index 4b3636d06..c24ebb2df 100644 --- a/shared/server-commands/index.ts +++ b/shared/server-commands/index.ts @@ -4,7 +4,6 @@ export * from './custom-pages' export * from './feeds' export * from './logs' export * from './miscs' -export * from './mock-servers' export * from './moderation' export * from './overviews' export * from './requests' diff --git a/shared/server-commands/logs/logs-command.ts b/shared/server-commands/logs/logs-command.ts index 7b5c66c0c..8f63383ea 100644 --- a/shared/server-commands/logs/logs-command.ts +++ b/shared/server-commands/logs/logs-command.ts @@ -1,5 +1,4 @@ -import { HttpStatusCode } from '@shared/models' -import { LogLevel } from '../../models/server/log-level.type' +import { HttpStatusCode, LogLevel } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class LogsCommand extends AbstractCommand { diff --git a/shared/server-commands/miscs/checks.ts b/shared/server-commands/miscs/checks.ts deleted file mode 100644 index 589928997..000000000 --- a/shared/server-commands/miscs/checks.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ - -import { expect } from 'chai' -import { pathExists, readFile } from 'fs-extra' -import { join } from 'path' -import { root } from '@shared/core-utils' -import { HttpStatusCode } from '@shared/models' -import { makeGetRequest } from '../requests' -import { PeerTubeServer } from '../server' - -// Default interval -> 5 minutes -function dateIsValid (dateString: string, interval = 300000) { - const dateToCheck = new Date(dateString) - const now = new Date() - - return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval -} - -function expectStartWith (str: string, start: string) { - expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true -} - -async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { - const content = await server.servers.getLogContent() - - expect(content.toString()).to.not.contain(str) -} - -async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { - const res = await makeGetRequest({ - url, - path: imagePath, - expectedStatus: HttpStatusCode.OK_200 - }) - - const body = res.body - - const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) - const minLength = body.length - ((30 * body.length) / 100) - const maxLength = body.length + ((30 * body.length) / 100) - - expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') - expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') -} - -async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { - const base = server.servers.buildDirectory(directory) - - expect(await pathExists(join(base, filePath))).to.equal(exist) -} - -export { - dateIsValid, - testImage, - expectLogDoesNotContain, - testFileExistsOrNot, - expectStartWith -} diff --git a/shared/server-commands/miscs/generate.ts b/shared/server-commands/miscs/generate.ts deleted file mode 100644 index 93673a063..000000000 --- a/shared/server-commands/miscs/generate.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { expect } from 'chai' -import ffmpeg from 'fluent-ffmpeg' -import { ensureDir, pathExists } from 'fs-extra' -import { dirname } from 'path' -import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '@shared/extra-utils/ffprobe' -import { getMaxBitrate } from '@shared/core-utils' -import { buildAbsoluteFixturePath } from './tests' - -async function ensureHasTooBigBitrate (fixturePath: string) { - const bitrate = await getVideoFileBitrate(fixturePath) - const dataResolution = await getVideoFileResolution(fixturePath) - const fps = await getVideoFileFPS(fixturePath) - - const maxBitrate = getMaxBitrate({ ...dataResolution, fps }) - expect(bitrate).to.be.above(maxBitrate) -} - -async function generateHighBitrateVideo () { - const tempFixturePath = buildAbsoluteFixturePath('video_high_bitrate_1080p.mp4', true) - - await ensureDir(dirname(tempFixturePath)) - - const exists = await pathExists(tempFixturePath) - if (!exists) { - console.log('Generating high bitrate video.') - - // Generate a random, high bitrate video on the fly, so we don't have to include - // a large file in the repo. The video needs to have a certain minimum length so - // that FFmpeg properly applies bitrate limits. - // https://stackoverflow.com/a/15795112 - return new Promise((res, rej) => { - ffmpeg() - .outputOptions([ '-f rawvideo', '-video_size 1920x1080', '-i /dev/urandom' ]) - .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) - .outputOptions([ '-maxrate 10M', '-bufsize 10M' ]) - .output(tempFixturePath) - .on('error', rej) - .on('end', () => res(tempFixturePath)) - .run() - }) - } - - await ensureHasTooBigBitrate(tempFixturePath) - - return tempFixturePath -} - -async function generateVideoWithFramerate (fps = 60) { - const tempFixturePath = buildAbsoluteFixturePath(`video_${fps}fps.mp4`, true) - - await ensureDir(dirname(tempFixturePath)) - - const exists = await pathExists(tempFixturePath) - if (!exists) { - console.log('Generating video with framerate %d.', fps) - - return new Promise((res, rej) => { - ffmpeg() - .outputOptions([ '-f rawvideo', '-video_size 1280x720', '-i /dev/urandom' ]) - .outputOptions([ '-ac 2', '-f s16le', '-i /dev/urandom', '-t 10' ]) - .outputOptions([ `-r ${fps}` ]) - .output(tempFixturePath) - .on('error', rej) - .on('end', () => res(tempFixturePath)) - .run() - }) - } - - return tempFixturePath -} - -export { - generateHighBitrateVideo, - generateVideoWithFramerate -} diff --git a/shared/server-commands/miscs/index.ts b/shared/server-commands/miscs/index.ts index 4474661de..a1d14e998 100644 --- a/shared/server-commands/miscs/index.ts +++ b/shared/server-commands/miscs/index.ts @@ -1,5 +1,2 @@ -export * from './checks' -export * from './generate' export * from './sql-command' -export * from './tests' export * from './webtorrent' diff --git a/shared/server-commands/miscs/sql-command.ts b/shared/server-commands/miscs/sql-command.ts index bedb3349b..09a99f834 100644 --- a/shared/server-commands/miscs/sql-command.ts +++ b/shared/server-commands/miscs/sql-command.ts @@ -1,5 +1,5 @@ import { QueryTypes, Sequelize } from 'sequelize' -import { AbstractCommand } from '../shared/abstract-command' +import { AbstractCommand } from '../shared' export class SQLCommand extends AbstractCommand { private sequelize: Sequelize diff --git a/shared/server-commands/miscs/tests.ts b/shared/server-commands/miscs/tests.ts deleted file mode 100644 index 658fe5fd3..000000000 --- a/shared/server-commands/miscs/tests.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { stat } from 'fs-extra' -import { basename, isAbsolute, join, resolve } from 'path' - -const FIXTURE_URLS = { - peertube_long: 'https://peertube2.cpy.re/videos/watch/122d093a-1ede-43bd-bd34-59d2931ffc5e', - peertube_short: 'https://peertube2.cpy.re/w/3fbif9S3WmtTP8gGsC5HBd', - - youtube: 'https://www.youtube.com/watch?v=msX3jv1XdvM', - - /** - * The video is used to check format-selection correctness wrt. HDR, - * which brings its own set of oddities outside of a MediaSource. - * - * The video needs to have the following format_ids: - * (which you can check by using `youtube-dl -F`): - * - (webm vp9) - * - (mp4 avc1) - * - (webm vp9.2 HDR) - */ - youtubeHDR: 'https://www.youtube.com/watch?v=RQgnBB9z_N4', - - // eslint-disable-next-line max-len - magnet: 'magnet:?xs=https%3A%2F%2Fpeertube2.cpy.re%2Flazy-static%2Ftorrents%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.torrent&xt=urn:btih:0f498834733e8057ed5c6f2ee2b4efd8d84a76ee&dn=super+peertube2+video&tr=https%3A%2F%2Fpeertube2.cpy.re%2Ftracker%2Fannounce&tr=wss%3A%2F%2Fpeertube2.cpy.re%3A443%2Ftracker%2Fsocket&ws=https%3A%2F%2Fpeertube2.cpy.re%2Fstatic%2Fwebseed%2Fb209ca00-c8bb-4b2b-b421-1ede169f3dbc-720.mp4', - - badVideo: 'https://download.cpy.re/peertube/bad_video.mp4', - goodVideo: 'https://download.cpy.re/peertube/good_video.mp4', - goodVideo720: 'https://download.cpy.re/peertube/good_video_720.mp4', - - file4K: 'https://download.cpy.re/peertube/4k_file.txt' -} - -function parallelTests () { - return process.env.MOCHA_PARALLEL === 'true' -} - -function isGithubCI () { - return !!process.env.GITHUB_WORKSPACE -} - -function areHttpImportTestsDisabled () { - const disabled = process.env.DISABLE_HTTP_IMPORT_TESTS === 'true' - - if (disabled) console.log('DISABLE_HTTP_IMPORT_TESTS env set to "true" so import tests are disabled') - - return disabled -} - -function areObjectStorageTestsDisabled () { - const disabled = process.env.ENABLE_OBJECT_STORAGE_TESTS !== 'true' - - if (disabled) console.log('ENABLE_OBJECT_STORAGE_TESTS env is not set to "true" so object storage tests are disabled') - - return disabled -} - -function buildAbsoluteFixturePath (path: string, customCIPath = false) { - if (isAbsolute(path)) return path - - if (customCIPath && process.env.GITHUB_WORKSPACE) { - return join(process.env.GITHUB_WORKSPACE, 'fixtures', path) - } - - return join(root(), 'server', 'tests', 'fixtures', path) -} - -function root () { - // We are in /miscs - let root = join(__dirname, '..', '..', '..') - - if (basename(root) === 'dist') root = resolve(root, '..') - - return root -} - -function wait (milliseconds: number) { - return new Promise(resolve => setTimeout(resolve, milliseconds)) -} - -async function getFileSize (path: string) { - const stats = await stat(path) - - return stats.size -} - -function buildRequestStub (): any { - return { } -} - -export { - FIXTURE_URLS, - - parallelTests, - isGithubCI, - areHttpImportTestsDisabled, - buildAbsoluteFixturePath, - getFileSize, - buildRequestStub, - areObjectStorageTestsDisabled, - wait, - root -} diff --git a/shared/server-commands/mock-servers/index.ts b/shared/server-commands/mock-servers/index.ts deleted file mode 100644 index 93c00c788..000000000 --- a/shared/server-commands/mock-servers/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './mock-email' -export * from './mock-instances-index' -export * from './mock-joinpeertube-versions' -export * from './mock-plugin-blocklist' -export * from './mock-object-storage' diff --git a/shared/server-commands/mock-servers/mock-429.ts b/shared/server-commands/mock-servers/mock-429.ts deleted file mode 100644 index 9e0d1281a..000000000 --- a/shared/server-commands/mock-servers/mock-429.ts +++ /dev/null @@ -1,33 +0,0 @@ -import express from 'express' -import { Server } from 'http' -import { getPort, randomListen, terminateServer } from './utils' - -export class Mock429 { - private server: Server - private responseSent = false - - async initialize () { - const app = express() - - app.get('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { - - if (!this.responseSent) { - this.responseSent = true - - // Retry after 5 seconds - res.header('retry-after', '2') - return res.sendStatus(429) - } - - return res.sendStatus(200) - }) - - this.server = await randomListen(app) - - return getPort(this.server) - } - - terminate () { - return terminateServer(this.server) - } -} diff --git a/shared/server-commands/mock-servers/mock-email.ts b/shared/server-commands/mock-servers/mock-email.ts deleted file mode 100644 index f646c1621..000000000 --- a/shared/server-commands/mock-servers/mock-email.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { ChildProcess } from 'child_process' -import MailDev from '@peertube/maildev' -import { randomInt } from '@shared/core-utils' -import { parallelTests } from '../miscs' - -class MockSmtpServer { - - private static instance: MockSmtpServer - private started = false - private emailChildProcess: ChildProcess - private emails: object[] - - private constructor () { } - - collectEmails (emailsCollection: object[]) { - return new Promise((res, rej) => { - const port = parallelTests() ? randomInt(1000, 2000) : 1025 - this.emails = emailsCollection - - if (this.started) { - return res(undefined) - } - - const maildev = new MailDev({ - ip: '127.0.0.1', - smtp: port, - disableWeb: true, - silent: true - }) - - maildev.on('new', email => { - this.emails.push(email) - }) - - maildev.listen(err => { - if (err) return rej(err) - - this.started = true - - return res(port) - }) - }) - } - - kill () { - if (!this.emailChildProcess) return - - process.kill(this.emailChildProcess.pid) - - this.emailChildProcess = null - MockSmtpServer.instance = null - } - - static get Instance () { - return this.instance || (this.instance = new this()) - } -} - -// --------------------------------------------------------------------------- - -export { - MockSmtpServer -} diff --git a/shared/server-commands/mock-servers/mock-instances-index.ts b/shared/server-commands/mock-servers/mock-instances-index.ts deleted file mode 100644 index 92b12d6f3..000000000 --- a/shared/server-commands/mock-servers/mock-instances-index.ts +++ /dev/null @@ -1,46 +0,0 @@ -import express from 'express' -import { Server } from 'http' -import { getPort, randomListen, terminateServer } from './utils' - -export class MockInstancesIndex { - private server: Server - - private readonly indexInstances: { host: string, createdAt: string }[] = [] - - async initialize () { - const app = express() - - app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { - if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) - - return next() - }) - - app.get('/api/v1/instances/hosts', (req: express.Request, res: express.Response) => { - const since = req.query.since - - const filtered = this.indexInstances.filter(i => { - if (!since) return true - - return i.createdAt > since - }) - - return res.json({ - total: filtered.length, - data: filtered - }) - }) - - this.server = await randomListen(app) - - return getPort(this.server) - } - - addInstance (host: string) { - this.indexInstances.push({ host, createdAt: new Date().toISOString() }) - } - - terminate () { - return terminateServer(this.server) - } -} diff --git a/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts b/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts deleted file mode 100644 index e7906ea56..000000000 --- a/shared/server-commands/mock-servers/mock-joinpeertube-versions.ts +++ /dev/null @@ -1,34 +0,0 @@ -import express from 'express' -import { Server } from 'http' -import { getPort, randomListen } from './utils' - -export class MockJoinPeerTubeVersions { - private server: Server - private latestVersion: string - - async initialize () { - const app = express() - - app.use('/', (req: express.Request, res: express.Response, next: express.NextFunction) => { - if (process.env.DEBUG) console.log('Receiving request on mocked server %s.', req.url) - - return next() - }) - - app.get('/versions.json', (req: express.Request, res: express.Response) => { - return res.json({ - peertube: { - latestVersion: this.latestVersion - } - }) - }) - - this.server = await randomListen(app) - - return getPort(this.server) - } - - setLatestVersion (latestVersion: string) { - this.latestVersion = latestVersion - } -} diff --git a/shared/server-commands/mock-servers/mock-object-storage.ts b/shared/server-commands/mock-servers/mock-object-storage.ts deleted file mode 100644 index d135c2631..000000000 --- a/shared/server-commands/mock-servers/mock-object-storage.ts +++ /dev/null @@ -1,41 +0,0 @@ -import express from 'express' -import got, { RequestError } from 'got' -import { Server } from 'http' -import { pipeline } from 'stream' -import { ObjectStorageCommand } from '../server' -import { getPort, randomListen, terminateServer } from './utils' - -export class MockObjectStorage { - private server: Server - - async initialize () { - const app = express() - - app.get('/:bucketName/:path(*)', (req: express.Request, res: express.Response, next: express.NextFunction) => { - const url = `http://${req.params.bucketName}.${ObjectStorageCommand.getEndpointHost()}/${req.params.path}` - - if (process.env.DEBUG) { - console.log('Receiving request on mocked server %s.', req.url) - console.log('Proxifying request to %s', url) - } - - return pipeline( - got.stream(url, { throwHttpErrors: false }), - res, - (err: RequestError) => { - if (!err) return - - console.error('Pipeline failed.', err) - } - ) - }) - - this.server = await randomListen(app) - - return getPort(this.server) - } - - terminate () { - return terminateServer(this.server) - } -} diff --git a/shared/server-commands/mock-servers/mock-plugin-blocklist.ts b/shared/server-commands/mock-servers/mock-plugin-blocklist.ts deleted file mode 100644 index f8a271cba..000000000 --- a/shared/server-commands/mock-servers/mock-plugin-blocklist.ts +++ /dev/null @@ -1,36 +0,0 @@ -import express, { Request, Response } from 'express' -import { Server } from 'http' -import { getPort, randomListen, terminateServer } from './utils' - -type BlocklistResponse = { - data: { - value: string - action?: 'add' | 'remove' - updatedAt?: string - }[] -} - -export class MockBlocklist { - private body: BlocklistResponse - private server: Server - - async initialize () { - const app = express() - - app.get('/blocklist', (req: Request, res: Response) => { - return res.json(this.body) - }) - - this.server = await randomListen(app) - - return getPort(this.server) - } - - replace (body: BlocklistResponse) { - this.body = body - } - - terminate () { - return terminateServer(this.server) - } -} diff --git a/shared/server-commands/mock-servers/mock-proxy.ts b/shared/server-commands/mock-servers/mock-proxy.ts deleted file mode 100644 index 75ac79055..000000000 --- a/shared/server-commands/mock-servers/mock-proxy.ts +++ /dev/null @@ -1,25 +0,0 @@ - -import { createServer, Server } from 'http' -import proxy from 'proxy' -import { getPort, terminateServer } from './utils' - -class MockProxy { - private server: Server - - initialize () { - return new Promise(res => { - this.server = proxy(createServer()) - this.server.listen(0, () => res(getPort(this.server))) - }) - } - - terminate () { - return terminateServer(this.server) - } -} - -// --------------------------------------------------------------------------- - -export { - MockProxy -} diff --git a/shared/server-commands/mock-servers/utils.ts b/shared/server-commands/mock-servers/utils.ts deleted file mode 100644 index 235642439..000000000 --- a/shared/server-commands/mock-servers/utils.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Express } from 'express' -import { Server } from 'http' -import { AddressInfo } from 'net' - -function randomListen (app: Express) { - return new Promise(res => { - const server = app.listen(0, () => res(server)) - }) -} - -function getPort (server: Server) { - const address = server.address() as AddressInfo - - return address.port -} - -function terminateServer (server: Server) { - if (!server) return Promise.resolve() - - return new Promise((res, rej) => { - server.close(err => { - if (err) return rej(err) - - return res() - }) - }) -} - -export { - randomListen, - getPort, - terminateServer -} diff --git a/shared/server-commands/requests/check-api-params.ts b/shared/server-commands/requests/check-api-params.ts deleted file mode 100644 index 26ba1e913..000000000 --- a/shared/server-commands/requests/check-api-params.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { HttpStatusCode } from '@shared/models' -import { makeGetRequest } from './requests' - -function checkBadStartPagination (url: string, path: string, token?: string, query = {}) { - return makeGetRequest({ - url, - path, - token, - query: { ...query, start: 'hello' }, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }) -} - -async function checkBadCountPagination (url: string, path: string, token?: string, query = {}) { - await makeGetRequest({ - url, - path, - token, - query: { ...query, count: 'hello' }, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }) - - await makeGetRequest({ - url, - path, - token, - query: { ...query, count: 2000 }, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }) -} - -function checkBadSortPagination (url: string, path: string, token?: string, query = {}) { - return makeGetRequest({ - url, - path, - token, - query: { ...query, sort: 'hello' }, - expectedStatus: HttpStatusCode.BAD_REQUEST_400 - }) -} - -// --------------------------------------------------------------------------- - -export { - checkBadStartPagination, - checkBadCountPagination, - checkBadSortPagination -} diff --git a/shared/server-commands/requests/index.ts b/shared/server-commands/requests/index.ts index 501163f92..802982301 100644 --- a/shared/server-commands/requests/index.ts +++ b/shared/server-commands/requests/index.ts @@ -1,3 +1 @@ -// Don't include activitypub that import stuff from server -export * from './check-api-params' export * from './requests' diff --git a/shared/server-commands/requests/requests.ts b/shared/server-commands/requests/requests.ts index b6b9024ed..95e4fe6b1 100644 --- a/shared/server-commands/requests/requests.ts +++ b/shared/server-commands/requests/requests.ts @@ -3,8 +3,8 @@ import { decode } from 'querystring' import request from 'supertest' import { URL } from 'url' +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { HttpStatusCode } from '@shared/models' -import { buildAbsoluteFixturePath } from '../miscs/tests' export type CommonRequestParams = { url: string diff --git a/shared/server-commands/server/config-command.ts b/shared/server-commands/server/config-command.ts index 89ae8eb4f..797231b1d 100644 --- a/shared/server-commands/server/config-command.ts +++ b/shared/server-commands/server/config-command.ts @@ -1,8 +1,7 @@ import { merge } from 'lodash' +import { About, CustomConfig, HttpStatusCode, ServerConfig } from '@shared/models' import { DeepPartial } from '@shared/typescript-utils' -import { About, HttpStatusCode, ServerConfig } from '@shared/models' -import { CustomConfig } from '../../models/server/custom-config.model' -import { AbstractCommand, OverrideCommandOptions } from '../shared' +import { AbstractCommand, OverrideCommandOptions } from '../shared/abstract-command' export class ConfigCommand extends AbstractCommand { diff --git a/shared/server-commands/server/directories.ts b/shared/server-commands/server/directories.ts deleted file mode 100644 index e6f72d6fc..000000000 --- a/shared/server-commands/server/directories.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { pathExists, readdir } from 'fs-extra' -import { join } from 'path' -import { root } from '@shared/core-utils' -import { PeerTubeServer } from './server' - -async function checkTmpIsEmpty (server: PeerTubeServer) { - await checkDirectoryIsEmpty(server, 'tmp', [ 'plugins-global.css', 'hls', 'resumable-uploads' ]) - - if (await pathExists(join('test' + server.internalServerNumber, 'tmp', 'hls'))) { - await checkDirectoryIsEmpty(server, 'tmp/hls') - } -} - -async function checkDirectoryIsEmpty (server: PeerTubeServer, directory: string, exceptions: string[] = []) { - const testDirectory = 'test' + server.internalServerNumber - - const directoryPath = join(root(), testDirectory, directory) - - const directoryExists = await pathExists(directoryPath) - expect(directoryExists).to.be.true - - const files = await readdir(directoryPath) - const filtered = files.filter(f => exceptions.includes(f) === false) - - expect(filtered).to.have.lengthOf(0) -} - -export { - checkTmpIsEmpty, - checkDirectoryIsEmpty -} diff --git a/shared/server-commands/server/index.ts b/shared/server-commands/server/index.ts index 76a2099da..0a4b21fc4 100644 --- a/shared/server-commands/server/index.ts +++ b/shared/server-commands/server/index.ts @@ -1,17 +1,14 @@ export * from './config-command' export * from './contact-form-command' export * from './debug-command' -export * from './directories' export * from './follows-command' export * from './follows' export * from './jobs' export * from './jobs-command' export * from './object-storage-command' export * from './plugins-command' -export * from './plugins' export * from './redundancy-command' export * from './server' export * from './servers-command' export * from './servers' export * from './stats-command' -export * from './tracker' diff --git a/shared/server-commands/server/jobs-command.ts b/shared/server-commands/server/jobs-command.ts index 6636e7e4d..ac62157d1 100644 --- a/shared/server-commands/server/jobs-command.ts +++ b/shared/server-commands/server/jobs-command.ts @@ -1,6 +1,5 @@ import { pick } from '@shared/core-utils' -import { HttpStatusCode } from '@shared/models' -import { Job, JobState, JobType, ResultList } from '../../models' +import { HttpStatusCode, Job, JobState, JobType, ResultList } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class JobsCommand extends AbstractCommand { diff --git a/shared/server-commands/server/jobs.ts b/shared/server-commands/server/jobs.ts index 34fefd444..fc65a873b 100644 --- a/shared/server-commands/server/jobs.ts +++ b/shared/server-commands/server/jobs.ts @@ -1,7 +1,7 @@ import { expect } from 'chai' +import { wait } from '@shared/core-utils' import { JobState, JobType } from '../../models' -import { wait } from '../miscs' import { PeerTubeServer } from './server' async function waitJobs (serversArg: PeerTubeServer[] | PeerTubeServer, skipDelayed = false) { diff --git a/shared/server-commands/server/plugins.ts b/shared/server-commands/server/plugins.ts deleted file mode 100644 index c6316898d..000000000 --- a/shared/server-commands/server/plugins.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { PeerTubeServer } from './server' - -async function testHelloWorldRegisteredSettings (server: PeerTubeServer) { - const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' }) - - const registeredSettings = body.registeredSettings - expect(registeredSettings).to.have.length.at.least(1) - - const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') - expect(adminNameSettings).to.not.be.undefined -} - -export { - testHelloWorldRegisteredSettings -} diff --git a/shared/server-commands/server/server.ts b/shared/server-commands/server/server.ts index 339b9cabb..617069b11 100644 --- a/shared/server-commands/server/server.ts +++ b/shared/server-commands/server/server.ts @@ -1,14 +1,14 @@ import { ChildProcess, fork } from 'child_process' import { copy } from 'fs-extra' import { join } from 'path' -import { root, randomInt } from '@shared/core-utils' -import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '../../models/videos' +import { parallelTests, randomInt, root } from '@shared/core-utils' +import { Video, VideoChannel, VideoCreateResult, VideoDetails } from '@shared/models' import { BulkCommand } from '../bulk' import { CLICommand } from '../cli' import { CustomPagesCommand } from '../custom-pages' import { FeedCommand } from '../feeds' import { LogsCommand } from '../logs' -import { parallelTests, SQLCommand } from '../miscs' +import { SQLCommand } from '../miscs' import { AbusesCommand } from '../moderation' import { OverviewsCommand } from '../overviews' import { SearchCommand } from '../search' @@ -33,11 +33,11 @@ import { ContactFormCommand } from './contact-form-command' import { DebugCommand } from './debug-command' import { FollowsCommand } from './follows-command' import { JobsCommand } from './jobs-command' +import { ObjectStorageCommand } from './object-storage-command' import { PluginsCommand } from './plugins-command' import { RedundancyCommand } from './redundancy-command' import { ServersCommand } from './servers-command' import { StatsCommand } from './stats-command' -import { ObjectStorageCommand } from './object-storage-command' export type RunServerOptions = { hideLogs?: boolean diff --git a/shared/server-commands/server/servers-command.ts b/shared/server-commands/server/servers-command.ts index 47420c95f..c5d8d18dc 100644 --- a/shared/server-commands/server/servers-command.ts +++ b/shared/server-commands/server/servers-command.ts @@ -1,9 +1,9 @@ import { exec } from 'child_process' import { copy, ensureDir, readFile, remove } from 'fs-extra' import { basename, join } from 'path' -import { root } from '@shared/core-utils' +import { isGithubCI, root, wait } from '@shared/core-utils' +import { getFileSize } from '@shared/extra-utils' import { HttpStatusCode } from '@shared/models' -import { getFileSize, isGithubCI, wait } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class ServersCommand extends AbstractCommand { diff --git a/shared/server-commands/server/servers.ts b/shared/server-commands/server/servers.ts index 21ab9405b..0faee3a8d 100644 --- a/shared/server-commands/server/servers.ts +++ b/shared/server-commands/server/servers.ts @@ -1,5 +1,5 @@ import { ensureDir } from 'fs-extra' -import { isGithubCI } from '../miscs' +import { isGithubCI } from '@shared/core-utils' import { PeerTubeServer, RunServerOptions } from './server' async function createSingleServer (serverNumber: number, configOverride?: Object, options: RunServerOptions = {}) { diff --git a/shared/server-commands/server/tracker.ts b/shared/server-commands/server/tracker.ts deleted file mode 100644 index ed43a5924..000000000 --- a/shared/server-commands/server/tracker.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { expect } from 'chai' -import { sha1 } from '@shared/core-utils/crypto' -import { makeGetRequest } from '../requests' - -async function hlsInfohashExist (serverUrl: string, masterPlaylistUrl: string, fileNumber: number) { - const path = '/tracker/announce' - - const infohash = sha1(`2${masterPlaylistUrl}+V${fileNumber}`) - - // From bittorrent-tracker - const infohashBinary = escape(Buffer.from(infohash, 'hex').toString('binary')).replace(/[@*/+]/g, function (char) { - return '%' + char.charCodeAt(0).toString(16).toUpperCase() - }) - - const res = await makeGetRequest({ - url: serverUrl, - path, - rawQuery: `peer_id=-WW0105-NkvYO/egUAr4&info_hash=${infohashBinary}&port=42100`, - expectedStatus: 200 - }) - - expect(res.text).to.not.contain('failure') -} - -export { - hlsInfohashExist -} diff --git a/shared/server-commands/shared/abstract-command.ts b/shared/server-commands/shared/abstract-command.ts index a57c857fc..1b53a5330 100644 --- a/shared/server-commands/shared/abstract-command.ts +++ b/shared/server-commands/shared/abstract-command.ts @@ -1,5 +1,5 @@ import { isAbsolute, join } from 'path' -import { root } from '../miscs/tests' +import { root } from '@shared/core-utils' import { makeDeleteRequest, makeGetRequest, diff --git a/shared/server-commands/users/accounts-command.ts b/shared/server-commands/users/accounts-command.ts index 98d9d5927..5844b330b 100644 --- a/shared/server-commands/users/accounts-command.ts +++ b/shared/server-commands/users/accounts-command.ts @@ -1,6 +1,4 @@ -import { HttpStatusCode, ResultList } from '@shared/models' -import { Account, ActorFollow } from '../../models/actors' -import { AccountVideoRate, VideoRateType } from '../../models/videos' +import { Account, AccountVideoRate, ActorFollow, HttpStatusCode, ResultList, VideoRateType } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class AccountsCommand extends AbstractCommand { diff --git a/shared/server-commands/users/actors.ts b/shared/server-commands/users/actors.ts deleted file mode 100644 index 12c3e078a..000000000 --- a/shared/server-commands/users/actors.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { pathExists, readdir } from 'fs-extra' -import { join } from 'path' -import { root } from '@shared/core-utils' -import { Account, VideoChannel } from '@shared/models' -import { PeerTubeServer } from '../server' - -async function expectChannelsFollows (options: { - server: PeerTubeServer - handle: string - followers: number - following: number -}) { - const { server } = options - const { data } = await server.channels.list() - - return expectActorFollow({ ...options, data }) -} - -async function expectAccountFollows (options: { - server: PeerTubeServer - handle: string - followers: number - following: number -}) { - const { server } = options - const { data } = await server.accounts.list() - - return expectActorFollow({ ...options, data }) -} - -async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { - const testDirectory = 'test' + serverNumber - - for (const directory of [ 'avatars' ]) { - const directoryPath = join(root(), testDirectory, directory) - - const directoryExists = await pathExists(directoryPath) - expect(directoryExists).to.be.true - - const files = await readdir(directoryPath) - for (const file of files) { - expect(file).to.not.contain(filename) - } - } -} - -export { - expectAccountFollows, - expectChannelsFollows, - checkActorFilesWereRemoved -} - -// --------------------------------------------------------------------------- - -function expectActorFollow (options: { - server: PeerTubeServer - data: (Account | VideoChannel)[] - handle: string - followers: number - following: number -}) { - const { server, data, handle, followers, following } = options - - const actor = data.find(a => a.name + '@' + a.host === handle) - const message = `${handle} on ${server.url}` - - expect(actor, message).to.exist - expect(actor.followersCount).to.equal(followers, message) - expect(actor.followingCount).to.equal(following, message) -} diff --git a/shared/server-commands/users/index.ts b/shared/server-commands/users/index.ts index 460a06f70..c2bc5c44f 100644 --- a/shared/server-commands/users/index.ts +++ b/shared/server-commands/users/index.ts @@ -1,9 +1,7 @@ export * from './accounts-command' -export * from './actors' export * from './blocklist-command' export * from './login' export * from './login-command' -export * from './notifications' export * from './notifications-command' export * from './subscriptions-command' export * from './users-command' diff --git a/shared/server-commands/users/notifications-command.ts b/shared/server-commands/users/notifications-command.ts index 692420b8b..6bd815daa 100644 --- a/shared/server-commands/users/notifications-command.ts +++ b/shared/server-commands/users/notifications-command.ts @@ -1,5 +1,4 @@ -import { HttpStatusCode, ResultList } from '@shared/models' -import { UserNotification, UserNotificationSetting } from '../../models/users' +import { HttpStatusCode, ResultList, UserNotification, UserNotificationSetting } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class NotificationsCommand extends AbstractCommand { diff --git a/shared/server-commands/users/notifications.ts b/shared/server-commands/users/notifications.ts deleted file mode 100644 index 07ccb0f8d..000000000 --- a/shared/server-commands/users/notifications.ts +++ /dev/null @@ -1,795 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' -import { inspect } from 'util' -import { AbuseState, PluginType } from '@shared/models' -import { UserNotification, UserNotificationSetting, UserNotificationSettingValue, UserNotificationType } from '../../models/users' -import { MockSmtpServer } from '../mock-servers/mock-email' -import { PeerTubeServer } from '../server' -import { doubleFollow } from '../server/follows' -import { createMultipleServers } from '../server/servers' -import { setAccessTokensToServers } from './login' - -type CheckerBaseParams = { - server: PeerTubeServer - emails: any[] - socketNotifications: UserNotification[] - token: string - check?: { web: boolean, mail: boolean } -} - -type CheckerType = 'presence' | 'absence' - -function getAllNotificationsSettings (): UserNotificationSetting { - return { - newVideoFromSubscription: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newCommentOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - abuseAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - videoAutoBlacklistAsModerator: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - blacklistOnMyVideo: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - myVideoImportFinished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - myVideoPublished: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - commentMention: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newFollow: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newUserRegistration: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newInstanceFollower: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - abuseNewMessage: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - abuseStateChange: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - autoInstanceFollowing: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newPeerTubeVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL, - newPluginVersion: UserNotificationSettingValue.WEB | UserNotificationSettingValue.EMAIL - } -} - -async function checkNewVideoFromSubscription (options: CheckerBaseParams & { - videoName: string - shortUUID: string - checkType: CheckerType -}) { - const { videoName, shortUUID } = options - const notificationType = UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkVideo(notification.video, videoName, shortUUID) - checkActor(notification.video.channel) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.type !== UserNotificationType.NEW_VIDEO_FROM_SUBSCRIPTION || n.video.name !== videoName - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - return text.indexOf(shortUUID) !== -1 && text.indexOf('Your subscription') !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkVideoIsPublished (options: CheckerBaseParams & { - videoName: string - shortUUID: string - checkType: CheckerType -}) { - const { videoName, shortUUID } = options - const notificationType = UserNotificationType.MY_VIDEO_PUBLISHED - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkVideo(notification.video, videoName, shortUUID) - checkActor(notification.video.channel) - } else { - expect(notification.video).to.satisfy(v => v === undefined || v.name !== videoName) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - return text.includes(shortUUID) && text.includes('Your video') - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkMyVideoImportIsFinished (options: CheckerBaseParams & { - videoName: string - shortUUID: string - url: string - success: boolean - checkType: CheckerType -}) { - const { videoName, shortUUID, url, success } = options - - const notificationType = success ? UserNotificationType.MY_VIDEO_IMPORT_SUCCESS : UserNotificationType.MY_VIDEO_IMPORT_ERROR - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.videoImport.targetUrl).to.equal(url) - - if (success) checkVideo(notification.videoImport.video, videoName, shortUUID) - } else { - expect(notification.videoImport).to.satisfy(i => i === undefined || i.targetUrl !== url) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - const toFind = success ? ' finished' : ' error' - - return text.includes(url) && text.includes(toFind) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkUserRegistered (options: CheckerBaseParams & { - username: string - checkType: CheckerType -}) { - const { username } = options - const notificationType = UserNotificationType.NEW_USER_REGISTRATION - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkActor(notification.account) - expect(notification.account.name).to.equal(username) - } else { - expect(notification).to.satisfy(n => n.type !== notificationType || n.account.name !== username) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - - return text.includes(' registered.') && text.includes(username) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewActorFollow (options: CheckerBaseParams & { - followType: 'channel' | 'account' - followerName: string - followerDisplayName: string - followingDisplayName: string - checkType: CheckerType -}) { - const { followType, followerName, followerDisplayName, followingDisplayName } = options - const notificationType = UserNotificationType.NEW_FOLLOW - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkActor(notification.actorFollow.follower) - expect(notification.actorFollow.follower.displayName).to.equal(followerDisplayName) - expect(notification.actorFollow.follower.name).to.equal(followerName) - expect(notification.actorFollow.follower.host).to.not.be.undefined - - const following = notification.actorFollow.following - expect(following.displayName).to.equal(followingDisplayName) - expect(following.type).to.equal(followType) - } else { - expect(notification).to.satisfy(n => { - return n.type !== notificationType || - (n.actorFollow.follower.name !== followerName && n.actorFollow.following !== followingDisplayName) - }) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - - return text.includes(followType) && text.includes(followingDisplayName) && text.includes(followerDisplayName) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewInstanceFollower (options: CheckerBaseParams & { - followerHost: string - checkType: CheckerType -}) { - const { followerHost } = options - const notificationType = UserNotificationType.NEW_INSTANCE_FOLLOWER - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkActor(notification.actorFollow.follower) - expect(notification.actorFollow.follower.name).to.equal('peertube') - expect(notification.actorFollow.follower.host).to.equal(followerHost) - - expect(notification.actorFollow.following.name).to.equal('peertube') - } else { - expect(notification).to.satisfy(n => { - return n.type !== notificationType || n.actorFollow.follower.host !== followerHost - }) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - - return text.includes('instance has a new follower') && text.includes(followerHost) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkAutoInstanceFollowing (options: CheckerBaseParams & { - followerHost: string - followingHost: string - checkType: CheckerType -}) { - const { followerHost, followingHost } = options - const notificationType = UserNotificationType.AUTO_INSTANCE_FOLLOWING - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - const following = notification.actorFollow.following - checkActor(following) - expect(following.name).to.equal('peertube') - expect(following.host).to.equal(followingHost) - - expect(notification.actorFollow.follower.name).to.equal('peertube') - expect(notification.actorFollow.follower.host).to.equal(followerHost) - } else { - expect(notification).to.satisfy(n => { - return n.type !== notificationType || n.actorFollow.following.host !== followingHost - }) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - - return text.includes(' automatically followed a new instance') && text.includes(followingHost) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkCommentMention (options: CheckerBaseParams & { - shortUUID: string - commentId: number - threadId: number - byAccountDisplayName: string - checkType: CheckerType -}) { - const { shortUUID, commentId, threadId, byAccountDisplayName } = options - const notificationType = UserNotificationType.COMMENT_MENTION - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkComment(notification.comment, commentId, threadId) - checkActor(notification.comment.account) - expect(notification.comment.account.displayName).to.equal(byAccountDisplayName) - - checkVideo(notification.comment.video, undefined, shortUUID) - } else { - expect(notification).to.satisfy(n => n.type !== notificationType || n.comment.id !== commentId) - } - } - - function emailNotificationFinder (email: object) { - const text: string = email['text'] - - return text.includes(' mentioned ') && text.includes(shortUUID) && text.includes(byAccountDisplayName) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -let lastEmailCount = 0 - -async function checkNewCommentOnMyVideo (options: CheckerBaseParams & { - shortUUID: string - commentId: number - threadId: number - checkType: CheckerType -}) { - const { server, shortUUID, commentId, threadId, checkType, emails } = options - const notificationType = UserNotificationType.NEW_COMMENT_ON_MY_VIDEO - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - checkComment(notification.comment, commentId, threadId) - checkActor(notification.comment.account) - checkVideo(notification.comment.video, undefined, shortUUID) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.comment === undefined || n.comment.id !== commentId - }) - } - } - - const commentUrl = `http://localhost:${server.port}/w/${shortUUID};threadId=${threadId}` - - function emailNotificationFinder (email: object) { - return email['text'].indexOf(commentUrl) !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) - - if (checkType === 'presence') { - // We cannot detect email duplicates, so check we received another email - expect(emails).to.have.length.above(lastEmailCount) - lastEmailCount = emails.length - } -} - -async function checkNewVideoAbuseForModerators (options: CheckerBaseParams & { - shortUUID: string - videoName: string - checkType: CheckerType -}) { - const { shortUUID, videoName } = options - const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.abuse.id).to.be.a('number') - checkVideo(notification.abuse.video, videoName, shortUUID) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.abuse === undefined || n.abuse.video.shortUUID !== shortUUID - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewAbuseMessage (options: CheckerBaseParams & { - abuseId: number - message: string - toEmail: string - checkType: CheckerType -}) { - const { abuseId, message, toEmail } = options - const notificationType = UserNotificationType.ABUSE_NEW_MESSAGE - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.abuse.id).to.equal(abuseId) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.type !== notificationType || n.abuse === undefined || n.abuse.id !== abuseId - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - const to = email['to'].filter(t => t.address === toEmail) - - return text.indexOf(message) !== -1 && to.length !== 0 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkAbuseStateChange (options: CheckerBaseParams & { - abuseId: number - state: AbuseState - checkType: CheckerType -}) { - const { abuseId, state } = options - const notificationType = UserNotificationType.ABUSE_STATE_CHANGE - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.abuse.id).to.equal(abuseId) - expect(notification.abuse.state).to.equal(state) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.abuse === undefined || n.abuse.id !== abuseId - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - - const contains = state === AbuseState.ACCEPTED - ? ' accepted' - : ' rejected' - - return text.indexOf(contains) !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewCommentAbuseForModerators (options: CheckerBaseParams & { - shortUUID: string - videoName: string - checkType: CheckerType -}) { - const { shortUUID, videoName } = options - const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.abuse.id).to.be.a('number') - checkVideo(notification.abuse.comment.video, videoName, shortUUID) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.abuse === undefined || n.abuse.comment.video.shortUUID !== shortUUID - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - return text.indexOf(shortUUID) !== -1 && text.indexOf('abuse') !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewAccountAbuseForModerators (options: CheckerBaseParams & { - displayName: string - checkType: CheckerType -}) { - const { displayName } = options - const notificationType = UserNotificationType.NEW_ABUSE_FOR_MODERATORS - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.abuse.id).to.be.a('number') - expect(notification.abuse.account.displayName).to.equal(displayName) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.abuse === undefined || n.abuse.account.displayName !== displayName - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - return text.indexOf(displayName) !== -1 && text.indexOf('abuse') !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkVideoAutoBlacklistForModerators (options: CheckerBaseParams & { - shortUUID: string - videoName: string - checkType: CheckerType -}) { - const { shortUUID, videoName } = options - const notificationType = UserNotificationType.VIDEO_AUTO_BLACKLIST_FOR_MODERATORS - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.videoBlacklist.video.id).to.be.a('number') - checkVideo(notification.videoBlacklist.video, videoName, shortUUID) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.video === undefined || n.video.shortUUID !== shortUUID - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - return text.indexOf(shortUUID) !== -1 && email['text'].indexOf('video-auto-blacklist/list') !== -1 - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewBlacklistOnMyVideo (options: CheckerBaseParams & { - shortUUID: string - videoName: string - blacklistType: 'blacklist' | 'unblacklist' -}) { - const { videoName, shortUUID, blacklistType } = options - const notificationType = blacklistType === 'blacklist' - ? UserNotificationType.BLACKLIST_ON_MY_VIDEO - : UserNotificationType.UNBLACKLIST_ON_MY_VIDEO - - function notificationChecker (notification: UserNotification) { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - const video = blacklistType === 'blacklist' ? notification.videoBlacklist.video : notification.video - - checkVideo(video, videoName, shortUUID) - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - const blacklistText = blacklistType === 'blacklist' - ? 'blacklisted' - : 'unblacklisted' - - return text.includes(shortUUID) && text.includes(blacklistText) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder, checkType: 'presence' }) -} - -async function checkNewPeerTubeVersion (options: CheckerBaseParams & { - latestVersion: string - checkType: CheckerType -}) { - const { latestVersion } = options - const notificationType = UserNotificationType.NEW_PEERTUBE_VERSION - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.peertube).to.exist - expect(notification.peertube.latestVersion).to.equal(latestVersion) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.peertube === undefined || n.peertube.latestVersion !== latestVersion - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - - return text.includes(latestVersion) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function checkNewPluginVersion (options: CheckerBaseParams & { - pluginType: PluginType - pluginName: string - checkType: CheckerType -}) { - const { pluginName, pluginType } = options - const notificationType = UserNotificationType.NEW_PLUGIN_VERSION - - function notificationChecker (notification: UserNotification, checkType: CheckerType) { - if (checkType === 'presence') { - expect(notification).to.not.be.undefined - expect(notification.type).to.equal(notificationType) - - expect(notification.plugin.name).to.equal(pluginName) - expect(notification.plugin.type).to.equal(pluginType) - } else { - expect(notification).to.satisfy((n: UserNotification) => { - return n === undefined || n.plugin === undefined || n.plugin.name !== pluginName - }) - } - } - - function emailNotificationFinder (email: object) { - const text = email['text'] - - return text.includes(pluginName) - } - - await checkNotification({ ...options, notificationChecker, emailNotificationFinder }) -} - -async function prepareNotificationsTest (serversCount = 3, overrideConfigArg: any = {}) { - const userNotifications: UserNotification[] = [] - const adminNotifications: UserNotification[] = [] - const adminNotificationsServer2: UserNotification[] = [] - const emails: object[] = [] - - const port = await MockSmtpServer.Instance.collectEmails(emails) - - const overrideConfig = { - smtp: { - hostname: 'localhost', - port - }, - signup: { - limit: 20 - } - } - const servers = await createMultipleServers(serversCount, Object.assign(overrideConfig, overrideConfigArg)) - - await setAccessTokensToServers(servers) - - if (serversCount > 1) { - await doubleFollow(servers[0], servers[1]) - } - - const user = { username: 'user_1', password: 'super password' } - await servers[0].users.create({ ...user, videoQuota: 10 * 1000 * 1000 }) - const userAccessToken = await servers[0].login.getAccessToken(user) - - await servers[0].notifications.updateMySettings({ token: userAccessToken, settings: getAllNotificationsSettings() }) - await servers[0].notifications.updateMySettings({ settings: getAllNotificationsSettings() }) - - if (serversCount > 1) { - await servers[1].notifications.updateMySettings({ settings: getAllNotificationsSettings() }) - } - - { - const socket = servers[0].socketIO.getUserNotificationSocket({ token: userAccessToken }) - socket.on('new-notification', n => userNotifications.push(n)) - } - { - const socket = servers[0].socketIO.getUserNotificationSocket() - socket.on('new-notification', n => adminNotifications.push(n)) - } - - if (serversCount > 1) { - const socket = servers[1].socketIO.getUserNotificationSocket() - socket.on('new-notification', n => adminNotificationsServer2.push(n)) - } - - const { videoChannels } = await servers[0].users.getMyInfo() - const channelId = videoChannels[0].id - - return { - userNotifications, - adminNotifications, - adminNotificationsServer2, - userAccessToken, - emails, - servers, - channelId - } -} - -// --------------------------------------------------------------------------- - -export { - getAllNotificationsSettings, - - CheckerBaseParams, - CheckerType, - checkMyVideoImportIsFinished, - checkUserRegistered, - checkAutoInstanceFollowing, - checkVideoIsPublished, - checkNewVideoFromSubscription, - checkNewActorFollow, - checkNewCommentOnMyVideo, - checkNewBlacklistOnMyVideo, - checkCommentMention, - checkNewVideoAbuseForModerators, - checkVideoAutoBlacklistForModerators, - checkNewAbuseMessage, - checkAbuseStateChange, - checkNewInstanceFollower, - prepareNotificationsTest, - checkNewCommentAbuseForModerators, - checkNewAccountAbuseForModerators, - checkNewPeerTubeVersion, - checkNewPluginVersion -} - -// --------------------------------------------------------------------------- - -async function checkNotification (options: CheckerBaseParams & { - notificationChecker: (notification: UserNotification, checkType: CheckerType) => void - emailNotificationFinder: (email: object) => boolean - checkType: CheckerType -}) { - const { server, token, checkType, notificationChecker, emailNotificationFinder, socketNotifications, emails } = options - - const check = options.check || { web: true, mail: true } - - if (check.web) { - const notification = await server.notifications.getLatest({ token: token }) - - if (notification || checkType !== 'absence') { - notificationChecker(notification, checkType) - } - - const socketNotification = socketNotifications.find(n => { - try { - notificationChecker(n, 'presence') - return true - } catch { - return false - } - }) - - if (checkType === 'presence') { - const obj = inspect(socketNotifications, { depth: 5 }) - expect(socketNotification, 'The socket notification is absent when it should be present. ' + obj).to.not.be.undefined - } else { - const obj = inspect(socketNotification, { depth: 5 }) - expect(socketNotification, 'The socket notification is present when it should not be present. ' + obj).to.be.undefined - } - } - - if (check.mail) { - // Last email - const email = emails - .slice() - .reverse() - .find(e => emailNotificationFinder(e)) - - if (checkType === 'presence') { - const texts = emails.map(e => e.text) - expect(email, 'The email is absent when is should be present. ' + inspect(texts)).to.not.be.undefined - } else { - expect(email, 'The email is present when is should not be present. ' + inspect(email)).to.be.undefined - } - } -} - -function checkVideo (video: any, videoName?: string, shortUUID?: string) { - if (videoName) { - expect(video.name).to.be.a('string') - expect(video.name).to.not.be.empty - expect(video.name).to.equal(videoName) - } - - if (shortUUID) { - expect(video.shortUUID).to.be.a('string') - expect(video.shortUUID).to.not.be.empty - expect(video.shortUUID).to.equal(shortUUID) - } - - expect(video.id).to.be.a('number') -} - -function checkActor (actor: any) { - expect(actor.displayName).to.be.a('string') - expect(actor.displayName).to.not.be.empty - expect(actor.host).to.not.be.undefined -} - -function checkComment (comment: any, commentId: number, threadId: number) { - expect(comment.id).to.equal(commentId) - expect(comment.threadId).to.equal(threadId) -} diff --git a/shared/server-commands/users/users-command.ts b/shared/server-commands/users/users-command.ts index 90c5f2183..b5ae9008e 100644 --- a/shared/server-commands/users/users-command.ts +++ b/shared/server-commands/users/users-command.ts @@ -4,6 +4,7 @@ import { HttpStatusCode, MyUser, ResultList, + ScopedToken, User, UserAdminFlag, UserCreateResult, @@ -13,7 +14,6 @@ import { UserVideoQuota, UserVideoRate } from '@shared/models' -import { ScopedToken } from '@shared/models/users/user-scoped-token' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/server-commands/videos/blacklist-command.ts b/shared/server-commands/videos/blacklist-command.ts index 3a2ef89ba..47e23ebc8 100644 --- a/shared/server-commands/videos/blacklist-command.ts +++ b/shared/server-commands/videos/blacklist-command.ts @@ -1,6 +1,5 @@ -import { HttpStatusCode, ResultList } from '@shared/models' -import { VideoBlacklist, VideoBlacklistType } from '../../models/videos' +import { HttpStatusCode, ResultList, VideoBlacklist, VideoBlacklistType } from '@shared/models' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class BlacklistCommand extends AbstractCommand { diff --git a/shared/server-commands/videos/captions-command.ts b/shared/server-commands/videos/captions-command.ts index a65ea99e3..62bf9c5e6 100644 --- a/shared/server-commands/videos/captions-command.ts +++ b/shared/server-commands/videos/captions-command.ts @@ -1,5 +1,5 @@ +import { buildAbsoluteFixturePath } from '@shared/core-utils' import { HttpStatusCode, ResultList, VideoCaption } from '@shared/models' -import { buildAbsoluteFixturePath } from '../miscs' import { AbstractCommand, OverrideCommandOptions } from '../shared' export class CaptionsCommand extends AbstractCommand { diff --git a/shared/server-commands/videos/captions.ts b/shared/server-commands/videos/captions.ts deleted file mode 100644 index 35e722408..000000000 --- a/shared/server-commands/videos/captions.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expect } from 'chai' -import request from 'supertest' -import { HttpStatusCode } from '@shared/models' - -async function testCaptionFile (url: string, captionPath: string, toTest: RegExp | string) { - const res = await request(url) - .get(captionPath) - .expect(HttpStatusCode.OK_200) - - if (toTest instanceof RegExp) { - expect(res.text).to.match(toTest) - } else { - expect(res.text).to.contain(toTest) - } -} - -// --------------------------------------------------------------------------- - -export { - testCaptionFile -} diff --git a/shared/server-commands/videos/channels-command.ts b/shared/server-commands/videos/channels-command.ts index e406e570b..8ab124658 100644 --- a/shared/server-commands/videos/channels-command.ts +++ b/shared/server-commands/videos/channels-command.ts @@ -1,7 +1,13 @@ import { pick } from '@shared/core-utils' -import { ActorFollow, HttpStatusCode, ResultList, VideoChannel, VideoChannelCreateResult } from '@shared/models' -import { VideoChannelCreate } from '../../models/videos/channel/video-channel-create.model' -import { VideoChannelUpdate } from '../../models/videos/channel/video-channel-update.model' +import { + ActorFollow, + HttpStatusCode, + ResultList, + VideoChannel, + VideoChannelCreate, + VideoChannelCreateResult, + VideoChannelUpdate +} from '@shared/models' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/server-commands/videos/index.ts b/shared/server-commands/videos/index.ts index 26e663f46..68a188b21 100644 --- a/shared/server-commands/videos/index.ts +++ b/shared/server-commands/videos/index.ts @@ -1,6 +1,5 @@ export * from './blacklist-command' export * from './captions-command' -export * from './captions' export * from './change-ownership-command' export * from './channels' export * from './channels-command' @@ -10,10 +9,7 @@ export * from './imports-command' export * from './live-command' export * from './live' export * from './playlists-command' -export * from './playlists' export * from './services-command' export * from './streaming-playlists-command' -export * from './streaming-playlists' export * from './comments-command' export * from './videos-command' -export * from './videos' diff --git a/shared/server-commands/videos/live-command.ts b/shared/server-commands/videos/live-command.ts index 74f5d3089..f7816eca0 100644 --- a/shared/server-commands/videos/live-command.ts +++ b/shared/server-commands/videos/live-command.ts @@ -3,8 +3,8 @@ import { readdir } from 'fs-extra' import { omit } from 'lodash' import { join } from 'path' +import { wait } from '@shared/core-utils' import { HttpStatusCode, LiveVideo, LiveVideoCreate, LiveVideoUpdate, VideoCreateResult, VideoDetails, VideoState } from '@shared/models' -import { wait } from '../miscs' import { unwrapBody } from '../requests' import { AbstractCommand, OverrideCommandOptions } from '../shared' import { sendRTMPStream, testFfmpegStreamError } from './live' diff --git a/shared/server-commands/videos/live.ts b/shared/server-commands/videos/live.ts index d3665bc90..7a7faa911 100644 --- a/shared/server-commands/videos/live.ts +++ b/shared/server-commands/videos/live.ts @@ -1,10 +1,5 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ - -import { expect } from 'chai' import ffmpeg, { FfmpegCommand } from 'fluent-ffmpeg' -import { pathExists, readdir } from 'fs-extra' -import { join } from 'path' -import { buildAbsoluteFixturePath, wait } from '../miscs' +import { buildAbsoluteFixturePath, wait } from '@shared/core-utils' import { PeerTubeServer } from '../server/server' function sendRTMPStream (options: { @@ -95,43 +90,11 @@ async function waitUntilLiveSavedOnAllServers (servers: PeerTubeServer[], videoI } } -async function checkLiveCleanupAfterSave (server: PeerTubeServer, videoUUID: string, resolutions: number[] = []) { - const basePath = server.servers.buildDirectory('streaming-playlists') - const hlsPath = join(basePath, 'hls', videoUUID) - - if (resolutions.length === 0) { - const result = await pathExists(hlsPath) - expect(result).to.be.false - - return - } - - const files = await readdir(hlsPath) - - // fragmented file and playlist per resolution + master playlist + segments sha256 json file - expect(files).to.have.lengthOf(resolutions.length * 2 + 2) - - for (const resolution of resolutions) { - const fragmentedFile = files.find(f => f.endsWith(`-${resolution}-fragmented.mp4`)) - expect(fragmentedFile).to.exist - - const playlistFile = files.find(f => f.endsWith(`${resolution}.m3u8`)) - expect(playlistFile).to.exist - } - - const masterPlaylistFile = files.find(f => f.endsWith('-master.m3u8')) - expect(masterPlaylistFile).to.exist - - const shaFile = files.find(f => f.endsWith('-segments-sha256.json')) - expect(shaFile).to.exist -} - export { sendRTMPStream, waitFfmpegUntilError, testFfmpegStreamError, stopFfmpeg, waitUntilLivePublishedOnAllServers, - waitUntilLiveSavedOnAllServers, - checkLiveCleanupAfterSave + waitUntilLiveSavedOnAllServers } diff --git a/shared/server-commands/videos/playlists.ts b/shared/server-commands/videos/playlists.ts deleted file mode 100644 index 3dde52bb9..000000000 --- a/shared/server-commands/videos/playlists.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { expect } from 'chai' -import { readdir } from 'fs-extra' -import { join } from 'path' -import { root } from '../miscs' - -async function checkPlaylistFilesWereRemoved ( - playlistUUID: string, - internalServerNumber: number, - directories = [ 'thumbnails' ] -) { - const testDirectory = 'test' + internalServerNumber - - for (const directory of directories) { - const directoryPath = join(root(), testDirectory, directory) - - const files = await readdir(directoryPath) - for (const file of files) { - expect(file).to.not.contain(playlistUUID) - } - } -} - -export { - checkPlaylistFilesWereRemoved -} diff --git a/shared/server-commands/videos/streaming-playlists.ts b/shared/server-commands/videos/streaming-playlists.ts deleted file mode 100644 index 0451c0efe..000000000 --- a/shared/server-commands/videos/streaming-playlists.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { expect } from 'chai' -import { basename } from 'path' -import { sha256 } from '@shared/core-utils/crypto' -import { removeFragmentedMP4Ext } from '@shared/core-utils' -import { HttpStatusCode, VideoStreamingPlaylist } from '@shared/models' -import { PeerTubeServer } from '../server' - -async function checkSegmentHash (options: { - server: PeerTubeServer - baseUrlPlaylist: string - baseUrlSegment: string - resolution: number - hlsPlaylist: VideoStreamingPlaylist -}) { - const { server, baseUrlPlaylist, baseUrlSegment, resolution, hlsPlaylist } = options - const command = server.streamingPlaylists - - const file = hlsPlaylist.files.find(f => f.resolution.id === resolution) - const videoName = basename(file.fileUrl) - - const playlist = await command.get({ url: `${baseUrlPlaylist}/${removeFragmentedMP4Ext(videoName)}.m3u8` }) - - const matches = /#EXT-X-BYTERANGE:(\d+)@(\d+)/.exec(playlist) - - const length = parseInt(matches[1], 10) - const offset = parseInt(matches[2], 10) - const range = `${offset}-${offset + length - 1}` - - const segmentBody = await command.getSegment({ - url: `${baseUrlSegment}/${videoName}`, - expectedStatus: HttpStatusCode.PARTIAL_CONTENT_206, - range: `bytes=${range}` - }) - - const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) - expect(sha256(segmentBody)).to.equal(shaBody[videoName][range]) -} - -async function checkLiveSegmentHash (options: { - server: PeerTubeServer - baseUrlSegment: string - videoUUID: string - segmentName: string - hlsPlaylist: VideoStreamingPlaylist -}) { - const { server, baseUrlSegment, videoUUID, segmentName, hlsPlaylist } = options - const command = server.streamingPlaylists - - const segmentBody = await command.getSegment({ url: `${baseUrlSegment}/${videoUUID}/${segmentName}` }) - const shaBody = await command.getSegmentSha256({ url: hlsPlaylist.segmentsSha256Url }) - - expect(sha256(segmentBody)).to.equal(shaBody[segmentName]) -} - -async function checkResolutionsInMasterPlaylist (options: { - server: PeerTubeServer - playlistUrl: string - resolutions: number[] -}) { - const { server, playlistUrl, resolutions } = options - - const masterPlaylist = await server.streamingPlaylists.get({ url: playlistUrl }) - - for (const resolution of resolutions) { - const reg = new RegExp( - '#EXT-X-STREAM-INF:BANDWIDTH=\\d+,RESOLUTION=\\d+x' + resolution + ',(FRAME-RATE=\\d+,)?CODECS="avc1.64001f,mp4a.40.2"' - ) - - expect(masterPlaylist).to.match(reg) - } -} - -export { - checkSegmentHash, - checkLiveSegmentHash, - checkResolutionsInMasterPlaylist -} diff --git a/shared/server-commands/videos/videos-command.ts b/shared/server-commands/videos/videos-command.ts index 8ea828b40..ead57b9aa 100644 --- a/shared/server-commands/videos/videos-command.ts +++ b/shared/server-commands/videos/videos-command.ts @@ -5,8 +5,7 @@ import { createReadStream, stat } from 'fs-extra' import got, { Response as GotResponse } from 'got' import { omit } from 'lodash' import validator from 'validator' -import { buildUUID } from '@shared/core-utils/uuid' -import { pick } from '@shared/core-utils' +import { buildAbsoluteFixturePath, buildUUID, pick, wait } from '@shared/core-utils' import { HttpStatusCode, ResultList, @@ -20,7 +19,6 @@ import { VideosCommonQuery, VideoTranscodingCreate } from '@shared/models' -import { buildAbsoluteFixturePath, wait } from '../miscs' import { unwrapBody } from '../requests' import { waitJobs } from '../server' import { AbstractCommand, OverrideCommandOptions } from '../shared' diff --git a/shared/server-commands/videos/videos.ts b/shared/server-commands/videos/videos.ts deleted file mode 100644 index 2c3464aa8..000000000 --- a/shared/server-commands/videos/videos.ts +++ /dev/null @@ -1,104 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ - -import { expect } from 'chai' -import { pathExists, readdir } from 'fs-extra' -import { basename, join } from 'path' -import { HttpStatusCode, VideoCaption, VideoDetails } from '@shared/models' -import { waitJobs } from '../server' -import { PeerTubeServer } from '../server/server' -import { VideoEdit } from './videos-command' - -async function checkVideoFilesWereRemoved (options: { - server: PeerTubeServer - video: VideoDetails - captions?: VideoCaption[] - onlyVideoFiles?: boolean // default false -}) { - const { video, server, captions = [], onlyVideoFiles = false } = options - - const webtorrentFiles = video.files || [] - const hlsFiles = video.streamingPlaylists[0]?.files || [] - - const thumbnailName = basename(video.thumbnailPath) - const previewName = basename(video.previewPath) - - const torrentNames = webtorrentFiles.concat(hlsFiles).map(f => basename(f.torrentUrl)) - - const captionNames = captions.map(c => basename(c.captionPath)) - - const webtorrentFilenames = webtorrentFiles.map(f => basename(f.fileUrl)) - const hlsFilenames = hlsFiles.map(f => basename(f.fileUrl)) - - let directories: { [ directory: string ]: string[] } = { - videos: webtorrentFilenames, - redundancy: webtorrentFilenames, - [join('playlists', 'hls')]: hlsFilenames, - [join('redundancy', 'hls')]: hlsFilenames - } - - if (onlyVideoFiles !== true) { - directories = { - ...directories, - - thumbnails: [ thumbnailName ], - previews: [ previewName ], - torrents: torrentNames, - captions: captionNames - } - } - - for (const directory of Object.keys(directories)) { - const directoryPath = server.servers.buildDirectory(directory) - - const directoryExists = await pathExists(directoryPath) - if (directoryExists === false) continue - - const existingFiles = await readdir(directoryPath) - for (const existingFile of existingFiles) { - for (const shouldNotExist of directories[directory]) { - expect(existingFile, `File ${existingFile} should not exist in ${directoryPath}`).to.not.contain(shouldNotExist) - } - } - } -} - -async function saveVideoInServers (servers: PeerTubeServer[], uuid: string) { - for (const server of servers) { - server.store.videoDetails = await server.videos.get({ id: uuid }) - } -} - -function checkUploadVideoParam ( - server: PeerTubeServer, - token: string, - attributes: Partial, - expectedStatus = HttpStatusCode.OK_200, - mode: 'legacy' | 'resumable' = 'legacy' -) { - return mode === 'legacy' - ? server.videos.buildLegacyUpload({ token, attributes, expectedStatus }) - : server.videos.buildResumeUpload({ token, attributes, expectedStatus }) -} - -// serverNumber starts from 1 -async function uploadRandomVideoOnServers ( - servers: PeerTubeServer[], - serverNumber: number, - additionalParams?: VideoEdit & { prefixName?: string } -) { - const server = servers.find(s => s.serverNumber === serverNumber) - const res = await server.videos.randomUpload({ wait: false, additionalParams }) - - await waitJobs(servers) - - return res -} - -// --------------------------------------------------------------------------- - -export { - checkUploadVideoParam, - uploadRandomVideoOnServers, - checkVideoFilesWereRemoved, - saveVideoInServers -} -- cgit v1.2.3