mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 17:56:30 -05:00
test(e2e/public/alias): use real authentication
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
28bd07597a
commit
64b136fb8b
1 changed files with 34 additions and 10 deletions
|
@ -13,20 +13,15 @@ import { TestSetup } from '../test-setup';
|
||||||
describe('Alias', () => {
|
describe('Alias', () => {
|
||||||
let testSetup: TestSetup;
|
let testSetup: TestSetup;
|
||||||
|
|
||||||
let user: User;
|
const content = 'This is a test note.';
|
||||||
let content: string;
|
|
||||||
let forbiddenNoteId: string;
|
let forbiddenNoteId: string;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
testSetup = await TestSetup.create();
|
testSetup = await (await TestSetup.create(false)).withUsers();
|
||||||
|
|
||||||
forbiddenNoteId =
|
forbiddenNoteId =
|
||||||
testSetup.configService.get('appConfig').forbiddenNoteIds[0];
|
testSetup.configService.get('appConfig').forbiddenNoteIds[0];
|
||||||
|
|
||||||
await testSetup.app.init();
|
await testSetup.app.init();
|
||||||
|
|
||||||
user = await testSetup.userService.createUser('hardcoded', 'Testy');
|
|
||||||
content = 'This is a test note.';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('POST /alias', () => {
|
describe('POST /alias', () => {
|
||||||
|
@ -39,7 +34,7 @@ describe('Alias', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const note = await testSetup.notesService.createNote(
|
const note = await testSetup.notesService.createNote(
|
||||||
content,
|
content,
|
||||||
user,
|
testSetup.users[0],
|
||||||
testAlias,
|
testAlias,
|
||||||
);
|
);
|
||||||
publicId = note.publicId;
|
publicId = note.publicId;
|
||||||
|
@ -48,17 +43,23 @@ describe('Alias', () => {
|
||||||
it('create with normal alias', async () => {
|
it('create with normal alias', async () => {
|
||||||
const newAlias = 'normalAlias';
|
const newAlias = 'normalAlias';
|
||||||
newAliasDto.newAlias = newAlias;
|
newAliasDto.newAlias = newAlias;
|
||||||
|
|
||||||
const metadata = await request(testSetup.app.getHttpServer())
|
const metadata = await request(testSetup.app.getHttpServer())
|
||||||
.post(`/api/v2/alias`)
|
.post(`/api/v2/alias`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(newAliasDto)
|
.send(newAliasDto)
|
||||||
.expect(201);
|
.expect(201);
|
||||||
|
|
||||||
expect(metadata.body.name).toEqual(newAlias);
|
expect(metadata.body.name).toEqual(newAlias);
|
||||||
expect(metadata.body.primaryAlias).toBeFalsy();
|
expect(metadata.body.primaryAlias).toBeFalsy();
|
||||||
expect(metadata.body.noteId).toEqual(publicId);
|
expect(metadata.body.noteId).toEqual(publicId);
|
||||||
|
|
||||||
const note = await request(testSetup.app.getHttpServer())
|
const note = await request(testSetup.app.getHttpServer())
|
||||||
.get(`/api/v2/notes/${newAlias}`)
|
.get(`/api/v2/notes/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(note.body.metadata.aliases).toContain(newAlias);
|
expect(note.body.metadata.aliases).toContain(newAlias);
|
||||||
expect(note.body.metadata.primaryAlias).toBeTruthy();
|
expect(note.body.metadata.primaryAlias).toBeTruthy();
|
||||||
expect(note.body.metadata.id).toEqual(publicId);
|
expect(note.body.metadata.id).toEqual(publicId);
|
||||||
|
@ -67,16 +68,20 @@ describe('Alias', () => {
|
||||||
describe('does not create an alias', () => {
|
describe('does not create an alias', () => {
|
||||||
it('because of a forbidden alias', async () => {
|
it('because of a forbidden alias', async () => {
|
||||||
newAliasDto.newAlias = forbiddenNoteId;
|
newAliasDto.newAlias = forbiddenNoteId;
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.post(`/api/v2/alias`)
|
.post(`/api/v2/alias`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(newAliasDto)
|
.send(newAliasDto)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
});
|
});
|
||||||
it('because of a alias that is a public id', async () => {
|
it('because of a alias that is a public id', async () => {
|
||||||
newAliasDto.newAlias = publicId;
|
newAliasDto.newAlias = publicId;
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.post(`/api/v2/alias`)
|
.post(`/api/v2/alias`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(newAliasDto)
|
.send(newAliasDto)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
|
@ -94,7 +99,7 @@ describe('Alias', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const note = await testSetup.notesService.createNote(
|
const note = await testSetup.notesService.createNote(
|
||||||
content,
|
content,
|
||||||
user,
|
testSetup.users[0],
|
||||||
testAlias,
|
testAlias,
|
||||||
);
|
);
|
||||||
publicId = note.publicId;
|
publicId = note.publicId;
|
||||||
|
@ -104,15 +109,20 @@ describe('Alias', () => {
|
||||||
it('updates a note with a normal alias', async () => {
|
it('updates a note with a normal alias', async () => {
|
||||||
const metadata = await request(testSetup.app.getHttpServer())
|
const metadata = await request(testSetup.app.getHttpServer())
|
||||||
.put(`/api/v2/alias/${newAlias}`)
|
.put(`/api/v2/alias/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(changeAliasDto)
|
.send(changeAliasDto)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(metadata.body.name).toEqual(newAlias);
|
expect(metadata.body.name).toEqual(newAlias);
|
||||||
expect(metadata.body.primaryAlias).toBeTruthy();
|
expect(metadata.body.primaryAlias).toBeTruthy();
|
||||||
expect(metadata.body.noteId).toEqual(publicId);
|
expect(metadata.body.noteId).toEqual(publicId);
|
||||||
|
|
||||||
const note = await request(testSetup.app.getHttpServer())
|
const note = await request(testSetup.app.getHttpServer())
|
||||||
.get(`/api/v2/notes/${newAlias}`)
|
.get(`/api/v2/notes/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
|
|
||||||
expect(note.body.metadata.aliases).toContain(newAlias);
|
expect(note.body.metadata.aliases).toContain(newAlias);
|
||||||
expect(note.body.metadata.primaryAlias).toBeTruthy();
|
expect(note.body.metadata.primaryAlias).toBeTruthy();
|
||||||
expect(note.body.metadata.id).toEqual(publicId);
|
expect(note.body.metadata.id).toEqual(publicId);
|
||||||
|
@ -122,14 +132,17 @@ describe('Alias', () => {
|
||||||
it('a note with unknown alias', async () => {
|
it('a note with unknown alias', async () => {
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.put(`/api/v2/alias/i_dont_exist`)
|
.put(`/api/v2/alias/i_dont_exist`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(changeAliasDto)
|
.send(changeAliasDto)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
it('if the property primaryAlias is false', async () => {
|
it('if the property primaryAlias is false', async () => {
|
||||||
changeAliasDto.primaryAlias = false;
|
changeAliasDto.primaryAlias = false;
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.put(`/api/v2/alias/${newAlias}`)
|
.put(`/api/v2/alias/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.set('Content-Type', 'application/json')
|
.set('Content-Type', 'application/json')
|
||||||
.send(changeAliasDto)
|
.send(changeAliasDto)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
|
@ -143,7 +156,7 @@ describe('Alias', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const note = await testSetup.notesService.createNote(
|
const note = await testSetup.notesService.createNote(
|
||||||
content,
|
content,
|
||||||
user,
|
testSetup.users[0],
|
||||||
testAlias,
|
testAlias,
|
||||||
);
|
);
|
||||||
await testSetup.aliasService.addAlias(note, newAlias);
|
await testSetup.aliasService.addAlias(note, newAlias);
|
||||||
|
@ -152,35 +165,46 @@ describe('Alias', () => {
|
||||||
it('deletes a normal alias', async () => {
|
it('deletes a normal alias', async () => {
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.delete(`/api/v2/alias/${newAlias}`)
|
.delete(`/api/v2/alias/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(204);
|
.expect(204);
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.get(`/api/v2/notes/${newAlias}`)
|
.get(`/api/v2/notes/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not delete an unknown alias', async () => {
|
it('does not delete an unknown alias', async () => {
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.delete(`/api/v2/alias/i_dont_exist`)
|
.delete(`/api/v2/alias/i_dont_exist`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(404);
|
.expect(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not delete a primary alias (if it is not the only one)', async () => {
|
it('does not delete a primary alias (if it is not the only one)', async () => {
|
||||||
const note = await testSetup.notesService.getNoteByIdOrAlias(testAlias);
|
const note = await testSetup.notesService.getNoteByIdOrAlias(testAlias);
|
||||||
await testSetup.aliasService.addAlias(note, newAlias);
|
await testSetup.aliasService.addAlias(note, newAlias);
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.delete(`/api/v2/alias/${testAlias}`)
|
.delete(`/api/v2/alias/${testAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(400);
|
.expect(400);
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.get(`/api/v2/notes/${newAlias}`)
|
.get(`/api/v2/notes/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('deletes a primary alias (if it is the only one)', async () => {
|
it('deletes a primary alias (if it is the only one)', async () => {
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.delete(`/api/v2/alias/${newAlias}`)
|
.delete(`/api/v2/alias/${newAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(204);
|
.expect(204);
|
||||||
|
|
||||||
await request(testSetup.app.getHttpServer())
|
await request(testSetup.app.getHttpServer())
|
||||||
.delete(`/api/v2/alias/${testAlias}`)
|
.delete(`/api/v2/alias/${testAlias}`)
|
||||||
|
.set('Authorization', `Bearer ${testSetup.authTokens[0].secret}`)
|
||||||
.expect(204);
|
.expect(204);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue