Skip to content

Commit

Permalink
fix: relax domain validation rules to match the API (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinKolarik authored Aug 8, 2024
1 parent e9ca74a commit 43630a1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/command/dns-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ const dnsOptionsSchema = Joi.object<DnsOptions>({
type: Joi.string().valid(...allowedTypes).optional().default('A'),
}),
ipVersion: Joi.when(Joi.ref('resolver'), {
is: Joi.string().domain(),
then: Joi.valid(...allowedIpVersions).default(4),
is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(),
then: Joi.valid(4).default(4),
otherwise: Joi.when(Joi.ref('resolver'), {
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }),
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(),
then: Joi.valid(6).default(6),
otherwise: Joi.valid(4).default(4),
otherwise: Joi.valid(...allowedIpVersions).default(4),
}),
}),
});
Expand Down
12 changes: 6 additions & 6 deletions src/command/http-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ const allowedIpVersions = [ 4, 6 ];
export const httpOptionsSchema = Joi.object<HttpOptions>({
type: Joi.string().valid('http').insensitive().required(),
inProgressUpdates: Joi.boolean().required(),
target: Joi.alternatives().try(Joi.string().ip(), Joi.string().domain()).required(),
target: Joi.string(),
resolver: Joi.string().ip(),
protocol: Joi.string().valid(...allowedHttpProtocols).insensitive().default('HTTPS'),
port: Joi.number(),
request: Joi.object({
method: Joi.string().valid(...allowedHttpMethods).insensitive().default('HEAD'),
host: Joi.string().domain(),
host: Joi.string(),
path: Joi.string().optional().default('/'),
query: Joi.string().allow('').optional().default(''),
headers: Joi.object().default({}),
}).required(),
ipVersion: Joi.when(Joi.ref('target'), {
is: Joi.string().domain(),
then: Joi.valid(...allowedIpVersions).default(4),
is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(),
then: Joi.valid(4).default(4),
otherwise: Joi.when(Joi.ref('target'), {
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }),
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(),
then: Joi.valid(6).default(6),
otherwise: Joi.valid(4).default(4),
otherwise: Joi.valid(...allowedIpVersions).default(4),
}),
}),
});
Expand Down
8 changes: 4 additions & 4 deletions src/command/mtr-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const mtrOptionsSchema = Joi.object<MtrOptions>({
packets: Joi.number().min(1).max(16).default(3),
port: Joi.number(),
ipVersion: Joi.when(Joi.ref('target'), {
is: Joi.string().domain(),
then: Joi.valid(...allowedIpVersions).default(4),
is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(),
then: Joi.valid(4).default(4),
otherwise: Joi.when(Joi.ref('target'), {
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }),
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(),
then: Joi.valid(6).default(6),
otherwise: Joi.valid(4).default(4),
otherwise: Joi.valid(...allowedIpVersions).default(4),
}),
}),
});
Expand Down
8 changes: 4 additions & 4 deletions src/command/ping-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const pingOptionsSchema = Joi.object<PingOptions>({
target: Joi.string(),
packets: Joi.number().min(1).max(16).default(3),
ipVersion: Joi.when(Joi.ref('target'), {
is: Joi.string().domain(),
then: Joi.valid(...allowedIpVersions).default(4),
is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(),
then: Joi.valid(4).default(4),
otherwise: Joi.when(Joi.ref('target'), {
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }),
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(),
then: Joi.valid(6).default(6),
otherwise: Joi.valid(4).default(4),
otherwise: Joi.valid(...allowedIpVersions).default(4),
}),
}),
});
Expand Down
8 changes: 4 additions & 4 deletions src/command/traceroute-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const traceOptionsSchema = Joi.object<TraceOptions>({
protocol: Joi.string(),
port: Joi.number(),
ipVersion: Joi.when(Joi.ref('target'), {
is: Joi.string().domain(),
then: Joi.valid(...allowedIpVersions).default(4),
is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(),
then: Joi.valid(4).default(4),
otherwise: Joi.when(Joi.ref('target'), {
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }),
is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(),
then: Joi.valid(6).default(6),
otherwise: Joi.valid(4).default(4),
otherwise: Joi.valid(...allowedIpVersions).default(4),
}),
}),
});
Expand Down

0 comments on commit 43630a1

Please sign in to comment.