Skip to content

Commit

Permalink
feat: add http schema
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-yarmosh committed Feb 4, 2025
1 parent 3f53cf9 commit e947a14
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 18 deletions.
35 changes: 34 additions & 1 deletion src/measurement/handler/result.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Joi from 'joi';
import type { Probe } from '../../probe/types.js';
import type { DnsRegularResult, DnsTraceResult, MeasurementResultMessage, MtrResult, PingResult, TestResult, TracerouteResult } from '../types.js';
import type { DnsRegularResult, DnsTraceResult, HttpResult, MeasurementResultMessage, MtrResult, PingResult, TestResult, TracerouteResult } from '../types.js';
import { getMeasurementRunner } from '../runner.js';
import { getProbeValidator } from '../../lib/probe-validator.js';

Expand Down Expand Up @@ -110,6 +110,38 @@ const mtrResultSchema = Joi.object<MtrResult>({
})),
});

const httpResultSchema = Joi.object<HttpResult>({
status: Joi.string().valid('finished', 'failed').required(),
rawOutput: Joi.string().allow(null).required(),
resolvedAddress: Joi.string().allow(null),
headers: Joi.object().pattern(Joi.string(), Joi.string()),
rawHeaders: Joi.string().allow(null),
rawBody: Joi.string().allow(null),
truncated: Joi.boolean(),
statusCode: Joi.number().allow(null),
statusCodeName: Joi.string().allow(null),
timings: Joi.object().pattern(Joi.string(), Joi.number().allow(null)),
tls: Joi.object({
authorized: Joi.boolean().required(),
createdAt: Joi.string(),
expiresAt: Joi.string(),
subject: Joi.object({
CN: Joi.string().required(),
alt: Joi.string().allow(null).required(),
}).required(),
issuer: Joi.object({
C: Joi.string().required(),
O: Joi.string().required(),
CN: Joi.string().required(),
}).required(),
keyType: Joi.string().valid('RSA', 'EC').allow(null).required(),
keyBits: Joi.number().allow(null).required(),
serialNumber: Joi.string().required(),
fingerprint256: Joi.string().required(),
publicKey: Joi.string().allow(null).required(),
}).allow(null),
});

const schema = Joi.object<MeasurementResultMessage>({
testId: Joi.string().required(),
measurementId: Joi.string().required(),
Expand All @@ -119,6 +151,7 @@ const schema = Joi.object<MeasurementResultMessage>({
tracerouteResultSchema,
dnsResultSchema,
mtrResultSchema,
httpResultSchema,
]).required(),
}).required();

Expand Down
46 changes: 29 additions & 17 deletions src/measurement/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ type PingTiming = {
};

export type PingResult = TestResult & {
resolvedAddress: string | null,
resolvedHostname: string | null,
resolvedAddress: string | null;
resolvedHostname: string | null;
timings: PingTiming[];
stats: {
min: number | null,
max: number | null,
avg: number | null,
total: number | null,
loss: number | null,
rcv: number | null,
drop: number | null,
min: number | null;
max: number | null;
avg: number | null;
total: number | null;
loss: number | null;
rcv: number | null;
drop: number | null;
};
};

Expand Down Expand Up @@ -150,21 +150,33 @@ export type HttpProgress = TestProgress & {
};

export type HttpResult = TestResult & {
resolvedAddress: string;
resolvedAddress: string | null;
headers: Record<string, string>;
rawHeaders: string;
rawBody: string;
rawHeaders: string | null;
rawBody: string | null;
truncated: boolean;
statusCode: number;
statusCode: number | null;
statusCodeName: string | null;
timings: Record<string, number>;
tls: {
[key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any
authorized: boolean;
authorizationError?: string;
createdAt: string;
expiresAt: string;
issuer: Record<string, string>;
subject: Record<string, string>;
authorizationError?: string;
subject: {
CN: string;
alt: string | null;
};
issuer: {
C: string;
O: string;
CN: string;
};
keyType: 'RSA' | 'EC' | null;
keyBits: number | null;
serialNumber: string;
fingerprint256: string;
publicKey: string | null;
};
};

Expand Down

0 comments on commit e947a14

Please sign in to comment.