From c2fc32e993ad6b6357a29a1b7b650076a7427c48 Mon Sep 17 00:00:00 2001 From: Liliana Date: Sun, 28 Apr 2024 18:50:00 +0200 Subject: [PATCH] fixed security hotspots and some issues --- webapp/src/components/FirstGame.test.js | 2 +- webapp/src/components/Util.test.js | 12 ++++++------ webapp/src/components/game/Calculator.js | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/webapp/src/components/FirstGame.test.js b/webapp/src/components/FirstGame.test.js index 0c82e188..135a2484 100644 --- a/webapp/src/components/FirstGame.test.js +++ b/webapp/src/components/FirstGame.test.js @@ -2,7 +2,7 @@ import { render, screen, fireEvent } from '@testing-library/react'; import { ContextFun } from './Context'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; -import { BrowserRouter as Router, useLocation } from 'react-router-dom'; +import { BrowserRouter as Router } from 'react-router-dom'; import FirstGame from './FirstGame'; import GameConfiguration from './game/GameConfiguration'; diff --git a/webapp/src/components/Util.test.js b/webapp/src/components/Util.test.js index 3f008217..da830684 100644 --- a/webapp/src/components/Util.test.js +++ b/webapp/src/components/Util.test.js @@ -1,17 +1,17 @@ import { shuffleArray, secureRandomNumber } from './Util'; -import axios from 'axios'; jest.mock('axios'); describe('shuffleArray function', () => { // Mocking window.crypto.getRandomValues beforeEach(() => { + const max = 100; global.crypto = { - getRandomValues: jest.fn().mockImplementation((array) => { - for (let i = 0; i < array.length; i++) { - array[i] = Math.floor(Math.random() * 100); // Mocking random values - } - }), + getRandomValues: jest.fn().mockImplementation((array) => { + for (let i = 0; i < array.length; i++) { + array[i] = i; + } + }), }; }); diff --git a/webapp/src/components/game/Calculator.js b/webapp/src/components/game/Calculator.js index f37cbbd2..4d54c5d4 100644 --- a/webapp/src/components/game/Calculator.js +++ b/webapp/src/components/game/Calculator.js @@ -1,12 +1,12 @@ -import React, { useState, useEffect } from 'react'; +import React from 'react'; import { shuffleArray, secureRandomNumber } from '../Util'; -import { Container, Typography, Box, LinearProgress} from '@mui/material'; +import { Container, Typography } from '@mui/material'; import { Footer } from '../footer/Footer'; import { Nav } from '../nav/Nav'; import Button from '../Button'; -var questions = [] -var questionIndex = -1 +let questions = [] +let questionIndex = -1 const Calculator = () => {