Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/main_endpoints/routes/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ router.post('/register', async (req, res) => {
const registrationStatus = await registerUser(req.body);
if (registrationStatus.userSaved) {
const name = req.body.firstName + ' ' + req.body.lastName;
const user = await User.findOne({email: req.body.email});

if (user) {
AuditLog.create({
userId: user._id,
action: AuditLogActions.SIGN_UP,
details: {email: req.body.email}
}).catch(logger.error);
}

sendVerificationEmail(name, req.body.email);
return res.sendStatus(OK);
}
Expand Down
23 changes: 23 additions & 0 deletions test/api/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ describe('Auth', () => {
await User.deleteOne({email: user.email});
}
});

it('Should create an audit log entry on successful signup', async () => {
const registerPayload = {
email: 'newuser@example.com',
password: 'Passw0rd123!',
firstName: 'Testfirst',
lastName: 'Testlast'
};

// ensure Audit log and User DB starts fresh before this test
await AuditLog.deleteMany({});
await User.deleteOne({email: registerPayload.email});

const res = await test.sendPostRequest('/api/Auth/register', registerPayload);
expect(res).to.have.status(OK);

const auditEntry = await AuditLog.findOne().lean();

expect(auditEntry).to.exist;
expect(auditEntry).to.have.property('userId');
expect(auditEntry.details).to.have.property('email', registerPayload.email);

});
});

describe('/POST login', () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thnk we can move the tests into the below section, we already have it for /POST login

describe('/POST login', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should already be resolved on most recent commit, [0020286]

Expand Down