Skip to content

Commit

Permalink
test(domainkeys): test domainkey OPTIONS requests
Browse files Browse the repository at this point in the history
  • Loading branch information
trieloff committed Oct 30, 2023
1 parent f90b3b6 commit 618470f
Showing 1 changed file with 217 additions and 7 deletions.
224 changes: 217 additions & 7 deletions test/options-pipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ const HELIX_CONFIG_JSON = JSON.stringify({
},
});

describe('Preflight OPTIONS Requests', () => {
function createRequest(headers) {
return new PipelineRequest('https://helix-pipeline.com/', {
method: 'options',
headers,
});
}
function createRequest(headers, url = '/') {
return new PipelineRequest(`https://helix-pipeline.com${url}`, {
method: 'options',
headers,
});
}

describe('Preflight OPTIONS Requests', () => {
const defaultState = () => ({
owner: 'owner',
repo: 'repo',
Expand Down Expand Up @@ -182,3 +182,213 @@ describe('Preflight OPTIONS Requests', () => {
});
});
});

describe('RUM Challenge OPTIONS Request', () => {
it('sends 204 without x-rum-challenge header for normal requests', async () => {
const state = new PipelineState({
owner: 'owner',
repo: 'repo',
ref: 'ref',
partition: 'live',
path: '/somepath/workbook',
log: console,
s3Loader: new StaticS3Loader()
.reply(
'helix-code-bus',
'owner/repo/ref/helix-config.json',
new PipelineResponse(HELIX_CONFIG_JSON),
),
});

const response = await optionsPipe(
state,
createRequest({
'x-forwarded-host': 'localhost',
}),
);
assert.strictEqual(response.status, 204);
const challenge = response.headers.get('x-rum-challenge');
// assert that the challenge is not set
assert.strictEqual(challenge, undefined);
});

it('sends 204 without x-rum-challenge header when hostnames do not match', async () => {
const state = new PipelineState({
owner: 'owner',
repo: 'repo',
ref: 'ref',
partition: 'live',
path: '/somepath/workbook',
log: console,
s3Loader: new StaticS3Loader()
.reply(
'helix-code-bus',
'owner/repo/ref/helix-config.json',
new PipelineResponse(HELIX_CONFIG_JSON),
)
.reply('helix-content-bus', 'foobus/live/.helix/config-all.json', {
status: 200,
body: JSON.stringify({
config: {
data: {
domainkey: 'foo/bar/baz',
cdn: {
prod: {
host: 'adobe.com',
},
},
},
},
}),
headers: new Map(),
}),
});

const response = await optionsPipe(
state,
createRequest({
'x-forwarded-host': 'example.com',
}, '/_rum-challenge'),
);

assert.strictEqual(response.status, 204);
const challenge = response.headers.get('x-rum-challenge');
// assert that the challenge is unsetset
assert.strictEqual(challenge, undefined);
});

it('sends 204 with x-rum-challenge header for rum-challenge requests', async () => {
const state = new PipelineState({
owner: 'owner',
repo: 'repo',
ref: 'ref',
partition: 'live',
path: '/somepath/workbook',
log: console,
s3Loader: new StaticS3Loader()
.reply(
'helix-code-bus',
'owner/repo/ref/helix-config.json',
new PipelineResponse(HELIX_CONFIG_JSON),
)
.reply('helix-content-bus', 'foobus/live/.helix/config-all.json', {
status: 200,
body: JSON.stringify({
config: {
data: {
domainkey: 'foo/bar/baz',
cdn: {
prod: {
host: 'example.com',
},
},
},
},
}),
headers: new Map(),
}),
});

const response = await optionsPipe(
state,
createRequest({
'x-forwarded-host': 'example.com',
}, '/_rum-challenge'),
);

assert.strictEqual(response.status, 204);
const challenge = response.headers.get('x-rum-challenge');
// assert that the challenge is set
assert.strictEqual(challenge, '7263bf25ef81b7a406a1bea7f367d553441c420678fc74726a7a8f9f63b8d5a7');
});

it('sends 204 with x-rum-challenge header for rum-challenge requests wit array of domainkeys', async () => {
const state = new PipelineState({
owner: 'owner',
repo: 'repo',
ref: 'ref',
partition: 'live',
path: '/somepath/workbook',
log: console,
s3Loader: new StaticS3Loader()
.reply(
'helix-code-bus',
'owner/repo/ref/helix-config.json',
new PipelineResponse(HELIX_CONFIG_JSON),
)
.reply('helix-content-bus', 'foobus/live/.helix/config-all.json', {
status: 200,
body: JSON.stringify({
config: {
data: {
domainkey: ['foo/bar/baz', 'bar/baz/foo'],
cdn: {
prod: {
host: 'example.com',
},
},
},
},
}),
headers: new Map(),
}),
});

const response = await optionsPipe(
state,
createRequest({
'x-forwarded-host': 'example.com',
}, '/_rum-challenge'),
);

assert.strictEqual(response.status, 204);
const challenge = response.headers.get('x-rum-challenge');
// assert that the challenge is set
assert.strictEqual(challenge, '7263bf25ef81b7a406a1bea7f367d553441c420678fc74726a7a8f9f63b8d5a7 de6b5c08a3d9257e699400a1de13958364a34b2ccd4dd9ea204926e9740327c4');
});

it('sends 204 with x-rum-challenge header for rum-challenge requests, falling back to Slack if unset', async () => {
const state = new PipelineState({
owner: 'owner',
repo: 'repo',
ref: 'ref',
partition: 'live',
path: '/somepath/workbook',
log: console,
s3Loader: new StaticS3Loader()
.reply(
'helix-code-bus',
'owner/repo/ref/helix-config.json',
new PipelineResponse(HELIX_CONFIG_JSON),
)
.reply('helix-content-bus', 'foobus/live/.helix/config-all.json', {
status: 200,
body: JSON.stringify({
config: {
data: {
slack: 'foo/bar/baz',
cdn: {
prod: {
host: 'example.com',
},
},
},
},
}),
headers: new Map(),
}),
});

const response = await optionsPipe(
state,
createRequest({
'x-forwarded-host': 'example.com',
}, '/_rum-challenge'),
);

assert.strictEqual(response.status, 204);
const challenge = response.headers.get('x-rum-challenge');
// assert that the challenge is set
assert.strictEqual(challenge, '7263bf25ef81b7a406a1bea7f367d553441c420678fc74726a7a8f9f63b8d5a7');
});
});

0 comments on commit 618470f

Please sign in to comment.