mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
Correctly handle slugs in POST requests
* bug: correctly handle slug in POST request * bug: disallow slashes in slug + modified tests * fix: fixed tests to work with PUT instead of POST+slug * fix: fixed tests failing in ci * fix: adapted to reviews * fix: adapted to review
This commit is contained in:
@@ -2,7 +2,6 @@ import { EventEmitter } from 'events';
|
||||
import { promises as fs } from 'fs';
|
||||
import type { IncomingHttpHeaders } from 'http';
|
||||
import { Readable } from 'stream';
|
||||
import * as url from 'url';
|
||||
import type { MockResponse } from 'node-mocks-http';
|
||||
import { createResponse } from 'node-mocks-http';
|
||||
import type { ResourceStore, PermissionSet, HttpHandler, HttpRequest } from '../../src/';
|
||||
@@ -93,24 +92,22 @@ export class ResourceHelper {
|
||||
return response;
|
||||
}
|
||||
|
||||
public async createResource(fileLocation: string, slug: string, contentType: string, mayFail = false):
|
||||
public async createResource(fileLocation: string, path: string, contentType: string, mayFail = false):
|
||||
Promise<MockResponse<any>> {
|
||||
const fileData = await fs.readFile(
|
||||
joinFilePath(__dirname, fileLocation),
|
||||
);
|
||||
|
||||
const response: MockResponse<any> = await this.performRequestWithBody(
|
||||
this.baseUrl,
|
||||
'POST',
|
||||
new URL(path, this.baseUrl),
|
||||
'PUT',
|
||||
{ 'content-type': contentType,
|
||||
slug,
|
||||
'transfer-encoding': 'chunked' },
|
||||
fileData,
|
||||
);
|
||||
if (!mayFail) {
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(response.statusCode).toBe(205);
|
||||
expect(response._getData()).toHaveLength(0);
|
||||
expect(response._getHeaders().location).toContain(url.format(this.baseUrl));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -153,20 +150,18 @@ export class ResourceHelper {
|
||||
return response;
|
||||
}
|
||||
|
||||
public async createContainer(slug: string): Promise<MockResponse<any>> {
|
||||
public async createContainer(path: string): Promise<MockResponse<any>> {
|
||||
const response: MockResponse<any> = await this.performRequest(
|
||||
this.baseUrl,
|
||||
'POST',
|
||||
new URL(path, this.baseUrl),
|
||||
'PUT',
|
||||
{
|
||||
slug,
|
||||
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
|
||||
'content-type': 'text/turtle',
|
||||
'transfer-encoding': 'chunked',
|
||||
},
|
||||
);
|
||||
expect(response.statusCode).toBe(201);
|
||||
expect(response.statusCode).toBe(205);
|
||||
expect(response._getData()).toHaveLength(0);
|
||||
expect(response._getHeaders().location).toContain(url.format(this.baseUrl));
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user