diff --git a/.env.template b/.env.template index 65b2cda9..9089c881 100644 --- a/.env.template +++ b/.env.template @@ -13,14 +13,11 @@ inxtbridge_server__ssl__redirect=443 inxtbridge_redis__password= inxtbridge_stripe__SIG_TEST=stripe_sig_test inxtbridge_gateway__username=user -inxtbridge_mailer__auth__pass=mailerpass inxtbridge_storage__mongoOpts__user=admin inxtbridge_stripe__PK_TEST=pk_test_vpHlkSQ7DhmzSW4EbmfT1lIJ inxtbridge_complex__rpcPassword=networkpass -inxtbridge_mailer__host=smtp.sendgrid.net inxtbridge_server__public__host=drive-server inxtbridge_stripe__SK_TEST=sk_test_stripe_key -inxtbridge_mailer__auth__user=internxt inxtbridge_mailer__sendgrid__api_key=APIKEY inxtbridge_mailer__sendgrid__delete_template_id=add_template_id inxtbridge_mailer__sendgrid__sandbox_mode=false @@ -28,7 +25,6 @@ inxtbridge_storage__mongoOpts__maxPoolSize=100 inxtbridge_stripe__SIG=whsec_otra_clave_de_stripe inxtbridge_drive__api=http://drive-server:8000 inxtbridge_server__public__port=443 -inxtbridge_mailer__port=465 inxtbridge_gateway__password=gatewaypass inxtbridge_storage__mongoOpts__dbName=__inxt-network inxtbridge_gateway__JWT_SECRET=LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUZ3d0RRWUpLb1pJaHZjTkFRRUJCUUFEU3dBd1NBSkJBTDlDTVRlZGEramdIcGJuTmtlSm51TlpnYzg5TGFvMApjUDZJenZSa2EydDFFSm54eWUwNXdSWGZLMXFpbTFOMGU3cGhkd0RkRWYvNGJ1eFc5V2g1UWxzQ0F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo= diff --git a/.env.test b/.env.test index 4b47ef64..3f5387ef 100644 --- a/.env.test +++ b/.env.test @@ -18,20 +18,16 @@ inxtbridge_redis__host=redis inxtbridge_complex__rpcUser=inxtbridge_complex__rpcUser inxtbridge_stripe__SIG_TEST=inxtbridge_stripe__SIG_TEST inxtbridge_gateway__username=inxtbridge_gateway__username -inxtbridge_mailer__auth__pass=inxtbridge_mailer__auth__pass inxtbridge_stripe__PK_TEST=inxtbridge_stripe__PK_TEST inxtbridge_complex__rpcPassword=inxtbridge_complex__rpcPassword -inxtbridge_mailer__host=inxtbridge_mailer__host inxtbridge_server__public__host=inxtbridge_server__public__host inxtbridge_stripe__SK_TEST=inxtbridge_stripe__SK_TEST inxtbridge_complex__rpcUrl=inxtbridge_complex__rpcUrl -inxtbridge_mailer__auth__user=inxtbridge_mailer__auth__user inxtbridge_mailer__sendgrid__api_key=inxtbridge_mailer__sendgrid__api_key inxtbridge_storage__mongoOpts__server__poolSize=100 inxtbridge_stripe__SIG=inxtbridge_stripe__SIG inxtbridge_drive__api=inxtbridge_drive__api inxtbridge_server__public__port=443 -inxtbridge_mailer__port=465 inxtbridge_gateway__password=inxtbridge_gateway__password inxtbridge_NEW_QUEUE_HOST=network-queue inxtbridge_NEW_QUEUE_PORT=6379 diff --git a/lib/config.js b/lib/config.js index f582190e..60bcfa91 100644 --- a/lib/config.js +++ b/lib/config.js @@ -47,13 +47,6 @@ const DEFAULTS = { level: CONSTANTS.LOG_LEVEL_INFO }, mailer: { - host: '127.0.0.1', - port: 465, - secure: true, - auth: { - user: 'username', - pass: 'password' - }, from: 'activate@internxt.com', sendgrid: { api_key: '', diff --git a/lib/core/mail/SendGridMailService.ts b/lib/core/mail/SendGridMailService.ts index aed414e4..25f5b78b 100644 --- a/lib/core/mail/SendGridMailService.ts +++ b/lib/core/mail/SendGridMailService.ts @@ -1,10 +1,10 @@ import sendGridMail, { MailService as SendGridClient } from '@sendgrid/mail'; export interface MailerConfig { - from?: string; + from: string; sendgrid: { api_key: string; - sandbox_mode?: boolean; + sandbox_mode: boolean; delete_template_id: string; }; } @@ -13,8 +13,6 @@ export interface MailService { sendDeleteUserMail: (sendTo: string, redirect: string) => Promise; } -const DEFAULT_FROM = 'activate@internxt.com'; - export class SendGridMailService implements MailService { constructor( private config: MailerConfig, @@ -29,7 +27,7 @@ export class SendGridMailService implements MailService { await this.client.send({ to: sendTo, from: { - email: from || DEFAULT_FROM, + email: from, name: 'Internxt', }, subject: '', @@ -47,7 +45,7 @@ export class SendGridMailService implements MailService { templateId: sendgrid.delete_template_id, mailSettings: { sandboxMode: { - enable: sendgrid.sandbox_mode || false, + enable: sendgrid.sandbox_mode, }, }, }, false); diff --git a/lib/core/mail/usecase.ts b/lib/core/mail/usecase.ts deleted file mode 100644 index 858311b2..00000000 --- a/lib/core/mail/usecase.ts +++ /dev/null @@ -1,58 +0,0 @@ -export interface Mailer { - dispatchSendGrid: ( - email: string, - type: 'delete' | 'reset', - params: { - token: string; - redirect: string; - url: string; - }, - cb: (err?: Error) => void - ) => void; -} - -export interface MailUsecase { - sendDeleteUserMail: (sendTo: string, token: string, redirect: string) => Promise; - sendResetPasswordMail: (sendTo: string, token: string, redirect: string, url?: string) => Promise -} - -export interface Profile { - host: string; - port?: number; - protocol: 'https:' | 'http:' -} - -export class SendGridMailUsecase implements MailUsecase { - constructor( - private mailer: Mailer, - private profile: Profile - ) {} - - async sendDeleteUserMail(sendTo: string, token: string, redirect: string): Promise { - const { protocol, host, port } = this.profile; - - await new Promise((resolve, reject) => { - this.mailer.dispatchSendGrid(sendTo, 'delete', { - token, - redirect, - url: protocol + '//' + host + (port ? `:${port}` : '') - }, (err) => { - if (err) { reject(err) } else resolve(null); - }); - }) - } - - async sendResetPasswordMail(sendTo: string, token: string, redirect: string, url?: string | undefined): Promise { - const { protocol, host, port } = this.profile; - - await new Promise((resolve, reject) => { - this.mailer.dispatchSendGrid(sendTo, 'reset', { - token, - redirect, - url: url || protocol + '//' + host + (port ? `:${port}` : '') - }, (err) => { - if (err) { reject(err) } else resolve(null); - }); - }); - } -} diff --git a/lib/core/users/usecase.ts b/lib/core/users/usecase.ts index cb2a44f1..e0de3e03 100644 --- a/lib/core/users/usecase.ts +++ b/lib/core/users/usecase.ts @@ -1,8 +1,7 @@ -import { createHash, randomBytes } from 'crypto'; +import { createHash } from 'crypto'; import { UsersRepository } from './Repository'; import { BucketsRepository } from '../buckets/Repository'; -import { MailUsecase } from '../mail/usecase'; import { MailService } from '../mail/SendGridMailService'; import { EventBus, EventBusEvents } from '../../server/eventBus'; import { FramesRepository } from '../frames/Repository'; @@ -16,9 +15,6 @@ function isEmailValid(email: string) { return email.match(emailPattern); } -export const RESET_PASSWORD_TOKEN_BYTES_LENGTH = 256; -export const SHA256_HASH_BYTES_LENGTH = 32; - export interface UserSpaceSnapshot { maxSpaceBytes: number; totalUsedSpaceBytes: number; @@ -56,17 +52,6 @@ export class EmailIsAlreadyInUseError extends Error { } } -export class ResetPasswordImpersonationError extends Error { - constructor( - userPerformingAction?: string, - userImpersonated?: string - ) { - super(`User ${userPerformingAction || ''} tried to impersonate ${userImpersonated || ''}`); - - Object.setPrototypeOf(this, ResetPasswordImpersonationError.prototype); - } -} - export class UserDeactivationDisabledError extends Error { constructor() { super('This account has the deactivation disabled'); @@ -80,7 +65,6 @@ export class UsersUsecase { private usersRepository: UsersRepository, private framesRepository: FramesRepository, private bucketsRepository: BucketsRepository, - private mailUsecase: MailUsecase, private eventBus: EventBus, private mailService: MailService ) {} @@ -175,68 +159,6 @@ export class UsersUsecase { await this.usersRepository.updateByUuid(uuid, { maxSpaceBytes: bytes }); } - async requestPasswordReset( - userRequestingResetEmail: User['email'], - redirect: string, - url?: string - ): Promise { - const user = await this.usersRepository.findByEmail(userRequestingResetEmail); - - if (!user) { - throw new UserNotFoundError(); - } - - const resetToken = randomBytes(RESET_PASSWORD_TOKEN_BYTES_LENGTH).toString('hex'); - - await this.usersRepository.updateById(user.id, { - resetter: resetToken - }); - - await this.mailUsecase.sendResetPasswordMail( - userRequestingResetEmail, - resetToken, - redirect, - url - ); - - return user; - } - - /** - * Confirms and applies the password reset - * @param password new password - * @param resetter token used to reset the password - */ - async resetPassword(password: string, resetter: string) { - const isSHA256Encoded = Buffer.from(password, 'hex').length === SHA256_HASH_BYTES_LENGTH; - - if (!isSHA256Encoded) { - throw new InvalidDataFormatError('Password must be an hex encoded SHA-256 hash'); - } - - const resetterIsHexEncoded = Buffer.from(resetter, 'hex').length === RESET_PASSWORD_TOKEN_BYTES_LENGTH; - - if (!resetterIsHexEncoded) { - throw new InvalidDataFormatError('Resetter must be an hex encoded 256 byte string'); - } - - const user = await this.usersRepository.findOne({ resetter }); - - if (!user) { - throw new UserNotFoundError(); - } - - const hashpass = createHash('sha256').update(password).digest('hex'); - const newResetter = null; - - await this.usersRepository.updateById(user.id, { - resetter: newResetter, - hashpass - }); - - return user; - } - async requestUserDestroy( userId: string, deactivator: string, diff --git a/lib/engine.js b/lib/engine.js index 0c5b4ec3..e0a2b82c 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -14,7 +14,6 @@ const { ErrorHandlerFactory: errorHandler } = require('./server/middleware/error const Server = require('./server'); const pow = require('./server/middleware/pow'); -const Mailer = require('inxt-service-mailer'); const { SendGridMailService } = require('./core/mail/SendGridMailService'); const log = require('./logger'); const NetworkMessageQueue = require('./server/queues/networkQueue'); @@ -119,7 +118,6 @@ Engine.prototype.start = function (callback) { NOTIFICATIONS_API_KEY ); - this.mailer = new Mailer(this._config.mailer); this.mailService = new SendGridMailService(this._config.mailer); this.redis = require('redis').createClient(this._config.redis); this.redis.on('ready', () => { @@ -206,7 +204,6 @@ Engine.prototype._configureApp = function () { const routers = Server.Routes({ config: this._config, storage: this.storage, - mailer: this.mailer, redis: this.redis, networkQueue: this.networkQueue, }); @@ -248,24 +245,9 @@ Engine.prototype._configureApp = function () { app.use(errorHandler({ logger: log })); app.use(json()); - const profile = this._config.server.public || this._config.server; - const port = [443, 80].indexOf(profile.port) > -1 ? profile.port : undefined; - const protocol = - this._config.server.ssl && - this._config.server.ssl.cert && - this._config.server.ssl.key - ? 'https:' - : 'http:'; - bindNewRoutes( app, this.storage, - this.mailer, - { - host: profile.host, - port, - protocol, - }, log, this.networkQueue, this.notifications, diff --git a/lib/server/http/index.ts b/lib/server/http/index.ts index 588c4915..620ef712 100644 --- a/lib/server/http/index.ts +++ b/lib/server/http/index.ts @@ -5,7 +5,6 @@ import { MongoDBBucketsRepository, MongoDBUsersRepository, UsersUsecase } from " import { BucketsRepository } from "../../core/buckets/Repository"; import { UsersRepository } from "../../core/users/Repository"; -import { Mailer, MailUsecase, Profile, SendGridMailUsecase } from "../../core/mail/usecase"; import { MailService } from "../../core/mail/SendGridMailService"; import { createUsersHTTPRouter } from "./users"; import { HTTPUsersController } from "./users/controller"; @@ -54,8 +53,6 @@ interface Models { export function bindNewRoutes( app: Application, storage: { models: Models }, - mailer: Mailer, - profile: Profile, log: Logger, networkQueue: any, notifications: Notifications, @@ -74,14 +71,12 @@ export function bindNewRoutes( const shardsRepository: ShardsRepository = new MongoDBShardsRepository(models.Shard); const fileStateRepository: FileStateRepository = new MongoDBFileStateRepository(models.FileState); - const mailUsecase: MailUsecase = new SendGridMailUsecase(mailer, profile); const eventBus = new EventBus(log, notifications); const usersUsecase = new UsersUsecase( usersRepository, framesRepository, bucketsRepository, - mailUsecase, eventBus, mailService ); diff --git a/lib/server/http/users/controller.ts b/lib/server/http/users/controller.ts index bb1671e2..06a845f8 100644 --- a/lib/server/http/users/controller.ts +++ b/lib/server/http/users/controller.ts @@ -2,7 +2,6 @@ import { Request, Response } from 'express'; import { Logger } from 'winston'; import { - InvalidDataFormatError, UserDeactivationDisabledError, UserNotFoundError, UsersUsecase @@ -16,72 +15,6 @@ export class HTTPUsersController { private logger: Logger ) {} - async resetPassword( - req: Request<{ token?: string }, {}, { password?: string }>, - res: Response - ): Promise { - const { token } = req.params; - const { password } = req.body; - - try { - if (!token || !password) { - return res.status(400).send(); - } - - const user = await this.usersUsecase.resetPassword(password, token); - - res.status(200).send(JSON.stringify(user)); - } catch (err) { - if (err instanceof InvalidDataFormatError) { - return res.status(400).send({ message: err.message }); - } - - if (err instanceof UserNotFoundError) { - return res.status(404).send(); - } - - this.logger.error( - 'Error resetting password for token %s: %s. %s', - token, - (err as Error).message, - (err as Error).stack - ); - - return res.status(500).send(); - } - } - - async requestPasswordReset( - req: Request<{ id: string }, {}, { redirect?: string, url?: string }>, - res: Response - ) { - if (!req.body || !req.body.redirect) { - return res.status(400).send(); - } - - const { id: userId } = req.params; - const { redirect, url } = req.body; - - try { - const user = await this.usersUsecase.requestPasswordReset(userId, redirect, url); - - return res.status(200).send(JSON.stringify(user)); - } catch (err) { - if (err instanceof UserNotFoundError) { - return res.status(404).send(); - } - - this.logger.error( - 'Error requesting password reset for user %s: %s. %s', - userId, - (err as Error).message, - (err as Error).stack - ); - - return res.status(500).send({ message: 'Internal Server Error' }); - } - } - async requestDestroyUser( req: Request<{}, {}, {}, { deactivator?: string, redirect?: string }>, res: Response diff --git a/lib/server/http/users/index.ts b/lib/server/http/users/index.ts index 8a787669..fdf6ac74 100644 --- a/lib/server/http/users/index.ts +++ b/lib/server/http/users/index.ts @@ -7,9 +7,6 @@ export const createUsersHTTPRouter = ( ): Router => { const router = Router(); - router.post('/:id/request-password-reset', controller.requestPasswordReset.bind(controller)); - router.post('/confirm-password-reset/:token', controller.resetPassword.bind(controller)); - router.delete('/request-deactivate', basicAuth, controller.requestDestroyUser.bind(controller)); router.delete('/confirm-deactivate/:token', controller.destroyUser.bind(controller)); diff --git a/lib/server/routefactory.js b/lib/server/routefactory.js index 14e53e08..61defaa7 100644 --- a/lib/server/routefactory.js +++ b/lib/server/routefactory.js @@ -13,7 +13,6 @@ module.exports = function RouteFactory(options) { config: options.config, network: options.network, storage: options.storage, - mailer: options.mailer, redis: options.redis, networkQueue: options.networkQueue, }).getEndpointDefinitions(); diff --git a/lib/server/routes/index.js b/lib/server/routes/index.js index 2f22ad2c..b41d3e98 100644 --- a/lib/server/routes/index.js +++ b/lib/server/routes/index.js @@ -7,7 +7,6 @@ * @param {Config} options.config * @param {complex.Client} options.network * @param {Storage} options.storage - * @param {Mailer} options.mailer */ function Router(options) { if (!(this instanceof Router)) { @@ -16,7 +15,6 @@ function Router(options) { this.config = options.config; this.storage = options.storage; - this.mailer = options.mailer; this.redis = options.redis; this.networkQueue = options.networkQueue; } diff --git a/package.json b/package.json index 376756a7..51c8efd7 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,6 @@ "express": "^4.22.3", "hat": "0.0.3", "helmet": "^3.20.0", - "inxt-service-mailer": "internxt/mailer#v1.5.2", "is-ip": "^2.0.0", "jsonwebtoken": "^8.5.1", "lodash": "4.18.1", diff --git a/tests/lib/core/mail/SendGridMailService.test.ts b/tests/lib/core/mail/SendGridMailService.test.ts index ad75c9e6..af0075a1 100644 --- a/tests/lib/core/mail/SendGridMailService.test.ts +++ b/tests/lib/core/mail/SendGridMailService.test.ts @@ -51,20 +51,6 @@ describe('SendGridMailService', () => { }, false); }); - it('When no sender or sandbox mode are configured, then it uses the defaults', async () => { - const client = buildClient(); - const usecase = new SendGridMailService( - { sendgrid: { api_key: 'api-key', delete_template_id: 'tpl' } }, - client - ); - - await usecase.sendDeleteUserMail('user@internxt.com', 'redirect'); - - const [payload] = client.send.mock.calls[0]; - expect(payload.from).toStrictEqual({ email: 'activate@internxt.com', name: 'Internxt' }); - expect(payload.mailSettings).toStrictEqual({ sandboxMode: { enable: false } }); - }); - it('When sendgrid fails, then the error is propagated', async () => { const client = buildClient(); client.send.mockRejectedValueOnce(new Error('sendgrid down')); diff --git a/tests/lib/core/users/usecase.test.ts b/tests/lib/core/users/usecase.test.ts index ef8591f4..781812e3 100644 --- a/tests/lib/core/users/usecase.test.ts +++ b/tests/lib/core/users/usecase.test.ts @@ -1,25 +1,20 @@ import { stub } from 'sinon'; import { v4 } from 'uuid'; import { createLogger } from 'winston'; -import { createHash, randomBytes } from 'crypto'; import { UsersRepository } from '../../../../lib/core/users/Repository'; import { MongoDBBucketsRepository, MongoDBUsersRepository, UsersUsecase, - InvalidDataFormatError, UserAlreadyExistsError, UserNotFoundError, UserDeactivationDisabledError, - RESET_PASSWORD_TOKEN_BYTES_LENGTH, - SHA256_HASH_BYTES_LENGTH, EmailIsAlreadyInUseError } from '../../../../lib/core'; import { MongoDBFramesRepository } from '../../../../lib/core/frames/MongoDBFramesRepository'; import { FramesRepository } from '../../../../lib/core/frames/Repository'; import { BucketsRepository } from '../../../../lib/core/buckets/Repository'; -import { Mailer, MailUsecase, SendGridMailUsecase } from '../../../../lib/core/mail/usecase'; import { MailService } from '../../../../lib/core/mail/SendGridMailService'; import { EventBus, EventBusEvents } from '../../../../lib/server/eventBus'; import { User } from '../../../../lib/core/users/User'; @@ -30,7 +25,6 @@ let usersRepository: UsersRepository; let framesRepository: FramesRepository; let bucketsRepository: BucketsRepository; let usecase: UsersUsecase; -let mailUsecase: MailUsecase; let mailService: MailService; let eventBus: EventBus; let notifications: Notifications; @@ -39,10 +33,6 @@ beforeEach(() => { usersRepository = new MongoDBUsersRepository({}); framesRepository = new MongoDBFramesRepository({}); bucketsRepository = new MongoDBBucketsRepository({}); - mailUsecase = new SendGridMailUsecase({} as Mailer, { - host: '', - protocol: 'http:', - }); notifications = new Notifications('',''); mailService = { sendDeleteUserMail: async () => {} }; eventBus = new EventBus(createLogger(), notifications); @@ -51,7 +41,6 @@ beforeEach(() => { usersRepository, framesRepository, bucketsRepository, - mailUsecase, eventBus, mailService ); @@ -146,117 +135,6 @@ describe('Users usecases', () => { }); }); - describe('requestPasswordReset()', () => { - it('Should work if input data is valid', async () => { - const findByIdStub = stub(usersRepository, 'findByEmail').resolves(fakeUser); - const updateByIdStub = stub(usersRepository, 'updateById').resolves(); - const sendResetPasswordMailStub = stub(mailUsecase, 'sendResetPasswordMail').resolves(); - - const user = await usecase.requestPasswordReset(fakeUser.email, fakeUser.password); - - expect(findByIdStub.calledOnce).toBeTruthy(); - expect(updateByIdStub.calledOnce).toBeTruthy(); - expect(sendResetPasswordMailStub.calledOnce).toBeTruthy(); - expect(user).toStrictEqual(fakeUser); - }); - - it('Should reject if user does not exist', async () => { - const findByIdStub = stub(usersRepository, 'findByEmail').resolves(null); - - try { - await usecase.requestPasswordReset(fakeUser.email, fakeUser.password); - expect(true).toBeFalsy() - } catch (err) { - expect(err).toBeInstanceOf(UserNotFoundError); - } - - expect(findByIdStub.calledOnce).toBeTruthy(); - }); - - it('Should try to update the reset token of the user requesting the reset', async () => { - const findByIdStub = stub(usersRepository, 'findByEmail').resolves(fakeUser); - const updateByIdStub = stub(usersRepository, 'updateById').resolves(); - const sendResetPasswordMailStub = stub(mailUsecase, 'sendResetPasswordMail').resolves(); - - await usecase.requestPasswordReset(fakeUser.email, fakeUser.password); - - expect(findByIdStub.calledOnce).toBeTruthy(); - expect(updateByIdStub.calledOnce).toBeTruthy(); - expect(sendResetPasswordMailStub.calledOnce).toBeTruthy(); - - const [userRequestingResetId, { resetter }] = updateByIdStub.args[0]; - - expect(userRequestingResetId).toStrictEqual(fakeUser.id); - expect(Buffer.from(resetter || '', 'hex').length).toBe(RESET_PASSWORD_TOKEN_BYTES_LENGTH); - }); - }); - - describe('resetPassword()', () => { - it('Should work if input data is valid', async () => { - const resetToken = randomBytes(RESET_PASSWORD_TOKEN_BYTES_LENGTH).toString('hex'); - const newPassword = randomBytes(SHA256_HASH_BYTES_LENGTH).toString('hex'); - - const findOneStub = stub(usersRepository, 'findOne').resolves(fakeUser); - const updateByIdStub = stub(usersRepository, 'updateById').resolves(); - - const user = await usecase.resetPassword(newPassword, resetToken); - - const [{ resetter }] = findOneStub.args[0]; - const [userId, { resetter: newResetter, hashpass }] = updateByIdStub.args[0]; - - expect(findOneStub.calledOnce).toBeTruthy(); - expect(resetter).not.toBeNull(); - expect(resetter).toBe(resetToken); - - expect(updateByIdStub.calledOnce).toBeTruthy(); - expect(userId).toBe(fakeUser.id); - expect(newResetter).toBeNull(); - expect(hashpass).toBe( - createHash('sha256').update(newPassword).digest('hex') - ); - - expect(user).toStrictEqual(fakeUser); - }); - - it('Should throw if the new password is invalid', async () => { - const resetToken = randomBytes(RESET_PASSWORD_TOKEN_BYTES_LENGTH).toString('hex'); - const newPassword = randomBytes(SHA256_HASH_BYTES_LENGTH - 1).toString('hex'); - - try { - await usecase.resetPassword(newPassword, resetToken); - expect(true).toBeFalsy(); - } catch (err) { - expect(err).toBeInstanceOf(InvalidDataFormatError); - } - }); - - it('Should throw if the reset token is invalid', async () => { - const resetToken = randomBytes(RESET_PASSWORD_TOKEN_BYTES_LENGTH - 1).toString('hex'); - const newPassword = randomBytes(SHA256_HASH_BYTES_LENGTH).toString('hex'); - - try { - await usecase.resetPassword(newPassword, resetToken); - expect(true).toBeFalsy(); - } catch (err) { - expect(err).toBeInstanceOf(InvalidDataFormatError); - } - }); - - it('Should throw if the user does not exist', async () => { - const resetToken = randomBytes(RESET_PASSWORD_TOKEN_BYTES_LENGTH).toString('hex'); - const newPassword = randomBytes(SHA256_HASH_BYTES_LENGTH).toString('hex'); - - stub(usersRepository, 'findOne').resolves(null); - - try { - await usecase.resetPassword(newPassword, resetToken); - expect(false).toBeTruthy(); - } catch (err) { - expect(err).toBeInstanceOf(UserNotFoundError); - } - }); - }); - describe('updateUserStorage()', () => { it('Should upgrade the user storage', async () => { const uuid = fakeUser.uuid; diff --git a/tests/lib/e2e/users/users.e2e-spec.ts b/tests/lib/e2e/users/users.e2e-spec.ts index 88d40fb6..6adbf03a 100644 --- a/tests/lib/e2e/users/users.e2e-spec.ts +++ b/tests/lib/e2e/users/users.e2e-spec.ts @@ -32,9 +32,6 @@ describe('Bridge E2E Tests', () => { describe('Deleting an existing user', () => { it('When requesting user deactivation, it should work for authorized user email', async () => { - // Arrange: Mock SendGrid call - engine.mailer.dispatchSendGrid = jest.fn((_, __, ___, cb) => { sendGridMail.send(null as any, null as any, cb) }) - // Arrange: Create User const payload = generateTestUserData() const user = await createTestUser({ user: payload }) diff --git a/yarn.lock b/yarn.lock index 6d099d01..7f8a8770 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2048,7 +2048,7 @@ astral-regex@^2.0.0: resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31" integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ== -async@^3.1.0, async@^3.2.0, async@^3.2.3: +async@^3.2.0, async@^3.2.3: version "3.2.6" resolved "https://registry.yarnpkg.com/async/-/async-3.2.6.tgz#1b0728e14929d51b85b449b7f06e27c1145e38ce" integrity sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA== @@ -3489,7 +3489,7 @@ graceful-fs@^4.2.9: resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== -handlebars@^4.1.2, handlebars@^4.7.10: +handlebars@^4.7.10: version "4.7.10" resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.10.tgz#12419ea1b41391b3ffcf003f2164dcbce090c417" integrity sha512-P5VJMVM7qgBn6vjXMw8WG9uVI+ncf2pi72j4de4yz5ZULLj2RGqLYaKOYGsgyrViQ0tePOVlN1tDCCXXtFqXKg== @@ -3715,15 +3715,6 @@ ini@~1.3.0: resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== -inxt-service-mailer@internxt/mailer#v1.5.2: - version "1.5.1" - resolved "https://codeload.github.com/internxt/mailer/tar.gz/27c3f6dc235af64410df50594cf4d65fc1d6435b" - dependencies: - "@sendgrid/mail" "^8.1.6" - async "^3.1.0" - handlebars "^4.1.2" - nodemailer "^7.0.10" - ioredis@5.11.1: version "5.11.1" resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-5.11.1.tgz#2d1e52e350a79ee3b00883f3681a410427b49f28" @@ -4898,11 +4889,6 @@ node-releases@^2.0.27: resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.27.tgz#eedca519205cf20f650f61d56b070db111231e4e" integrity sha512-nmh3lCkYZ3grZvqcCH+fjmQ7X+H0OeZgP40OierEaAptX4XofMh5kwNbWh7lBduUzCcV/8kZ+NDLCwm2iorIlA== -nodemailer@^7.0.10: - version "7.0.13" - resolved "https://registry.yarnpkg.com/nodemailer/-/nodemailer-7.0.13.tgz#74acaa55f0c6f9476384c29f27f53e467e8483cd" - integrity sha512-PNDFSJdP+KFgdsG3ZzMXCgquO7I6McjY2vlqILjtJd0hy8wEvtugS9xKRF2NWlPNGxvLCXlTNIae4serI7dinw== - nodemon@^2.0.15: version "2.0.22" resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-2.0.22.tgz#182c45c3a78da486f673d6c1702e00728daf5258"