From a55248774cc214e07ba4ff4b6c0825c2b9d210e3 Mon Sep 17 00:00:00 2001 From: Raul-Cristian Kele Date: Fri, 16 Jun 2023 13:07:47 +0300 Subject: [PATCH] fix: login bug when both anonymous and auth is enabled Signed-off-by: Raul-Cristian Kele --- src/components/Login/SignIn.jsx | 17 +++++++++-------- tests/tag.spec.js | 3 --- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/components/Login/SignIn.jsx b/src/components/Login/SignIn.jsx index 014de65a..027f810e 100644 --- a/src/components/Login/SignIn.jsx +++ b/src/components/Login/SignIn.jsx @@ -4,7 +4,7 @@ import { useNavigate } from 'react-router-dom'; import { host } from '../../host'; // utility import { api, endpoints } from '../../api'; -import { isEmpty } from 'lodash'; +import { isEmpty, isNil } from 'lodash'; // components import Button from '@mui/material/Button'; @@ -142,17 +142,18 @@ export default function SignIn({ isLoggedIn, setIsLoggedIn, wrapperSetLoading = event.preventDefault(); setRequestProcessing(true); let cfg = {}; - const token = btoa(username + ':' + password); - cfg = { - headers: { - Authorization: `Basic ${token}` - } - }; + let token = !isNil(username) && !isNil(password) ? btoa(username + ':' + password) : '-'; + if (token !== '-') { + cfg = { + headers: { + Authorization: `Basic ${token}` + } + }; + } api .get(`${host()}/v2/`, abortController.signal, cfg) .then((response) => { if (response.status === 200) { - const token = btoa(username + ':' + password); localStorage.setItem('token', token); setRequestProcessing(false); setRequestError(false); diff --git a/tests/tag.spec.js b/tests/tag.spec.js index ccea0448..a5cbc3b8 100644 --- a/tests/tag.spec.js +++ b/tests/tag.spec.js @@ -1,7 +1,6 @@ import { test, expect } from '@playwright/test'; import { getTagWithDependencies, getTagWithDependents, getTagWithVulnerabilities } from './utils/test-data-parser'; import { hosts, pageSizes } from './values/test-constants'; -import { scroll } from './utils/scroll'; test.describe('Tag page test', () => { test.beforeEach(async ({ page }) => { @@ -39,7 +38,5 @@ test.describe('Tag page test', () => { await expect(page.getByTestId('vulnerability-container').locator('div').nth(1)).toBeVisible({ timeout: 100000 }); await expect(await page.getByText('CVE-').count()).toBeGreaterThan(1); await expect(await page.getByText('CVE-').count()).toBeLessThanOrEqual(pageSizes.EXPLORE); - await page.evaluate(scroll, { direction: 'down', speed: 'fast' }); - await expect(await page.getByText('CVE-').count()).toBeGreaterThanOrEqual(pageSizes.EXPLORE); }); });