diff --git a/apis/allquestionservice/Dockerfile b/apis/allquestionservice/Dockerfile index 74b03e40..e6107956 100644 --- a/apis/allquestionservice/Dockerfile +++ b/apis/allquestionservice/Dockerfile @@ -11,7 +11,13 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY allquestions-api.js ./ +COPY allquestions-api.test.js ./ +COPY home.png ./ +COPY package-lock.json ./ +COPY package.json ./ +COPY question-model.js ./ # Expose the port the app runs on EXPOSE 8007 diff --git a/apis/allquestionservice/allquestions-api.js b/apis/allquestionservice/allquestions-api.js index f03ca55b..7266d04d 100644 --- a/apis/allquestionservice/allquestions-api.js +++ b/apis/allquestionservice/allquestions-api.js @@ -4,6 +4,7 @@ const Question = require('./question-model') const bodyParser = require('body-parser'); const app = express(); +app.disable('x-powered-by'); const port = 8007; const originEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000'; diff --git a/apis/alluserservice/Dockerfile b/apis/alluserservice/Dockerfile index 2b562cbc..c15252a4 100644 --- a/apis/alluserservice/Dockerfile +++ b/apis/alluserservice/Dockerfile @@ -11,7 +11,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY allusers-api.js ./ +COPY allusers-api.test.js ./ +COPY package-lock.json ./ +COPY package.json ./ +COPY user-model.js ./ # Expose the port the app runs on EXPOSE 8006 diff --git a/apis/alluserservice/allusers-api.js b/apis/alluserservice/allusers-api.js index 2d3e0938..82ee1eeb 100644 --- a/apis/alluserservice/allusers-api.js +++ b/apis/alluserservice/allusers-api.js @@ -4,6 +4,7 @@ const bodyParser = require('body-parser'); const User = require('./user-model') const app = express(); +app.disable('x-powered-by'); const port = 8006; const originEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000'; diff --git a/gamehistoryservice/Dockerfile b/gamehistoryservice/Dockerfile index 1fe06eb2..eb9cf75c 100644 --- a/gamehistoryservice/Dockerfile +++ b/gamehistoryservice/Dockerfile @@ -12,7 +12,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY gamehistory-model.js ./ +COPY gamehistory.js ./ +COPY gamehistory.test.js ./ +COPY package-lock.json ./ +COPY package.json ./ # Expose the port the app runs on EXPOSE 8004 diff --git a/gamehistoryservice/gamehistory.js b/gamehistoryservice/gamehistory.js index e537612e..496aedf8 100644 --- a/gamehistoryservice/gamehistory.js +++ b/gamehistoryservice/gamehistory.js @@ -9,6 +9,7 @@ mongoose.connect(mongoUri); const originEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000'; const app = express(); +app.disable('x-powered-by'); const port = 8004; // Middleware to parse JSON in request body diff --git a/gamehistoryservice/gamehistory.test.js b/gamehistoryservice/gamehistory.test.js index e2a3c516..037af61a 100644 --- a/gamehistoryservice/gamehistory.test.js +++ b/gamehistoryservice/gamehistory.test.js @@ -130,7 +130,6 @@ describe('Game History Service', () => { .get('/topUsers'); expect(response.status).toBe(200); - console.log(response.body); expect(response.body).toEqual({ primero: 'user1 - 90%', segundo: 'user2 - 85%', diff --git a/gatewayservice/Dockerfile b/gatewayservice/Dockerfile index 6c340432..932fadec 100644 --- a/gatewayservice/Dockerfile +++ b/gatewayservice/Dockerfile @@ -11,7 +11,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY gateway-service.js ./ +COPY gateway-service.test.js ./ +COPY openapi.yaml ./ +COPY package-lock.json ./ +COPY package.json ./ # Define the command to run your app CMD ["node", "gateway-service.js"] diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index c4700598..1c281fdb 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -8,6 +8,7 @@ const fs = require("fs") const YAML = require('yaml') const app = express(); +app.disable('x-powered-by'); const port = 8000; const gamehistoryUrl = process.env.GAMEHISTORY_SERVICE_URL || 'http://localhost:8004'; diff --git a/gatewayservice/gateway-service.test.js b/gatewayservice/gateway-service.test.js index eac6a6e3..7aaf7f02 100644 --- a/gatewayservice/gateway-service.test.js +++ b/gatewayservice/gateway-service.test.js @@ -3,10 +3,21 @@ const axios = require('axios'); const app = require('./gateway-service'); const { createServer } = require('http'); const sinon = require('sinon'); - +const { randomBytes } = require('crypto'); const server = createServer(app); -const newPassword = Math.floor(Math.random() * 10).toString(); // Genera una nueva contraseña aleatoria para evitar el Security Hostpot de SonarCloud en las pruebas +const newString = generateSecureRandomPassword(8); // Genera una nueva contraseña aleatoria para evitar el Security Hostpot de SonarCloud en las pruebas + +function generateSecureRandomPassword(length) { + const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+'; + const password = []; + const bytes = randomBytes(length); + for (let i = 0; i < length; i++) { + const randomIndex = bytes[i] % characters.length; + password.push(characters[randomIndex]); + } + return password.join(''); +} afterAll(async () => { app.close(); @@ -58,7 +69,7 @@ describe('Gateway Service', () => { it('should forward login request to auth service', async () => { const response = await request(app) .post('/login') - .send({ username: 'testuser', password: newPassword }); + .send({ username: 'testuser', password: newString }); expect(response.statusCode).toBe(200); expect(response.body.token).toBe('mockedToken'); @@ -73,7 +84,7 @@ describe('Gateway Service', () => { it('should forward add user request to user service', async () => { const response = await request(app) .post('/adduser') - .send({ username: 'newuser', email: 'newuser@email.com', password: newPassword }); + .send({ username: 'newuser', email: 'newuser@email.com', password: newString }); expect(response.statusCode).toBe(200); expect(response.body.userId).toBe('mockedUserId'); diff --git a/gatewayservice/package-lock.json b/gatewayservice/package-lock.json index 8660a783..acf15976 100644 --- a/gatewayservice/package-lock.json +++ b/gatewayservice/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "axios": "^1.6.5", "cors": "^2.8.5", + "crypto": "^1.0.1", "express": "^4.18.2", "express-openapi": "^12.1.3", "express-prom-bundle": "^7.0.0", @@ -1902,6 +1903,12 @@ "node": ">= 8" } }, + "node_modules/crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", + "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", diff --git a/gatewayservice/package.json b/gatewayservice/package.json index 5abb800a..070db4da 100644 --- a/gatewayservice/package.json +++ b/gatewayservice/package.json @@ -20,6 +20,7 @@ "dependencies": { "axios": "^1.6.5", "cors": "^2.8.5", + "crypto": "^1.0.1", "express": "^4.18.2", "express-openapi": "^12.1.3", "express-prom-bundle": "^7.0.0", @@ -28,7 +29,7 @@ }, "devDependencies": { "jest": "^29.7.0", - "supertest": "^6.3.4", - "sinon": "^11.0.0" + "sinon": "^11.0.0", + "supertest": "^6.3.4" } } diff --git a/perfilservice/Dockerfile b/perfilservice/Dockerfile index 889973d2..f99d2a52 100644 --- a/perfilservice/Dockerfile +++ b/perfilservice/Dockerfile @@ -11,7 +11,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY package-lock.json ./ +COPY package.json ./ +COPY perfil-api.js ./ +COPY perfil-api.test.js ./ +COPY user-model.js ./ # Expose the port the app runs on EXPOSE 8005 diff --git a/perfilservice/perfil-api.js b/perfilservice/perfil-api.js index 66226df3..8d5ecc8c 100644 --- a/perfilservice/perfil-api.js +++ b/perfilservice/perfil-api.js @@ -4,6 +4,7 @@ const User = require('./user-model') const bodyParser = require('body-parser'); const app = express(); +app.disable('x-powered-by'); const port = 8005; const originEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000'; diff --git a/questiongenerator/Dockerfile b/questiongenerator/Dockerfile index 79be9ed1..707e7740 100644 --- a/questiongenerator/Dockerfile +++ b/questiongenerator/Dockerfile @@ -11,7 +11,17 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY game-model.js ./ +COPY image-questions.js ./ +COPY image-questions.test.js ./ +COPY package-lock.json ./ +COPY package.json ./ +COPY question-model.js ./ +COPY question.js ./ +COPY question.test.js ./ +COPY text-questions.js ./ +COPY text-questions.test.js ./ COPY game-model.js /usr/src/gamehistoryservice diff --git a/questiongenerator/package-lock.json b/questiongenerator/package-lock.json index 015c0383..38e69fcb 100644 --- a/questiongenerator/package-lock.json +++ b/questiongenerator/package-lock.json @@ -12,11 +12,11 @@ "axios": "^0.21.1", "bcrypt": "^5.1.1", "body-parser": "^1.20.2", + "crypto": "^1.0.1", "express": "^4.18.2", "mongoose": "^8.0.4" }, "devDependencies": { - "axios-mock-adapter": "^1.22.0", "jest": "^29.7.0", "mongodb-memory-server": "^9.1.5", "sinon": "^11.0.0", @@ -1451,19 +1451,6 @@ "follow-redirects": "^1.14.0" } }, - "node_modules/axios-mock-adapter": { - "version": "1.22.0", - "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", - "integrity": "sha512-dmI0KbkyAhntUR05YY96qg2H6gg0XMl2+qTW0xmYg6Up+BFBAJYRLROMXRdDEL06/Wqwa0TJThAYvFtSFdRCZw==", - "dev": true, - "dependencies": { - "fast-deep-equal": "^3.1.3", - "is-buffer": "^2.0.5" - }, - "peerDependencies": { - "axios": ">= 0.17.0" - } - }, "node_modules/b4a": { "version": "1.6.4", "resolved": "https://registry.npmjs.org/b4a/-/b4a-1.6.4.tgz", @@ -2000,6 +1987,12 @@ "node": ">= 8" } }, + "node_modules/crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", + "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", @@ -2335,12 +2328,6 @@ "node": ">= 0.8" } }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true - }, "node_modules/fast-fifo": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/fast-fifo/-/fast-fifo-1.3.2.tgz", @@ -2869,29 +2856,6 @@ "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", "dev": true }, - "node_modules/is-buffer": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", - "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "engines": { - "node": ">=4" - } - }, "node_modules/is-core-module": { "version": "2.13.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", diff --git a/questiongenerator/package.json b/questiongenerator/package.json index 693480ae..9b4e6c07 100644 --- a/questiongenerator/package.json +++ b/questiongenerator/package.json @@ -18,16 +18,17 @@ }, "homepage": "https://github.com/arquisoft/wiq_es2c#readme", "dependencies": { + "axios": "^0.21.1", "bcrypt": "^5.1.1", "body-parser": "^1.20.2", + "crypto": "^1.0.1", "express": "^4.18.2", - "mongoose": "^8.0.4", - "axios": "^0.21.1" + "mongoose": "^8.0.4" }, "devDependencies": { "jest": "^29.7.0", "mongodb-memory-server": "^9.1.5", - "supertest": "^6.3.4", - "sinon": "^11.0.0" + "sinon": "^11.0.0", + "supertest": "^6.3.4" } } diff --git a/questiongenerator/question.js b/questiongenerator/question.js index 0d94c13c..4b2b7c5a 100644 --- a/questiongenerator/question.js +++ b/questiongenerator/question.js @@ -2,6 +2,7 @@ const axios = require('axios'); const express = require('express'); const mongoose = require('mongoose'); const bodyParser = require('body-parser'); +const crypto = require('crypto'); const Question = require('./question-model'); const Game = require('./game-model'); const { queries:textQueries } = require('./text_questions'); @@ -10,6 +11,7 @@ const { queries:imagesQueries } = require('./image_questions'); const generatorEndpoint = process.env.REACT_APP_API_ORIGIN_ENDPOINT || 'http://localhost:3000'; const app = express(); +app.disable('x-powered-by'); const port = 8003; var language = 'undefined'; @@ -164,10 +166,10 @@ function getAllValues() { async function generarPregunta() { - randomNumber = Math.floor(Math.random() * 2); + randomNumber = crypto.randomInt(0, 2); try { // Petición a la API de WikiData - randomNumber = Math.floor(Math.random() * queries.length); + randomNumber = crypto.randomInt(0, queries.length); var response = await axios.get(url, { params: { query: queries[randomNumber][0], @@ -197,7 +199,7 @@ function procesarDatos(data) { // Obtenemos cuatro índices aleatorios sin repetición while (randomIndexes.length < 4) { - var randomIndex = Math.floor(Math.random() * data.length); + var randomIndex = crypto.randomInt(0, data.length); var option = data[randomIndex].optionLabel.value; var quest = ""; @@ -218,7 +220,7 @@ function procesarDatos(data) { } // Escogemos un índice aleatorio como la opción correcta - var correctIndex = Math.floor(Math.random() * 4); + var correctIndex = crypto.randomInt(0, 4); correctOption = data[randomIndexes[correctIndex]].optionLabel.value; if(quest == "") { diff --git a/questiongenerator/question.test.js b/questiongenerator/question.test.js index ba2b8a84..a05efd7b 100644 --- a/questiongenerator/question.test.js +++ b/questiongenerator/question.test.js @@ -51,7 +51,7 @@ describe('Question Generator test', () => { }); it('Should manager errors when calling /generateQuestion', async () => { - await simulateError('get', '/generateQuestion', 'Error al obtener datos', { error: "Error al obtener datos TypeError: Cannot read properties of undefined (reading '0')" }); + await simulateError('get', '/generateQuestion', 'Error al obtener datos', { error: "Error al obtener datos RangeError [ERR_OUT_OF_RANGE]: The value of \"max\" is out of range. It must be greater than the value of \"min\" (0). Received 0" }); }); it('Should configure the game when calling /configureGame', async () => { diff --git a/questiongenerator/text_questions.js b/questiongenerator/text_questions.js index 680e252d..2fabe944 100644 --- a/questiongenerator/text_questions.js +++ b/questiongenerator/text_questions.js @@ -236,7 +236,7 @@ queries["en"] = { BIND(CONCAT(?day, "/", ?month, "/", ?year) AS ?option) SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } - `, "¿En que fecha se creó "], + `, "Where was created "], [ // pregunta = creador, opcion = lenguaje de programacion ` diff --git a/users/authservice/Dockerfile b/users/authservice/Dockerfile index 70648d70..f0e6a771 100644 --- a/users/authservice/Dockerfile +++ b/users/authservice/Dockerfile @@ -11,7 +11,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY auth-model.js ./ +COPY auth-service.js ./ +COPY auth-service.test.js ./ +COPY package-lock.json ./ +COPY package.json ./ # Expose the port the app runs on EXPOSE 8002 diff --git a/users/authservice/auth-service.js b/users/authservice/auth-service.js index 9764f088..6e2a6c5a 100644 --- a/users/authservice/auth-service.js +++ b/users/authservice/auth-service.js @@ -5,6 +5,7 @@ const jwt = require('jsonwebtoken'); const User = require('./auth-model') const app = express(); +app.disable('x-powered-by'); const port = 8002; // Middleware to parse JSON in request body diff --git a/users/authservice/auth-service.test.js b/users/authservice/auth-service.test.js index 50424792..b271cebd 100644 --- a/users/authservice/auth-service.test.js +++ b/users/authservice/auth-service.test.js @@ -2,11 +2,24 @@ const request = require('supertest'); const { MongoMemoryServer } = require('mongodb-memory-server'); const bcrypt = require('bcrypt'); const User = require('./auth-model'); +const { randomBytes } = require('crypto'); let mongoServer; let app; -const newPassword = Math.floor(Math.random() * 10).toString(); // Genera una nueva contraseña aleatoria para evitar el Security Hostpot de SonarCloud en las pruebas +const newPassword = generateSecureRandomPassword(8); // Genera una nueva contraseña aleatoria para evitar el Security Hostpot de SonarCloud en las pruebas + +function generateSecureRandomPassword(length) { + const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_=+'; + const password = []; + const bytes = randomBytes(length); + for (let i = 0; i < length; i++) { + const randomIndex = bytes[i] % characters.length; + password.push(characters[randomIndex]); + } + return password.join(''); +} + //test user const user = { diff --git a/users/authservice/package-lock.json b/users/authservice/package-lock.json index e0ceb0b8..4bb9add5 100644 --- a/users/authservice/package-lock.json +++ b/users/authservice/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "bcrypt": "^5.1.1", "body-parser": "^1.20.2", + "crypto": "^1.0.1", "express": "^4.18.2", "jsonwebtoken": "^9.0.2", "mongoose": "^8.0.4" @@ -1944,6 +1945,12 @@ "node": ">= 8" } }, + "node_modules/crypto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", + "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", + "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." + }, "node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", diff --git a/users/authservice/package.json b/users/authservice/package.json index 1891890e..d3e243a1 100644 --- a/users/authservice/package.json +++ b/users/authservice/package.json @@ -20,6 +20,7 @@ "dependencies": { "bcrypt": "^5.1.1", "body-parser": "^1.20.2", + "crypto": "^1.0.1", "express": "^4.18.2", "jsonwebtoken": "^9.0.2", "mongoose": "^8.0.4" diff --git a/users/userservice/Dockerfile b/users/userservice/Dockerfile index f43e2df7..2112b186 100644 --- a/users/userservice/Dockerfile +++ b/users/userservice/Dockerfile @@ -11,7 +11,12 @@ COPY package*.json ./ RUN npm install # Copy the app source code to the working directory -COPY . . +COPY .dockerignore ./ +COPY package-lock.json ./ +COPY package.json ./ +COPY user-model.js ./ +COPY user-service.js ./ +COPY user-service.test.js ./ # Expose the port the app runs on EXPOSE 8001 diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index 463030fa..512b539e 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -6,6 +6,7 @@ const bodyParser = require('body-parser'); const User = require('./user-model') const app = express(); +app.disable('x-powered-by'); const port = 8001; // Middleware to parse JSON in request body