Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lara f mz #120

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,16 @@ app.post('/login', async (req, res) => {
}
});


function validateCredentials(username, password) {
// Verifica si la contraseña es erronea
if (password.length < 8) {
return false;
}

return true;
}

app.post('/adduser', async (req, res) => {

const isValidUser = validateCredentials(req.body.username, req.body.password);
try {
const { username, password, valido, mensajeError } = req.body;

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
}
if (!valido) {
// Si las credenciales son inválidas, devuelve un error 401
res.status(401).json({ error: mensajeError });
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);
res.json(userResponse.data);
Expand Down Expand Up @@ -110,6 +99,15 @@ app.get('/getUserData', async (req, res) => {
}
});

app.get('/getUsernames', async (req, res) => {
try{
const getUserDataResponse = await axios.get(userServiceUrl+ `/getUsernames`)
res.json(getUserDataResponse.data);
}catch(error){
res.status(error.response.status).json({error: error.response.data.error});
}
});

// Read the OpenAPI YAML file synchronously
let openapiPath='./openapi.yaml';
if (fs.existsSync(openapiPath)) {
Expand Down
11 changes: 0 additions & 11 deletions gatewayservice/gateway-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,6 @@ describe('Gateway Service', () => {
expect(response.status).toBe(500);
expect(response.body).toEqual({ error: errorMessage });
});

// Test /adduser endpoint
it('deberia añadir usuario correctamente', async () => {
const response = await request(app)
.post('/adduser')
.send({ username: 'newuser', password: 'newpassword' });

// Verificamos que la respuesta tenga un código de estado 200 y un ID de usuario
expect(response.statusCode).toBe(200);
expect(response.body.userId).toBe('mockedUserId');
});

// Probamos con una pregunta errónea
it('debería devolver error con esa pregunta', async () => {
Expand Down
141 changes: 141 additions & 0 deletions questionservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions questionservice/questionservice/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions questionservice/questionservice/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"questionservice": "file:.."
}
}
Loading