]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Ask password reset/email verif error handling
authorChocobozzz <me@florianbigard.com>
Wed, 28 Sep 2022 14:00:32 +0000 (16:00 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 28 Sep 2022 14:00:32 +0000 (16:00 +0200)
With a user that uses a plugin authentication

server/controllers/api/users/index.ts
server/middlewares/validators/users.ts
server/tests/external-plugins/auth-ldap.ts

index 0b27d5277c005c52bcb8ec7e1c0d80ae61e768a6..07b9ae395a619ccb3dc445af749887535f60ad94 100644 (file)
@@ -343,7 +343,7 @@ async function askResetUserPassword (req: express.Request, res: express.Response
 
   const verificationString = await Redis.Instance.setResetPasswordVerificationString(user.id)
   const url = WEBSERVER.URL + '/reset-password?userId=' + user.id + '&verificationString=' + verificationString
-  await Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url)
+  Emailer.Instance.addPasswordResetEmailJob(user.username, user.email, url)
 
   return res.status(HttpStatusCode.NO_CONTENT_204).end()
 }
index 2de5265fb50978ecdec32bc58ece815597b45c1a..eb693318fc2a998e603b6e4a6c7be073e55bd867 100644 (file)
@@ -411,6 +411,13 @@ const usersAskResetPasswordValidator = [
       return res.status(HttpStatusCode.NO_CONTENT_204).end()
     }
 
+    if (res.locals.user.pluginAuth) {
+      return res.fail({
+        status: HttpStatusCode.CONFLICT_409,
+        message: 'Cannot recover password of a user that uses a plugin authentication.'
+      })
+    }
+
     return next()
   }
 ]
@@ -454,6 +461,13 @@ const usersAskSendVerifyEmailValidator = [
       return res.status(HttpStatusCode.NO_CONTENT_204).end()
     }
 
+    if (res.locals.user.pluginAuth) {
+      return res.fail({
+        status: HttpStatusCode.CONFLICT_409,
+        message: 'Cannot ask verification email of a user that uses a plugin authentication.'
+      })
+    }
+
     return next()
   }
 ]
index d7f155d2a315247e7447ee2bc30695b2f938a417..6f6a574a07be8660bd1306b0a3cfd1a03e69f5a3 100644 (file)
@@ -94,6 +94,14 @@ describe('Official plugin auth-ldap', function () {
     await server.login.login({ user: { username: 'fry@planetexpress.com', password: 'fry' } })
   })
 
+  it('Should not be able to ask password reset', async function () {
+    await server.users.askResetPassword({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 })
+  })
+
+  it('Should not be able to ask email verification', async function () {
+    await server.users.askSendVerifyEmail({ email: 'fry@planetexpress.com', expectedStatus: HttpStatusCode.CONFLICT_409 })
+  })
+
   it('Should not login if the plugin is uninstalled', async function () {
     await server.plugins.uninstall({ npmName: 'peertube-plugin-auth-ldap' })