Skip to content

Commit

Permalink
feat: add OPTIONS as an allowed HTTP Method (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh authored Dec 17, 2024
1 parent 3aa418f commit fc926b7
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion public/demo/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ const ALLOWED_MTR_PROTOCOLS = [ 'TCP', 'UDP', 'ICMP' ];

// http
const ALLOWED_HTTP_PROTOCOLS = [ 'HTTP', 'HTTPS', 'HTTP2' ];
const ALLOWED_HTTP_METHODS = [ 'GET', 'HEAD' ];
const ALLOWED_HTTP_METHODS = [ 'GET', 'HEAD', 'OPTIONS' ];
1 change: 1 addition & 0 deletions public/v1/components/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ components:
enum:
- HEAD
- GET
- OPTIONS
default: HEAD
headers:
type: object
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/schema/command-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const ipVersionDnsSchema = Joi.number().when(Joi.ref('resolver'), {
export const validCmdTypes = [ 'ping', 'dns', 'traceroute', 'mtr', 'http' ];

const allowedHttpProtocols = [ 'HTTP', 'HTTPS', 'HTTP2' ];
const allowedHttpMethods = [ 'GET', 'HEAD' ];
const allowedHttpMethods = [ 'GET', 'HEAD', 'OPTIONS' ];

// Http
const httpTargetSchema = Joi.alternatives()
Expand Down
2 changes: 1 addition & 1 deletion src/measurement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ type DnsResult = TestResult & (DnsRegularResult | DnsTraceResult);

type HttpTest = {
request: {
method: 'HEAD' | 'GET';
method: 'HEAD' | 'GET' | 'OPTIONS';
host?: string;
path: string;
query: string;
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/cases/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@ describe('http measurement', () => {
expect(response).to.matchApiSchema();
});

it('should finish successfully in case of OPTIONS request', async () => {
const { id } = await got.post('http://localhost:80/v1/measurements', { json: {
target: 'www.jsdelivr.com',
type: 'http',
measurementOptions: {
request: {
method: 'OPTIONS',
},
},
} }).json<any>();

const response = await waitMeasurementFinish(id);

expect(response.body.status).to.equal('finished');
expect(response.body.results[0].result.status).to.equal('finished');
expect(response.body.results[0].result.rawBody).to.equal(null);
expect(response).to.matchApiSchema();
});

it('should finish successfully in case of IPv6 domain target', async () => {
const { id } = await got.post('http://localhost:80/v1/measurements', { json: {
target: 'www.jsdelivr.com',
Expand Down
2 changes: 1 addition & 1 deletion test/tests/unit/measurement/schema/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,7 @@ describe('command schema', async () => {
const valid = globalSchema.validate(input, { convert: true });

expect(valid.error).to.exist;
expect(valid.error!.message).to.equal('"measurementOptions.request.method" must be one of [GET, HEAD]');
expect(valid.error!.message).to.equal('"measurementOptions.request.method" must be one of [GET, HEAD, OPTIONS]');
});

it('should fail (unsupported protocol)', () => {
Expand Down
7 changes: 6 additions & 1 deletion wallaby.e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function wallaby () {
export default function w (wallaby) {
return {
testFramework: 'mocha',
files: [
Expand Down Expand Up @@ -31,6 +31,11 @@ export default function wallaby () {
env: 'NODE_ENV=test',
},
},
compilers: {
'**/*.ts?(x)': wallaby.compilers.typeScript({
module: 'ESNext',
}),
},
workers: { restart: true, initial: 1, regular: 1 },
runMode: 'onsave',
};
Expand Down
4 changes: 2 additions & 2 deletions wallaby.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'node:path';
import * as url from 'node:url';

export default function wallaby (wallaby) {
export default function w (wallaby) {
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

return {
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function wallaby (wallaby) {
params: {
runner: '--experimental-specifier-resolution=node --loader '
+ url.pathToFileURL(path.join(__dirname, 'node_modules/testdouble/lib/index.mjs')),
env: 'NODE_ENV=test;NEW_RELIC_ENABLED=false;NEW_RELIC_LOG_ENABLED=false;TEST_MODE=unit',
env: 'NODE_ENV=test;TEST_MODE=unit',
},
},
compilers: {
Expand Down

0 comments on commit fc926b7

Please sign in to comment.