diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 31757b4..5dff392 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -28,14 +28,6 @@ app.get('/health', (_req, res) => { }); app.post('/login', async (req, res) => { - const isValidUser = validateCredentials(req.body.username, req.body.password); - - if (!isValidUser) { - // Si las credenciales son inválidas, devuelve un error 401 - res.status(401).json({ error: 'Credenciales incorrectas' }); - return; // Termina la ejecución de la función para evitar ejecutar el código restante - } - try { // Forward the login request to the authentication service const authResponse = await axios.post(authServiceUrl+'/login', req.body); @@ -45,14 +37,26 @@ app.post('/login', async (req, res) => { } }); + function validateCredentials(username, password) { // Verifica si la contraseña es erronea - const invalidPassword = 'no'; + if (password.length < 8) { + return false; + } - return !(password === invalidPassword); + return true; } app.post('/adduser', async (req, res) => { + + const isValidUser = validateCredentials(req.body.username, req.body.password); + + if (!isValidUser) { + // Si las credenciales son inválidas, devuelve un error 401 + res.status(401).json({ error: 'Credenciales incorrectas. La contraseña debe contener al menos 8 caracteres' }); + return; // Termina la ejecución de la función para evitar ejecutar el código restante + } + try { // Forward the add user request to the user service const userResponse = await axios.post(userServiceUrl+'/adduser', req.body); diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index 211098e..f7ab259 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -21,30 +21,18 @@ describe('Gateway Service', () => { return Promise.resolve({ data: { userId: 'mockedUserId' } }); } }); - - /* - // Test /login endpoint - it('deberia iniciar sesión correctamente', async () => { - const response = await request(app) - .post('/login') - .send({ username: 'testuser', password: 'testpassword' }); - - expect(response.statusCode).toBe(200); - expect(response.body.token).toBe('mockedToken'); - }); - */ - // Prueba de manejo de errores para el endpoint /login - it('deberia devolver error al iniciar sesion', async () => { - // Datos de prueba para iniciar sesión (incorrectos) + // Prueba de manejo de errores para el endpoint /adduser + it('deberia devolver error al registrate', async () => { + // Datos de prueba para registro (incorrectos) const invalidLoginData = { username: 'userInvalido', - password: 'no' + password: 'invalid' }; // Realizamos una solicitud POST al endpoint /login con datos incorrectos const response = await request(app) - .post('/login') + .post('/adduser') .send(invalidLoginData); // Verificamos que la respuesta tenga un código de estado 401 (Unauthorized) diff --git a/webapp/e2e/steps/register-form.steps.js b/webapp/e2e/steps/01-register-form.steps.js similarity index 98% rename from webapp/e2e/steps/register-form.steps.js rename to webapp/e2e/steps/01-register-form.steps.js index f805781..ee540bc 100644 --- a/webapp/e2e/steps/register-form.steps.js +++ b/webapp/e2e/steps/01-register-form.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('An unregistered user', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "REGÍSTRATE" }); }); diff --git a/webapp/e2e/steps/login.steps.js b/webapp/e2e/steps/02-login.steps.js similarity index 98% rename from webapp/e2e/steps/login.steps.js rename to webapp/e2e/steps/02-login.steps.js index 8fab6a7..6d4cdb3 100644 --- a/webapp/e2e/steps/login.steps.js +++ b/webapp/e2e/steps/02-login.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('A user that is logged in the application', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "INICIA SESIÓN" }); }); diff --git a/webapp/e2e/steps/home.steps.js b/webapp/e2e/steps/03-home.steps.js similarity index 98% rename from webapp/e2e/steps/home.steps.js rename to webapp/e2e/steps/03-home.steps.js index 9064c93..0e001d0 100644 --- a/webapp/e2e/steps/home.steps.js +++ b/webapp/e2e/steps/03-home.steps.js @@ -30,7 +30,7 @@ defineFeature(feature, test => { given('A user that is logged in the application', async () => { username = "pablo@gmail.com" - password = "pabloasw" + password = "pabloasw1" await expect(page).toClick("button", { text: "INICIA SESIÓN" }); });