diff --git a/api/src/routes/api/spec/user.spec.ts b/api/src/routes/api/spec/user.spec.ts index 64510a2..4e5e2bf 100644 --- a/api/src/routes/api/spec/user.spec.ts +++ b/api/src/routes/api/spec/user.spec.ts @@ -9,14 +9,14 @@ import { generateAccessToken, saveTokensInDB } from '../../../utils' const clientId = 'someclientID' const adminUser = { displayName: 'Test Admin', - username: 'testAdminUsername', + username: 'testadminusername', password: '12345678', isAdmin: true, isActive: true } const user = { displayName: 'Test User', - username: 'testUsername', + username: 'testusername', password: '87654321', isAdmin: false, isActive: true, @@ -68,6 +68,20 @@ describe('user', () => { expect(res.body.autoExec).toEqual(user.autoExec) }) + it('should respond with new user having username as lowercase', async () => { + const res = await request(app) + .post('/SASjsApi/user') + .auth(adminAccessToken, { type: 'bearer' }) + .send({ ...user, username: user.username.toUpperCase() }) + .expect(200) + + expect(res.body.username).toEqual(user.username) + expect(res.body.displayName).toEqual(user.displayName) + expect(res.body.isAdmin).toEqual(user.isAdmin) + expect(res.body.isActive).toEqual(user.isActive) + expect(res.body.autoExec).toEqual(user.autoExec) + }) + it('should respond with Unauthorized if access token is not present', async () => { const res = await request(app) .post('/SASjsApi/user') @@ -244,7 +258,7 @@ describe('user', () => { const dbUser1 = await controller.createUser(user) const dbUser2 = await controller.createUser({ ...user, - username: 'randomUser' + username: 'randomuser' }) const res = await request(app) diff --git a/api/src/routes/api/spec/web.spec.ts b/api/src/routes/api/spec/web.spec.ts index 12da618..4f8ec30 100644 --- a/api/src/routes/api/spec/web.spec.ts +++ b/api/src/routes/api/spec/web.spec.ts @@ -10,7 +10,7 @@ const clientSecret = 'someclientSecret' const user = { id: 1234, displayName: 'Test User', - username: 'testUsername', + username: 'testusername', password: '87654321', isAdmin: false, isActive: true @@ -77,6 +77,7 @@ describe('web', () => { expect(res.body.loggedIn).toBeTruthy() expect(res.body.user).toEqual({ + id: expect.any(Number), username: user.username, displayName: user.displayName }) @@ -155,7 +156,6 @@ const getCSRF = async (app: Express) => { const { header } = await request(app).get('/') const cookies = header['set-cookie'].join() - console.log('cookies', cookies) const csrfToken = extractCSRF(cookies) return { csrfToken, cookies } } diff --git a/api/src/utils/validation.ts b/api/src/utils/validation.ts index 73ce4e5..33a403f 100644 --- a/api/src/utils/validation.ts +++ b/api/src/utils/validation.ts @@ -1,6 +1,6 @@ import Joi from 'joi' -const usernameSchema = Joi.string().alphanum().min(3).max(16) +const usernameSchema = Joi.string().lowercase().alphanum().min(3).max(16) const passwordSchema = Joi.string().min(6).max(1024) export const blockFileRegex = /\.(exe|sh|htaccess)$/i diff --git a/web/src/components/header.tsx b/web/src/components/header.tsx index 7288d27..28e0d57 100644 --- a/web/src/components/header.tsx +++ b/web/src/components/header.tsx @@ -153,7 +153,7 @@ const Header = (props: any) => { color="primary" startIcon={} > - Setting + Settings diff --git a/web/src/containers/Settings/profile.tsx b/web/src/containers/Settings/profile.tsx index 7571250..14d8e09 100644 --- a/web/src/containers/Settings/profile.tsx +++ b/web/src/containers/Settings/profile.tsx @@ -14,9 +14,9 @@ import { FormControlLabel, Checkbox } from '@mui/material' +import { toast } from 'react-toastify' import { AppContext } from '../../context/appContext' -import { toast } from 'react-toastify' const Profile = () => { const [isLoading, setIsLoading] = useState(false) @@ -106,6 +106,19 @@ const Profile = () => { /> + + + + { /> - - - -