Skip to content

Commit 0a89e2f

Browse files
committed
fix: include static s3 loader
1 parent 6461018 commit 0a89e2f

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

.npmignore

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
*.tgz
2-
.circleci/
3-
.eslintignore
4-
.eslintrc.js
5-
.github/
6-
.idea
7-
.jsdoc.json
8-
.nyc_output/
9-
.releaserc.js
10-
.renovaterc.json
11-
.snyk
12-
.tidelift.yml
1+
.*
132
build
143
coverage
154
junit
165
logs
176
node_modules/
187
snykmocha.js
19-
test
8+
test/*
209
test-results.xml
10+
!test/StaticS3Loader.js

src/html-pipe.js

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import splitSections from './steps/split-sections.js';
3333
import tohtml from './steps/stringify-response.js';
3434
import { PipelineStatusError } from './PipelineStatusError.js';
3535
import { PipelineResponse } from './PipelineResponse.js';
36+
import { validatePathInfo } from './utils/path.js';
3637

3738
/**
3839
* Runs the default pipeline and returns the response.
@@ -43,6 +44,15 @@ import { PipelineResponse } from './PipelineResponse.js';
4344
export async function htmlPipe(state, req) {
4445
const { log } = state;
4546

47+
if (!validatePathInfo(state.info)) {
48+
return new PipelineResponse('', {
49+
status: 404,
50+
headers: {
51+
'x-error': 'invalid path',
52+
},
53+
});
54+
}
55+
4656
/** @type PipelineResponse */
4757
const res = new PipelineResponse();
4858

src/steps/fetch-content.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default async function fetchContent(state, req, res) {
2626

2727
const isCode = state.content.sourceBus === 'code';
2828
const key = isCode
29-
? `${owner}/${repo}/${ref}/${info.resourcePath}`
29+
? `${owner}/${repo}/${ref}${info.resourcePath}`
3030
: `${contentBusId}/${partition}${info.resourcePath}`;
3131
const bucketId = isCode ? 'helix-code-bus' : 'helix-content-bus';
3232

@@ -55,12 +55,12 @@ export default async function fetchContent(state, req, res) {
5555
// (https://github.com/adobe/helix-pipeline-service/issues/290)
5656
if (state.info.originalFilename === 'index') {
5757
res.status = 404;
58-
res.error = `request to ${info.path} not allowed (no-index).`;
58+
res.error = `request to ${info.resourcePath} not allowed (no-index).`;
5959
}
6060
} else {
6161
// keep 404, but propagate others as 502
6262
res.status = ret.status === 404 ? 404 : 502;
63-
res.error = `failed to load ${info.path} from ${state.content.sourceBus}-bus: ${ret.status}`;
63+
res.error = `failed to load ${info.resourcePath} from ${state.content.sourceBus}-bus: ${ret.status}`;
6464
}
6565

6666
if (res.status === 404) {

src/steps/folder-mapping.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ export default function folderMapping(state) {
5353
// special case: use code-bus
5454
state.content.sourceBus = 'code';
5555
state.info.resourcePath = mapped;
56-
state.log.info(`mapped ${path} to ${state.info.resourcePath} (${state.content.sourceBus}-bus)`);
56+
state.log.info(`mapped ${path} to ${state.info.resourcePath} (code-bus)`);
5757
} else {
58-
state.log.info(`mapped ${path} to ${state.info.path} (${state.content.sourceBus}-bus)`);
58+
state.log.info(`mapped ${path} to ${state.info.path} (content-bus)`);
5959
}
6060
}
6161
}

test/html-pipe.test.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,27 @@
1414
import assert from 'assert';
1515
import esmock from 'esmock';
1616
import { FileS3Loader } from './FileS3Loader.js';
17-
import { PipelineRequest, PipelineState } from '../src/index.js';
17+
import { htmlPipe, PipelineRequest, PipelineState } from '../src/index.js';
1818

1919
describe('Index Tests', () => {
20+
it('responds with 404 for invalid path', async () => {
21+
const resp = await htmlPipe(
22+
new PipelineState({ path: '/foo.hidden.html' }),
23+
new PipelineRequest(new URL('https://www.hlx.live/')),
24+
);
25+
assert.strictEqual(resp.status, 404);
26+
assert.strictEqual(resp.headers.get('x-error'), 'invalid path');
27+
});
28+
2029
it('responds with 500 for pipeline errors', async () => {
2130
/** @type htmlPipe */
22-
const { htmlPipe } = await esmock('../src/html-pipe.js', {
31+
const { htmlPipe: mockPipe } = await esmock('../src/html-pipe.js', {
2332
'../src/steps/fetch-config.js': () => {
2433
throw Error('kaputt');
2534
},
2635
});
2736

28-
const resp = await htmlPipe(
37+
const resp = await mockPipe(
2938
new PipelineState({ s3Loader: new FileS3Loader() }),
3039
new PipelineRequest(new URL('https://www.hlx.live/')),
3140
);

test/rendering.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ describe('Rendering', () => {
272272
'content-type': 'text/html; charset=utf-8',
273273
'last-modified': 'Wed, 12 Oct 2009 17:50:00 GMT',
274274
'x-surrogate-key': 'super-test--helix-pages--adobe_404',
275-
'x-error': 'failed to load /not-found-with-handler from content-bus: 404',
275+
'x-error': 'failed to load /not-found-with-handler.md from content-bus: 404',
276276
});
277277
});
278278

test/steps/fetch-content.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@ describe('Fetch Content', () => {
3737

3838
await fetchContent(state, {}, res);
3939
assert.strictEqual(res.status, 502);
40-
assert.strictEqual(res.error, 'failed to load undefined from undefined-bus: 500');
40+
assert.strictEqual(res.error, 'failed to load /index.md from undefined-bus: 500');
4141
});
4242
});

0 commit comments

Comments
 (0)