Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Check role is undefined

Chocobozzz3bf698925fa8
diff --git a/packages/tests/src/api/check-params/users-admin.ts b/packages/tests/src/api/check-params/users-admin.ts
index 6d998911ec..9bf322687e 100644
--- a/packages/tests/src/api/check-params/users-admin.ts
+++ b/packages/tests/src/api/check-params/users-admin.ts
@@ -1,7 +1,5 @@
/* oxlint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
-import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
-import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js'
import { omit } from '@peertube/peertube-core-utils'
import { HttpStatusCode, UserAdminFlag, UserRole } from '@peertube/peertube-models'
import {
@@ -15,6 +13,8 @@ import {
PeerTubeServer,
setAccessTokensToServers
} from '@peertube/peertube-server-commands'
+import { checkBadCountPagination, checkBadSort, checkBadStartPagination } from '@tests/shared/checks.js'
+import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js'
describe('Test users admin API validators', function () {
const path = '/api/v1/users/'
@@ -466,15 +466,17 @@ describe('Test users admin API validators', function () {
})
it('Should fail to update user role for a moderator', async function () {
- const fields = { role: UserRole.MODERATOR }
-
- await makePutBodyRequest({
- url: server.url,
- path: path + userId,
- token: moderatorToken,
- fields,
- expectedStatus: HttpStatusCode.FORBIDDEN_403
- })
+ for (const token of [ userToken, moderatorToken ]) {
+ for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
+ await makePutBodyRequest({
+ url: server.url,
+ path: path + userId,
+ token,
+ fields: { role },
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
+ })
+ }
+ }
})
it('Should succeed to update a user with a moderator', async function () {
diff --git a/server/core/lib/auth/external-auth.ts b/server/core/lib/auth/external-auth.ts
index e12cb26e4a..af2aaf3d5b 100644
--- a/server/core/lib/auth/external-auth.ts
+++ b/server/core/lib/auth/external-auth.ts
@@ -230,19 +230,21 @@ function isAuthResultValid (npmName: string, authName: string, result: RegisterS
if (!result.email) return returnError('email')
// Following fields are optional
- if (result.role && !isUserRoleValid(result.role)) return returnError('role')
- if (result.displayName && !isUserDisplayNameValid(result.displayName)) return returnError('displayName')
- if (result.adminFlags && !isUserAdminFlagsValid(result.adminFlags)) return returnError('adminFlags')
- if (result.videoQuota && !isUserVideoQuotaValid(result.videoQuota + '')) return returnError('videoQuota')
- if (result.videoQuotaDaily && !isUserVideoQuotaDailyValid(result.videoQuotaDaily + '')) return returnError('videoQuotaDaily')
- if (result.language && !isUserLanguage(result.language)) return returnError('language')
-
- if (result.userUpdater && typeof result.userUpdater !== 'function') {
+ if (result.role !== undefined && !isUserRoleValid(result.role)) return returnError('role')
+ if (result.displayName !== undefined && !isUserDisplayNameValid(result.displayName)) return returnError('displayName')
+ if (result.adminFlags !== undefined && !isUserAdminFlagsValid(result.adminFlags)) return returnError('adminFlags')
+ if (result.videoQuota !== undefined && !isUserVideoQuotaValid(result.videoQuota + '')) return returnError('videoQuota')
+ if (result.videoQuotaDaily !== undefined && !isUserVideoQuotaDailyValid(result.videoQuotaDaily + '')) {
+ return returnError('videoQuotaDaily')
+ }
+ if (result.language !== undefined && !isUserLanguage(result.language)) return returnError('language')
+
+ if (result.userUpdater !== undefined && typeof result.userUpdater !== 'function') {
logger.error('Auth method %s of plugin %s did not provide a valid user updater function.', authName, npmName)
return false
}
- if (result.externalId && (typeof result.externalId !== 'string' || result.externalId.length > 255)) {
+ if (result.externalId !== undefined && (typeof result.externalId !== 'string' || result.externalId.length > 255)) {
return returnError('externalId')
}
diff --git a/server/core/middlewares/validators/users/users.ts b/server/core/middlewares/validators/users/users.ts
index de30ebba48..f195037a06 100644
--- a/server/core/middlewares/validators/users/users.ts
+++ b/server/core/middlewares/validators/users/users.ts
@@ -209,7 +209,7 @@ export const usersUpdateValidator = [
}
if (!checkCanModerate(user, res)) return
- if (req.body.role && !checkCanSetRole(req.body.role, res)) return
+ if (req.body.role !== undefined && !checkCanSetRole(req.body.role, res)) return
if (
req.body.email &&