ActivityPub-federated video streaming platform using P2P directly in your web browser
Fix broken sorts/invalid sort checkers
Chocobozzzb201ee0c7793
diff --git a/packages/tests/src/api/check-params/channel-syncs.ts b/packages/tests/src/api/check-params/channel-syncs.tsindex d51c7e3c84..ee6890cd2c 100644--- a/packages/tests/src/api/check-params/channel-syncs.ts+++ b/packages/tests/src/api/check-params/channel-syncs.ts@@ -258,6 +258,19 @@ describe('Test video channel sync API validator', () => {})})+ it('Should succeed with every sortable column', async function () {+ for (const column of [ 'externalChannelUrl', 'videoChannel', 'createdAt', 'lastSyncAt', 'state' ]) {+ for (const sort of [ column, '-' + column ]) {+ await command.listByAccount({+ accountName: 'root',+ sort,+ token: server.accessToken,+ expectedStatus: HttpStatusCode.OK_200+ })+ }+ }+ })+it('Should fail with no authentication', async function () {await command.listByAccount({accountName: 'root',diff --git a/packages/tests/src/api/check-params/video-change-ownership.ts b/packages/tests/src/api/check-params/video-change-ownership.tsindex 1ed1928f9f..32cbc0a124 100644--- a/packages/tests/src/api/check-params/video-change-ownership.ts+++ b/packages/tests/src/api/check-params/video-change-ownership.ts@@ -2,6 +2,7 @@import { ChangeOwnershipState, HttpStatusCode, UserRole, VideoCreateResult } from '@peertube/peertube-models'import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@peertube/peertube-server-commands'+import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'import { expect } from 'chai'describe('Test video change ownership API validator', function () {@@ -100,6 +101,12 @@ describe('Test video change ownership API validator', function () {})describe('List ownership change requests', function () {+ it('Should fail with bad pagination/sort params', async function () {+ await checkBadStartPagination(server.url, '/api/v1/videos/ownership', server.accessToken)+ await checkBadCountPagination(server.url, '/api/v1/videos/ownership', server.accessToken)+ await checkBadSort(server.url, '/api/v1/videos/ownership', server.accessToken)+ })+it('Should fail if not authenticated', async function () {await server.changeOwnership.listVideos({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })})@@ -111,6 +118,14 @@ describe('Test video change ownership API validator', function () {})describe('List video ownership changes', function () {+ it('Should fail with bad pagination/sort params', async function () {+ const path = '/api/v1/videos/' + rootVideo.uuid + '/ownership'++ await checkBadStartPagination(server.url, path, server.accessToken)+ await checkBadCountPagination(server.url, path, server.accessToken)+ await checkBadSort(server.url, path, server.accessToken)+ })+it('Should fail if not authenticated', async function () {await server.changeOwnership.listOfVideo({videoId: rootVideo.id,diff --git a/server/core/controllers/api/videos/ownership.ts b/server/core/controllers/api/videos/ownership.tsindex c83352a0c4..823580d8d2 100644--- a/server/core/controllers/api/videos/ownership.ts+++ b/server/core/controllers/api/videos/ownership.ts@@ -51,6 +51,7 @@ ownershipVideoRouter.get(authenticate,paginationValidator,setDefaultPagination,+ changeOwnershipSortValidator,asyncRetryTransactionMiddleware(listAccountVideoOwnershipChanges))diff --git a/server/core/models/shared/sort.ts b/server/core/models/shared/sort.tsindex ed2a737ec4..08efdf7bde 100644--- a/server/core/models/shared/sort.ts+++ b/server/core/models/shared/sort.ts@@ -113,7 +113,7 @@ export function getChannelSyncSort (value: string): OrderItem[] {const { direction, field } = buildSortDirectionAndField(value)if (field.toLowerCase() === 'videochannel') {return [- [ literal('"VideoChannel.name"'), direction ]+ [ 'VideoChannel.name', direction ]]}return [ [ field, direction ] ]@@ -146,7 +146,7 @@ export function buildSortDirectionAndField (value: string) {}export function throwOnInvalidSortColumnName (columnName: string) {- if (columnName.match(/^[a-zA-Z."]+$/) === null) {+ if (columnName.match(/^[a-zA-Z.]+$/) === null) {throw new Error('Invalid sort column ' + columnName)}}