mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	fix: #8918
This commit is contained in:
		| @@ -82,15 +82,15 @@ usersAPI.update = async function (caller, data) { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| usersAPI.delete = async function (caller, { uid, password }) { | usersAPI.delete = async function (caller, { uid, password }) { | ||||||
| 	processDeletion({ uid: uid, method: 'delete', password, caller }); | 	await processDeletion({ uid: uid, method: 'delete', password, caller }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| usersAPI.deleteContent = async function (caller, { uid, password }) { | usersAPI.deleteContent = async function (caller, { uid, password }) { | ||||||
| 	processDeletion({ uid, method: 'deleteContent', password, caller }); | 	await processDeletion({ uid, method: 'deleteContent', password, caller }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| usersAPI.deleteAccount = async function (caller, { uid, password }) { | usersAPI.deleteAccount = async function (caller, { uid, password }) { | ||||||
| 	processDeletion({ uid, method: 'deleteAccount', password, caller }); | 	await processDeletion({ uid, method: 'deleteAccount', password, caller }); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| usersAPI.deleteMany = async function (caller, data) { | usersAPI.deleteMany = async function (caller, data) { | ||||||
|   | |||||||
| @@ -37,6 +37,7 @@ SocketUser.exists = async function (socket, data) { | |||||||
|  |  | ||||||
| SocketUser.deleteAccount = async function (socket, data) { | SocketUser.deleteAccount = async function (socket, data) { | ||||||
| 	sockets.warnDeprecated(socket, 'DELETE /api/v3/users/:uid/account'); | 	sockets.warnDeprecated(socket, 'DELETE /api/v3/users/:uid/account'); | ||||||
|  | 	data.uid = socket.uid; | ||||||
| 	await api.users.deleteAccount(socket, data); | 	await api.users.deleteAccount(socket, data); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										29
									
								
								test/user.js
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								test/user.js
									
									
									
									
									
								
							| @@ -1593,18 +1593,29 @@ describe('User', function () { | |||||||
| 			}); | 			}); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should delete user', function (done) { | 		it('should delete user', async function () { | ||||||
| 			User.create({ username: 'tobedeleted' }, function (err, _uid) { | 			const uid = await User.create({ username: 'willbedeleted' }); | ||||||
| 				assert.ifError(err); | 			await socketUser.deleteAccount({ uid: uid }, {}); | ||||||
| 				socketUser.deleteAccount({ uid: _uid }, {}, function (err) { | 			const exists = await socketUser.exists({ uid: testUid }, { username: 'willbedeleted' }); | ||||||
| 					assert.ifError(err); |  | ||||||
| 					socketUser.exists({ uid: testUid }, { username: 'doesnot exist' }, function (err, exists) { |  | ||||||
| 						assert.ifError(err); |  | ||||||
| 			assert(!exists); | 			assert(!exists); | ||||||
| 						done(); |  | ||||||
| 					}); |  | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should fail to delete user with wrong password', async function () { | ||||||
|  | 			const uid = await User.create({ username: 'willbedeletedpwd', password: '123456' }); | ||||||
|  | 			let err; | ||||||
|  | 			try { | ||||||
|  | 				await socketUser.deleteAccount({ uid: uid }, { password: '654321' }); | ||||||
|  | 			} catch (_err) { | ||||||
|  | 				err = _err; | ||||||
|  | 			} | ||||||
|  | 			assert.strictEqual(err.message, '[[error:invalid-password]]'); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
|  | 		it('should delete user with correct password', async function () { | ||||||
|  | 			const uid = await User.create({ username: 'willbedeletedcorrectpwd', password: '123456' }); | ||||||
|  | 			await socketUser.deleteAccount({ uid: uid }, { password: '123456' }); | ||||||
|  | 			const exists = await User.exists(uid); | ||||||
|  | 			assert(!exists); | ||||||
| 		}); | 		}); | ||||||
|  |  | ||||||
| 		it('should fail to delete user if account deletion is not allowed', async function () { | 		it('should fail to delete user if account deletion is not allowed', async function () { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user