Skip to content

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

Fix updating a user with the same email as before

Chocobozzzc345f683d641
diff --git a/packages/tests/src/api/check-params/my-user.ts b/packages/tests/src/api/check-params/my-user.ts
index 64d8ec336c..2e8400a287 100644
--- a/packages/tests/src/api/check-params/my-user.ts
+++ b/packages/tests/src/api/check-params/my-user.ts
@@ -57,7 +57,6 @@ describe('Test my user API validators', function () {
})
describe('When updating my account', function () {
-
it('Should fail with an invalid email attribute', async function () {
const fields = {
email: 'blabla',
@@ -86,6 +85,19 @@ describe('Test my user API validators', function () {
}
})
+ it('Should succeed with the same email', async function () {
+ await makePutBodyRequest({
+ url: server.url,
+ path: path + 'me',
+ token: userToken,
+ fields: {
+ email: '[email protected]',
+ currentPassword: 'password'
+ },
+ expectedStatus: HttpStatusCode.NO_CONTENT_204
+ })
+ })
+
it('Should fail with a too small password', async function () {
const fields = {
currentPassword: 'password',
@@ -318,14 +330,12 @@ describe('Test my user API validators', function () {
})
describe('When managing my scoped tokens', function () {
-
it('Should fail to get my scoped tokens with an non authenticated user', async function () {
await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
})
it('Should fail to get my scoped tokens with a bad token', async function () {
await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
-
})
it('Should succeed to get my scoped tokens', async function () {
@@ -448,7 +458,6 @@ describe('Test my user API validators', function () {
})
describe('When blocking/unblocking/removing user', function () {
-
it('Should fail with an incorrect id', async function () {
const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
@@ -498,7 +507,6 @@ describe('Test my user API validators', function () {
})
describe('When deleting our account', function () {
-
it('Should fail with with the root account', async function () {
await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
})
diff --git a/packages/tests/src/api/check-params/users-admin.ts b/packages/tests/src/api/check-params/users-admin.ts
index 91a93c63fc..b77bfed6d0 100644
--- a/packages/tests/src/api/check-params/users-admin.ts
+++ b/packages/tests/src/api/check-params/users-admin.ts
@@ -311,7 +311,6 @@ describe('Test users admin API validators', function () {
})
describe('When getting a user', function () {
-
it('Should fail with an non authenticated user', async function () {
await makeGetRequest({
url: server.url,
@@ -331,7 +330,6 @@ describe('Test users admin API validators', function () {
})
describe('When updating a user', function () {
-
it('Should fail with an invalid email attribute', async function () {
const fields = {
email: 'blabla'
@@ -352,6 +350,18 @@ describe('Test users admin API validators', function () {
})
})
+ it('Should succeed with the same email', async function () {
+ const fields = { email: '[email protected]' }
+
+ await makePutBodyRequest({
+ url: server.url,
+ path: path + userId,
+ token: server.accessToken,
+ fields,
+ expectedStatus: HttpStatusCode.CONFLICT_409
+ })
+ })
+
it('Should fail with an invalid emailVerified attribute', async function () {
const fields = {
emailVerified: 'yes'
diff --git a/packages/tests/src/api/users/users.ts b/packages/tests/src/api/users/users.ts
index 222493a387..0705f19da1 100644
--- a/packages/tests/src/api/users/users.ts
+++ b/packages/tests/src/api/users/users.ts
@@ -5,7 +5,8 @@ import { testAvatarSize } from '@tests/shared/checks.js'
import { AbuseState, HttpStatusCode, UserAdminFlag, UserRole, VideoPlaylistType } from '@peertube/peertube-models'
import {
cleanupTests,
- createSingleServer, PeerTubeServer,
+ createSingleServer,
+ PeerTubeServer,
setAccessTokensToServers
} from '@peertube/peertube-server-commands'
@@ -37,7 +38,6 @@ describe('Test users', function () {
})
describe('Creating a user', function () {
-
it('Should be able to create a new user', async function () {
await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
})
@@ -81,7 +81,6 @@ describe('Test users', function () {
})
describe('Users listing', function () {
-
it('Should list all the users', async function () {
const { data, total } = await server.users.list()
@@ -186,7 +185,6 @@ describe('Test users', function () {
})
describe('Update my account', function () {
-
it('Should update my password', async function () {
await server.users.updateMe({
token: userToken,
@@ -339,7 +337,6 @@ describe('Test users', function () {
})
describe('Updating another user', function () {
-
it('Should be able to update another user', async function () {
await server.users.update({
userId,
@@ -391,7 +388,6 @@ describe('Test users', function () {
})
describe('Remove a user', function () {
-
before(async function () {
await server.users.update({
userId,
diff --git a/server/core/middlewares/validators/users/users.ts b/server/core/middlewares/validators/users/users.ts
index 6f0b8afc3a..8087a014a7 100644
--- a/server/core/middlewares/validators/users/users.ts
+++ b/server/core/middlewares/validators/users/users.ts
@@ -200,7 +200,7 @@ export const usersUpdateValidator = [
return res.fail({ message: 'Cannot change root role.' })
}
- if (req.body.email && !await checkEmailDoesNotAlreadyExist(req.body.email, res)) return
+ if (req.body.email && req.body.email !== user.email && !await checkEmailDoesNotAlreadyExist(req.body.email, res)) return
return next()
}
@@ -281,7 +281,7 @@ export const usersUpdateMeValidator = [
if (areValidationErrors(req, res, { omitBodyLog: true })) return
- if (req.body.email && !await checkEmailDoesNotAlreadyExist(req.body.email, res)) return
+ if (req.body.email && req.body.email !== user.email && !await checkEmailDoesNotAlreadyExist(req.body.email, res)) return
return next()
}