-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Super Admin force set password (#1209)
- Loading branch information
1 parent
221a1fc
commit 6dbdb7f
Showing
5 changed files
with
162 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,22 @@ describe('SuperAdminPage', () => { | |
|
||
expect(screen.getByText('Done')).toBeInTheDocument(); | ||
}); | ||
|
||
test('Force set password', async () => { | ||
setup(); | ||
|
||
await act(async () => { | ||
fireEvent.change(screen.getByLabelText('Email *'), { target: { value: '[email protected]' } }); | ||
}); | ||
|
||
await act(async () => { | ||
fireEvent.change(screen.getByLabelText('Password *'), { target: { value: 'override123' } }); | ||
}); | ||
|
||
await act(async () => { | ||
fireEvent.click(screen.getByRole('button', { name: 'Force Set Password' })); | ||
}); | ||
|
||
expect(screen.getByText('Done')).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { randomUUID } from 'crypto'; | |
import express from 'express'; | ||
import request from 'supertest'; | ||
import { initApp, shutdownApp } from '../app'; | ||
import { registerNew } from '../auth/register'; | ||
import { loadTestConfig } from '../config'; | ||
import { systemRepo } from '../fhir/repo'; | ||
import { generateAccessToken } from '../oauth/keys'; | ||
|
@@ -199,4 +200,68 @@ describe('Super Admin routes', () => { | |
|
||
expect(res.status).toBe(400); | ||
}); | ||
|
||
test('Set password access denied', async () => { | ||
const res = await request(app) | ||
.post('/admin/super/setpassword') | ||
.set('Authorization', 'Bearer ' + nonAdminAccessToken) | ||
.type('json') | ||
.send({ | ||
email: '[email protected]', | ||
password: 'password123', | ||
}); | ||
|
||
expect(res.status).toBe(403); | ||
}); | ||
|
||
test('Set password missing password', async () => { | ||
const res = await request(app) | ||
.post('/admin/super/setpassword') | ||
.set('Authorization', 'Bearer ' + adminAccessToken) | ||
.type('json') | ||
.send({ | ||
email: '[email protected]', | ||
password: '', | ||
}); | ||
|
||
expect(res.status).toBe(400); | ||
expect(res.body.issue[0].details.text).toBe('Invalid password, must be at least 8 characters'); | ||
}); | ||
|
||
test('Set password user not found', async () => { | ||
const res = await request(app) | ||
.post('/admin/super/setpassword') | ||
.set('Authorization', 'Bearer ' + adminAccessToken) | ||
.type('json') | ||
.send({ | ||
email: '[email protected]', | ||
password: 'password123', | ||
}); | ||
|
||
expect(res.status).toBe(400); | ||
expect(res.body.issue[0].details.text).toBe('User not found'); | ||
}); | ||
|
||
test('Set password success', async () => { | ||
const email = `alice${randomUUID()}@example.com`; | ||
|
||
await registerNew({ | ||
firstName: 'Alice', | ||
lastName: 'Smith', | ||
projectName: 'Alice Project', | ||
email, | ||
password: 'password!@#', | ||
}); | ||
|
||
const res = await request(app) | ||
.post('/admin/super/setpassword') | ||
.set('Authorization', 'Bearer ' + adminAccessToken) | ||
.type('json') | ||
.send({ | ||
email, | ||
password: 'new-password!@#', | ||
}); | ||
|
||
expect(res.status).toBe(200); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6dbdb7f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
medplum-storybook – ./
medplum-storybook-medplum.vercel.app
medplum-storybook-git-main-medplum.vercel.app
storybook.medplum.com