Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-16077: fix base domain name validation #2268

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { test, describe, expect } from 'vitest';
import {
baseDomainValidationSchema,
dnsNameValidationSchema,
hostPrefixValidationSchema,
ipBlockValidationSchema,
Expand Down Expand Up @@ -317,4 +318,51 @@ describe('validationSchemas', () => {

expect(counter).toBe(invalid.length);
});

test('baseDomainNameValidationSchema', async () => {
const valid = [
'a.com',
'co',
'1c',
'1-c',
'1--c',
'aaa',
'abc.def',
'a-aa.com',
'a--aa.com',
'aa.com.com.com.com',
'red.cat--rahul.com',
];
const invalid = [
'a',
'-',
'a-',
'-aaa.com.',
'aaa-.com',
'a.c',
'aaa.c',
'DNSnamescancontainonlyalphabeticalcharactersa-znumericcharacters0-9theminussign-andtheperiod',
'DNSnamescancontainonlyalphabeticalcharactersa-znumericcharacters0-9theminussign-andtheperiod.com',
];

await Promise.all(
valid.map((value) =>
baseDomainValidationSchema
.validate(value)
.catch(() => expect(value).toBe(`was rejected but is valid`)),
),
);

let counter = 0;
await Promise.all(
invalid.map((value) =>
baseDomainValidationSchema.validate(value).then(
() => expect(value).toBe('should be rejected since it is invalid'),
() => counter++,
),
),
);

expect(counter).toBe(invalid.length);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const CLUSTER_NAME_VALID_CHARS_REGEX = /^[a-z0-9-]*$/;
const SSH_PUBLIC_KEY_REGEX =
/^(ssh-rsa|ssh-ed25519|ecdsa-[-a-z0-9]*) AAAA[0-9A-Za-z+/]+[=]{0,3}( .+)?$/;
const DNS_NAME_REGEX = /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/;
const BASE_DOMAIN_REGEX = /^([a-z0-9]+(-[a-z0-9]+)*)$/;
const DNS_NAME_REGEX_OCM = /^([a-z0-9]+(-[a-z0-9]+)*[.])+[a-z]{2,}$/;
const BASE_DOMAIN_REGEX = /^[a-z\d][\-]*[a-z\d]+$/;
ammont82 marked this conversation as resolved.
Show resolved Hide resolved
const DNS_NAME_REGEX_OCM = /^([a-z\d]([\-]*[a-z\d]+)*\.)+[a-z\d]+[\-]*[a-z\d]+$/;
ammont82 marked this conversation as resolved.
Show resolved Hide resolved

const PROXY_DNS_REGEX =
/(^\.?([a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62}){1}(\.[a-zA-Z0-9_]{1}[a-zA-Z0-9_-]{0,62})*$)/;
Expand Down