Skip to content

Commit 3a0b628

Browse files
committed
fix(registry/server): remove archived is-valid-domain lib using joi and regex
1 parent cc41976 commit 3a0b628

File tree

5 files changed

+12
-49
lines changed

5 files changed

+12
-49
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ jobs:
199199
options: --name=postgres --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
200200

201201
steps:
202-
- uses: actions/checkout@v64
202+
- uses: actions/checkout@v6
203203
with:
204204
ref: ${{ matrix.branch.ref }}
205205

registry/package-lock.json

Lines changed: 0 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

registry/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"@types/escape-html": "^1.0.4",
3737
"@types/express": "^5.0.5",
3838
"@types/express-session": "^1.18.2",
39-
"@types/is-valid-domain": "0.0.4",
4039
"@types/jsonwebtoken": "^9.0.10",
4140
"@types/lodash": "^4.17.21",
4241
"@types/mocha": "^10.0.10",
@@ -77,7 +76,6 @@
7776
"express-session": "^1.18.2",
7877
"http-shutdown": "^1.2.2",
7978
"ilc-plugins-sdk": "^2.3.0",
80-
"is-valid-domain": "0.1.6",
8179
"joi": "^18.0.2",
8280
"knex": "^3.1.0",
8381
"lodash": "^4.17.21",

registry/server/routerDomains/interfaces/index.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import Joi from 'joi';
2-
import isValidDomain from 'is-valid-domain';
32

4-
import { getJoiErr } from '../../util/helpers';
53
import { templateNameSchema } from '../../templates/routes/validation';
64

75
export default interface RouterDomains {
@@ -15,24 +13,18 @@ export default interface RouterDomains {
1513

1614
export const routerDomainIdSchema = Joi.string().trim().required();
1715

18-
const domainValidation = (fieldName: string) =>
19-
Joi.string()
20-
.trim()
21-
.min(1)
22-
.external((value) => {
23-
if (!value) return;
24-
25-
if (value.match(/^(localhost|127\.0\.0\.1)(:\d{1,5})?$/) || isValidDomain(value)) {
26-
return;
27-
}
28-
29-
throw getJoiErr(fieldName, `Specified "${fieldName}" is not valid.`, value);
30-
});
16+
const domainValidation = () =>
17+
Joi.alternatives().try(
18+
Joi.string()
19+
.trim()
20+
.pattern(/^(localhost|127\.0\.0\.1)(:\d{1,5})?$/),
21+
Joi.string().trim().min(1).domain({ allowFullyQualified: true, tlds: false }),
22+
);
3123

3224
const commonRouterDomainsSchema = {
33-
domainName: domainValidation('domainName').required(),
25+
domainName: domainValidation().required(),
3426
template500: templateNameSchema.required(),
35-
canonicalDomain: domainValidation('canonicalDomain').allow(null).default(null),
27+
canonicalDomain: domainValidation().allow(null).default(null),
3628
props: Joi.object().allow(null).default(null),
3729
ssrProps: Joi.object().allow(null).default(null),
3830
versionId: Joi.string().strip(),

registry/tests/routerDomains.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe(`Tests ${example.url}`, () => {
7171
await req
7272
.post(example.url)
7373
.send(incorrect)
74-
.expect(422, '"domainName" must be a string\n' + '"template500" must be a string');
74+
.expect(422, '"domainName" must be one of [string]\n' + '"template500" must be a string');
7575
});
7676

7777
it('should not create record with non-existed template500', async () => {
@@ -323,7 +323,7 @@ describe(`Tests ${example.url}`, () => {
323323
await req
324324
.put(example.url + routerDomainsId)
325325
.send(incorrect)
326-
.expect(422, '"domainName" must be a string\n' + '"template500" must be a string');
326+
.expect(422, '"domainName" must be one of [string]\n' + '"template500" must be a string');
327327
} finally {
328328
routerDomainsId && (await req.delete(example.url + routerDomainsId));
329329
}

0 commit comments

Comments
 (0)