test: fix test and use stronger passwords

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2022-09-25 02:05:30 +02:00 committed by David Mehren
parent 6a56ce5541
commit 3ba9f95f83
10 changed files with 68 additions and 38 deletions

View file

@ -35,6 +35,7 @@ describe('FrontendConfigService', () => {
local: { local: {
enableLogin: false, enableLogin: false,
enableRegister: false, enableRegister: false,
minimalPasswordStrength: 2,
}, },
facebook: { facebook: {
clientID: undefined, clientID: undefined,
@ -339,6 +340,7 @@ describe('FrontendConfigService', () => {
local: { local: {
enableLogin: true, enableLogin: true,
enableRegister, enableRegister,
minimalPasswordStrength: 3,
}, },
}; };
const customizationConfig: CustomizationConfig = { const customizationConfig: CustomizationConfig = {

View file

@ -8,7 +8,14 @@ import request from 'supertest';
import { AliasCreateDto } from '../../src/notes/alias-create.dto'; import { AliasCreateDto } from '../../src/notes/alias-create.dto';
import { AliasUpdateDto } from '../../src/notes/alias-update.dto'; import { AliasUpdateDto } from '../../src/notes/alias-update.dto';
import { User } from '../../src/users/user.entity'; import { User } from '../../src/users/user.entity';
import { TestSetup, TestSetupBuilder } from '../test-setup'; import {
password1,
password2,
TestSetup,
TestSetupBuilder,
username1,
username2,
} from '../test-setup';
describe('Alias', () => { describe('Alias', () => {
let testSetup: TestSetup; let testSetup: TestSetup;
@ -31,13 +38,13 @@ describe('Alias', () => {
agent1 = request.agent(testSetup.app.getHttpServer()); agent1 = request.agent(testSetup.app.getHttpServer());
await agent1 await agent1
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'testuser1', password: 'testuser1' }) .send({ username: username1, password: password1 })
.expect(201); .expect(201);
agent2 = request.agent(testSetup.app.getHttpServer()); agent2 = request.agent(testSetup.app.getHttpServer());
await agent2 await agent2
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'testuser2', password: 'testuser2' }) .send({ username: username2, password: password2 })
.expect(201); .expect(201);
}); });

View file

@ -6,7 +6,12 @@
import request from 'supertest'; import request from 'supertest';
import { LoginDto } from '../../src/identity/local/login.dto'; import { LoginDto } from '../../src/identity/local/login.dto';
import { TestSetup, TestSetupBuilder } from '../test-setup'; import {
password1,
TestSetup,
TestSetupBuilder,
username1,
} from '../test-setup';
describe('Groups', () => { describe('Groups', () => {
let testSetup: TestSetup; let testSetup: TestSetup;
@ -21,8 +26,8 @@ describe('Groups', () => {
// log in to create a session // log in to create a session
const loginDto: LoginDto = { const loginDto: LoginDto = {
password: 'testuser1', password: password1,
username: 'testuser1', username: username1,
}; };
testuser1Session = request.agent(testSetup.app.getHttpServer()); testuser1Session = request.agent(testSetup.app.getHttpServer());
await testuser1Session await testuser1Session

View file

@ -33,21 +33,23 @@ describe('History', () => {
testSetup.configService.get('noteConfig').forbiddenNoteIds[0]; testSetup.configService.get('noteConfig').forbiddenNoteIds[0];
const moduleRef = testSetup.moduleRef; const moduleRef = testSetup.moduleRef;
const username = 'hardcoded';
const password = 'AHardcodedStrongP@ssword123';
await testSetup.app.init(); await testSetup.app.init();
content = 'This is a test note.'; content = 'This is a test note.';
historyService = moduleRef.get(HistoryService); historyService = moduleRef.get(HistoryService);
const userService = moduleRef.get(UsersService); const userService = moduleRef.get(UsersService);
identityService = moduleRef.get(IdentityService); identityService = moduleRef.get(IdentityService);
user = await userService.createUser('hardcoded', 'Testy'); user = await userService.createUser(username, 'Testy');
await identityService.createLocalIdentity(user, 'test'); await identityService.createLocalIdentity(user, password);
const notesService = moduleRef.get(NotesService); const notesService = moduleRef.get(NotesService);
note = await notesService.createNote(content, user, 'note'); note = await notesService.createNote(content, user, 'note');
note2 = await notesService.createNote(content, user, 'note2'); note2 = await notesService.createNote(content, user, 'note2');
agent = request.agent(testSetup.app.getHttpServer()); agent = request.agent(testSetup.app.getHttpServer());
await agent await agent
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'hardcoded', password: 'test' }) .send({ username: username, password: password })
.expect(201); .expect(201);
}); });

View file

@ -28,11 +28,12 @@ describe('Me', () => {
uploadPath = uploadPath =
testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath; testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath;
const username = 'hardcoded';
const password = 'AHardcodedStrongP@ssword123';
await testSetup.app.init(); await testSetup.app.init();
user = await testSetup.userService.createUser('hardcoded', 'Testy'); user = await testSetup.userService.createUser(username, 'Testy');
await testSetup.identityService.createLocalIdentity(user, 'test'); await testSetup.identityService.createLocalIdentity(user, password);
content = 'This is a test note.'; content = 'This is a test note.';
alias2 = 'note2'; alias2 = 'note2';
@ -41,7 +42,7 @@ describe('Me', () => {
agent = request.agent(testSetup.app.getHttpServer()); agent = request.agent(testSetup.app.getHttpServer());
await agent await agent
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'hardcoded', password: 'test' }) .send({ username: username, password: password })
.expect(201); .expect(201);
}); });

View file

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
@ -20,6 +20,8 @@ describe('Media', () => {
let user: User; let user: User;
beforeAll(async () => { beforeAll(async () => {
const username = 'hardcoded';
const password = 'AHardcodedStrongP@ssword123';
testSetup = await TestSetupBuilder.create().build(); testSetup = await TestSetupBuilder.create().build();
uploadPath = uploadPath =
@ -39,13 +41,13 @@ describe('Media', () => {
null, null,
'test_upload_media', 'test_upload_media',
); );
user = await testSetup.userService.createUser('hardcoded', 'Testy'); user = await testSetup.userService.createUser(username, 'Testy');
await testSetup.identityService.createLocalIdentity(user, 'test'); await testSetup.identityService.createLocalIdentity(user, password);
agent = request.agent(testSetup.app.getHttpServer()); agent = request.agent(testSetup.app.getHttpServer());
await agent await agent
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'hardcoded', password: 'test' }) .send({ username: username, password: password })
.expect(201); .expect(201);
}); });

View file

@ -31,21 +31,22 @@ describe('Notes', () => {
testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath; testSetup.configService.get('mediaConfig').backend.filesystem.uploadPath;
await testSetup.app.init(); await testSetup.app.init();
const username1 = 'hardcoded';
const password1 = 'AHardcodedStrongP@ssword123';
const username2 = 'hardcoded2';
const password2 = 'AHardcodedStrongP@ssword12';
user = await testSetup.userService.createUser('hardcoded', 'Testy'); user = await testSetup.userService.createUser(username1, 'Testy');
await testSetup.identityService.createLocalIdentity(user, 'test'); await testSetup.identityService.createLocalIdentity(user, password1);
user2 = await testSetup.userService.createUser( user2 = await testSetup.userService.createUser(username2, 'Max Mustermann');
'hardcoded2', await testSetup.identityService.createLocalIdentity(user2, password2);
'Max Mustermann',
);
await testSetup.identityService.createLocalIdentity(user2, 'test');
content = 'This is a test note.'; content = 'This is a test note.';
testImage = await fs.readFile('test/public-api/fixtures/test.png'); testImage = await fs.readFile('test/public-api/fixtures/test.png');
agent = request.agent(testSetup.app.getHttpServer()); agent = request.agent(testSetup.app.getHttpServer());
await agent await agent
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'hardcoded', password: 'test' }) .send({ username: username1, password: password1 })
.expect(201); .expect(201);
}); });

View file

@ -14,7 +14,7 @@ describe('Register and Login', () => {
const USERNAME = 'testuser'; const USERNAME = 'testuser';
const DISPLAYNAME = 'A Test User'; const DISPLAYNAME = 'A Test User';
const PASSWORD = 'secure'; const PASSWORD = 'AVerySecurePassword';
beforeEach(async () => { beforeEach(async () => {
testSetup = await TestSetupBuilder.create().build(); testSetup = await TestSetupBuilder.create().build();
@ -103,6 +103,7 @@ describe('Register and Login', () => {
password: PASSWORD, password: PASSWORD,
username: USERNAME, username: USERNAME,
}; };
const newPassword = 'ASecureNewPassword';
let session = request.agent(testSetup.app.getHttpServer()); let session = request.agent(testSetup.app.getHttpServer());
await session await session
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
@ -117,7 +118,7 @@ describe('Register and Login', () => {
.send( .send(
JSON.stringify({ JSON.stringify({
currentPassword: PASSWORD, currentPassword: PASSWORD,
newPassword: 'newPassword', newPassword: newPassword,
}), }),
) )
.expect(200); .expect(200);
@ -129,7 +130,7 @@ describe('Register and Login', () => {
await session.get('/api/private/me').expect(401); await session.get('/api/private/me').expect(401);
// login with new password // login with new password
loginDto.password = 'newPassword'; loginDto.password = newPassword;
await session await session
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.set('Content-Type', 'application/json') .set('Content-Type', 'application/json')

View file

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file) * SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
* *
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
@ -17,15 +17,17 @@ describe('Tokens', () => {
beforeAll(async () => { beforeAll(async () => {
testSetup = await TestSetupBuilder.create().build(); testSetup = await TestSetupBuilder.create().build();
const username = 'hardcoded';
const password = 'AHardcodedStrongP@ssword123';
user = await testSetup.userService.createUser('hardcoded', 'Testy'); user = await testSetup.userService.createUser(username, 'Testy');
await testSetup.identityService.createLocalIdentity(user, 'test'); await testSetup.identityService.createLocalIdentity(user, password);
await testSetup.app.init(); await testSetup.app.init();
agent = request.agent(testSetup.app.getHttpServer()); agent = request.agent(testSetup.app.getHttpServer());
await agent await agent
.post('/api/private/auth/local/login') .post('/api/private/auth/local/login')
.send({ username: 'hardcoded', password: 'test' }) .send({ username: username, password: password })
.expect(201); .expect(201);
}); });

View file

@ -320,27 +320,27 @@ export class TestSetupBuilder {
this.setupPostCompile.push(async () => { this.setupPostCompile.push(async () => {
// Create users // Create users
this.testSetup.users.push( this.testSetup.users.push(
await this.testSetup.userService.createUser('testuser1', 'Test User 1'), await this.testSetup.userService.createUser(username1, 'Test User 1'),
); );
this.testSetup.users.push( this.testSetup.users.push(
await this.testSetup.userService.createUser('testuser2', 'Test User 2'), await this.testSetup.userService.createUser(username2, 'Test User 2'),
); );
this.testSetup.users.push( this.testSetup.users.push(
await this.testSetup.userService.createUser('testuser3', 'Test User 3'), await this.testSetup.userService.createUser(username3, 'Test User 3'),
); );
// Create identities for login // Create identities for login
await this.testSetup.identityService.createLocalIdentity( await this.testSetup.identityService.createLocalIdentity(
this.testSetup.users[0], this.testSetup.users[0],
'testuser1', password1,
); );
await this.testSetup.identityService.createLocalIdentity( await this.testSetup.identityService.createLocalIdentity(
this.testSetup.users[1], this.testSetup.users[1],
'testuser2', password2,
); );
await this.testSetup.identityService.createLocalIdentity( await this.testSetup.identityService.createLocalIdentity(
this.testSetup.users[2], this.testSetup.users[2],
'testuser3', password3,
); );
// create auth tokens // create auth tokens
@ -410,3 +410,10 @@ export class TestSetupBuilder {
return this; return this;
} }
} }
export const username1 = 'testuser1';
export const password1 = 'AStrongP@sswordForUser1';
export const username2 = 'testuser2';
export const password2 = 'AStrongP@sswordForUser2';
export const username3 = 'testuser3';
export const password3 = 'AStrongP@sswordForUser3';