From f0add13351b9e0e5e550e06f1e05230bc5d2a73d Mon Sep 17 00:00:00 2001 From: Knightplayzz <73634415+Knightplayzz@users.noreply.github.com> Date: Thu, 13 Jun 2024 21:30:06 +0200 Subject: [PATCH] security update --- test/auth/login.test.js | 10 +++++----- test/brawlers/brawlers.test.js | 6 +++--- test/brawlers/getBrawler.test.js | 6 +++--- test/clubs/getClub.test.js | 6 +++--- test/events/getEvents.test.js | 6 +++--- test/players/getBattlelog.test.js | 6 +++--- test/players/getPlayer.test.js | 6 +++--- test/rankings/getRankingsBrawler.test.js | 6 +++--- test/rankings/getRankingsClubs.test.js | 6 +++--- test/rankings/getRankingsPlayers.test.js | 6 +++--- test/rankings/getRankingsPowerplay..test.js | 6 +++--- test/rankings/getRankingsPowerplaySeasons.test.js | 6 +++--- 12 files changed, 38 insertions(+), 38 deletions(-) diff --git a/test/auth/login.test.js b/test/auth/login.test.js index 4969641..db9b4b8 100644 --- a/test/auth/login.test.js +++ b/test/auth/login.test.js @@ -19,20 +19,20 @@ describe('login function', () => { test('should throw an error if fetch response is not ok', async () => { fetch.mockResolvedValue(new Response(null, { status: 401 })); - context.getAuthToken.mockReturnValue('invalid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); - await expect(login('valid-token')).rejects.toThrow('Authentication token is wrong.'); + await expect(login('SampleToken')).rejects.toThrow('Authentication token is wrong.'); }); test('should set auth token and log in successfully if fetch response is ok', async () => { fetch.mockResolvedValue(new Response(null, { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); console.log = jest.fn(); // Mock console.log - await login('valid-token'); + await login('SampleToken'); - expect(context.setAuthToken).toHaveBeenCalledWith('valid-token'); + expect(context.setAuthToken).toHaveBeenCalledWith('SampleToken'); expect(console.log).toHaveBeenCalledWith('You succesfully logged in.'); }); }); diff --git a/test/brawlers/brawlers.test.js b/test/brawlers/brawlers.test.js index 303b87a..0d462da 100644 --- a/test/brawlers/brawlers.test.js +++ b/test/brawlers/brawlers.test.js @@ -15,19 +15,19 @@ describe('brawlers function', () => { test('should fetch brawlers information successfully', async () => { const mockResponse = { items: [{ name: 'Shelly' }, { name: 'Colt' }] }; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await brawlers(); expect(fetch).toHaveBeenCalledWith('https://api.brawlstars.com/v1/brawlers', { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); test('should handle fetch error', async () => { fetch.mockResolvedValue(new Response(null, { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); await expect(brawlers()).rejects.toThrow(); }); diff --git a/test/brawlers/getBrawler.test.js b/test/brawlers/getBrawler.test.js index 8ccdc99..fe96917 100644 --- a/test/brawlers/getBrawler.test.js +++ b/test/brawlers/getBrawler.test.js @@ -25,12 +25,12 @@ describe('getBrawler function', () => { const brawlerId = '123'; const mockResponse = { id: '123', name: 'Shelly' }; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getBrawler(brawlerId); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/brawlers/${encodeURIComponent(brawlerId)}`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -38,7 +38,7 @@ describe('getBrawler function', () => { test('should handle fetch error', async () => { const brawlerId = '123'; fetch.mockRejectedValue(new Error('Failed to fetch')); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); await expect(getBrawler(brawlerId)).rejects.toThrow(); }); diff --git a/test/clubs/getClub.test.js b/test/clubs/getClub.test.js index 2da4e21..47b5785 100644 --- a/test/clubs/getClub.test.js +++ b/test/clubs/getClub.test.js @@ -33,13 +33,13 @@ describe('getClub function', () => { test('should fetch club information successfully', async () => { const mockResponse = { id: '123', name: 'Awesome Club' }; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const clubTag = '#ABC123'; const data = await getClub(clubTag); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/clubs/${encodeURIComponent(clubTag)}`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -47,7 +47,7 @@ describe('getClub function', () => { test('should handle fetch error and return error response', async () => { const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const clubTag = '#ABC123'; const result = await getClub(clubTag); diff --git a/test/events/getEvents.test.js b/test/events/getEvents.test.js index 6918c46..6d8ac57 100644 --- a/test/events/getEvents.test.js +++ b/test/events/getEvents.test.js @@ -15,12 +15,12 @@ describe('getEvents function', () => { test('should fetch events successfully', async () => { const mockResponse = [{ id: '1', name: 'Event 1' }, { id: '2', name: 'Event 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getEvents(); expect(fetch).toHaveBeenCalledWith('https://api.brawlstars.com/v1/events/rotation', { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -28,7 +28,7 @@ describe('getEvents function', () => { test('should handle fetch error and return error response', async () => { const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const result = await getEvents(); diff --git a/test/players/getBattlelog.test.js b/test/players/getBattlelog.test.js index 98a51a4..4584b43 100644 --- a/test/players/getBattlelog.test.js +++ b/test/players/getBattlelog.test.js @@ -33,13 +33,13 @@ describe('getBattlelog function', () => { test('should fetch battle log successfully', async () => { const mockResponse = [{ battleId: '1', result: 'victory' }, { battleId: '2', result: 'defeat' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const playerTag = '#ABC123'; const data = await getBattlelog(playerTag); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/players/${encodeURIComponent(playerTag)}/battlelog`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -47,7 +47,7 @@ describe('getBattlelog function', () => { test('should handle fetch error and return error response', async () => { const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const playerTag = '#ABC123'; const result = await getBattlelog(playerTag); diff --git a/test/players/getPlayer.test.js b/test/players/getPlayer.test.js index e1d50f1..2764a7d 100644 --- a/test/players/getPlayer.test.js +++ b/test/players/getPlayer.test.js @@ -33,13 +33,13 @@ describe('getPlayer function', () => { test('should fetch player information successfully', async () => { const mockResponse = { playerId: '123', name: 'PlayerName' }; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const playerTag = '#ABC123'; const data = await getPlayer(playerTag); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/players/${encodeURIComponent(playerTag)}`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -47,7 +47,7 @@ describe('getPlayer function', () => { test('should handle fetch error and return error response', async () => { const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const playerTag = '#ABC123'; const result = await getPlayer(playerTag); diff --git a/test/rankings/getRankingsBrawler.test.js b/test/rankings/getRankingsBrawler.test.js index 469bcae..6af9238 100644 --- a/test/rankings/getRankingsBrawler.test.js +++ b/test/rankings/getRankingsBrawler.test.js @@ -39,12 +39,12 @@ describe('getRankingsBrawlers function', () => { const brawlerId = '123'; const mockResponse = [{ playerId: '1', name: 'Player 1' }, { playerId: '2', name: 'Player 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getRankingsBrawlers(countryCode, brawlerId); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/brawlers/${encodeURIComponent(brawlerId)}`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -54,7 +54,7 @@ describe('getRankingsBrawlers function', () => { const brawlerId = '123'; const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const result = await getRankingsBrawlers(countryCode, brawlerId); diff --git a/test/rankings/getRankingsClubs.test.js b/test/rankings/getRankingsClubs.test.js index fe01957..8f05ab3 100644 --- a/test/rankings/getRankingsClubs.test.js +++ b/test/rankings/getRankingsClubs.test.js @@ -25,12 +25,12 @@ describe('getRankingsClubs function', () => { const countryCode = 'US'; const mockResponse = [{ clubId: '1', name: 'Club 1' }, { clubId: '2', name: 'Club 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getRankingsClubs(countryCode); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/clubs`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -39,7 +39,7 @@ describe('getRankingsClubs function', () => { const countryCode = 'US'; const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const result = await getRankingsClubs(countryCode); diff --git a/test/rankings/getRankingsPlayers.test.js b/test/rankings/getRankingsPlayers.test.js index a1dc52a..5f9cb0e 100644 --- a/test/rankings/getRankingsPlayers.test.js +++ b/test/rankings/getRankingsPlayers.test.js @@ -25,12 +25,12 @@ describe('getRankingsPlayers function', () => { const countryCode = 'US'; const mockResponse = [{ playerId: '1', name: 'Player 1' }, { playerId: '2', name: 'Player 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getRankingsPlayers(countryCode); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/players`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -39,7 +39,7 @@ describe('getRankingsPlayers function', () => { const countryCode = 'US'; const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const result = await getRankingsPlayers(countryCode); diff --git a/test/rankings/getRankingsPowerplay..test.js b/test/rankings/getRankingsPowerplay..test.js index 1c8ef9b..879c4d8 100644 --- a/test/rankings/getRankingsPowerplay..test.js +++ b/test/rankings/getRankingsPowerplay..test.js @@ -39,12 +39,12 @@ describe('getRankingsPowerplay function', () => { const seasonId = '2023'; const mockResponse = [{ playerId: '1', name: 'Player 1' }, { playerId: '2', name: 'Player 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const data = await getRankingsPowerplay(countryCode, seasonId); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/players`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -54,7 +54,7 @@ describe('getRankingsPowerplay function', () => { const seasonId = '2023'; const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const result = await getRankingsPowerplay(countryCode, seasonId); diff --git a/test/rankings/getRankingsPowerplaySeasons.test.js b/test/rankings/getRankingsPowerplaySeasons.test.js index d3cca65..708b43d 100644 --- a/test/rankings/getRankingsPowerplaySeasons.test.js +++ b/test/rankings/getRankingsPowerplaySeasons.test.js @@ -24,13 +24,13 @@ describe('getRankingsPowerplaySeasons function', () => { test('should fetch powerplay seasons successfully', async () => { const mockResponse = [{ seasonId: '1', name: 'Season 1' }, { seasonId: '2', name: 'Season 2' }]; fetch.mockResolvedValue(new Response(JSON.stringify(mockResponse), { status: 200 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const countryCode = 'US'; const data = await getRankingsPowerplaySeasons(countryCode); expect(fetch).toHaveBeenCalledWith(`https://api.brawlstars.com/v1/rankings/${encodeURIComponent(countryCode)}/powerplay/seasons`, { - headers: { 'Authorization': 'Bearer valid-token' }, + headers: { 'Authorization': 'Bearer SampleToken' }, }); expect(data).toEqual(mockResponse); }); @@ -38,7 +38,7 @@ describe('getRankingsPowerplaySeasons function', () => { test('should handle fetch error and return error response', async () => { const errorResponse = { reason: 'error', message: 'Server error' }; fetch.mockResolvedValue(new Response(JSON.stringify(errorResponse), { status: 500 })); - context.getAuthToken.mockReturnValue('valid-token'); + context.getAuthToken.mockReturnValue('SampleToken'); const countryCode = 'US'; const result = await getRankingsPowerplaySeasons(countryCode);