mirror of
https://gitlab.nic.cz/turris/reforis/foris-js.git
synced 2024-11-13 17:25:34 +01:00
Merge branch 'add-hostname-validation' into 'dev'
Add hostname validation See merge request turris/reforis/foris-js!181
This commit is contained in:
commit
0a143e7de6
|
@ -1,16 +1,17 @@
|
|||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
* Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
*/
|
||||
|
||||
import {
|
||||
validateDomain,
|
||||
validateDUID,
|
||||
validateIPv4Address,
|
||||
validateIPv6Address,
|
||||
validateIPv6Prefix,
|
||||
validateDomain,
|
||||
validateHostname,
|
||||
validateDUID,
|
||||
validateMAC,
|
||||
} from "utils/validations";
|
||||
|
||||
|
@ -68,6 +69,15 @@ describe("Validation functions", () => {
|
|||
expect(validateDomain(".")).not.toBe(undefined);
|
||||
});
|
||||
|
||||
it("validateHostname valid", () => {
|
||||
expect(validateHostname("new-android")).toBe(undefined);
|
||||
expect(validateHostname("local")).toBe(undefined);
|
||||
});
|
||||
it("validateHostname invalid", () => {
|
||||
expect(validateHostname("-android")).not.toBe(undefined);
|
||||
expect(validateHostname("local.")).not.toBe(undefined);
|
||||
});
|
||||
|
||||
it("validateDUID valid", () => {
|
||||
expect(validateDUID("abcdefAB")).toBe(undefined);
|
||||
expect(validateDUID("ABCDEF12")).toBe(undefined);
|
||||
|
|
|
@ -82,6 +82,7 @@ export {
|
|||
validateIPv6Address,
|
||||
validateIPv6Prefix,
|
||||
validateDomain,
|
||||
validateHostname,
|
||||
validateDUID,
|
||||
validateMAC,
|
||||
validateMultipleEmails,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2019 CZ.NIC z.s.p.o. (http://www.nic.cz/)
|
||||
* Copyright (C) 2019-2022 CZ.NIC z.s.p.o. (https://www.nic.cz/)
|
||||
*
|
||||
* This is free software, licensed under the GNU General Public License v3.
|
||||
* See /LICENSE for more information.
|
||||
|
@ -14,6 +14,7 @@ export const ERROR_MESSAGES = {
|
|||
IPv6: _("This is not a valid IPv6 address."),
|
||||
IPv6Prefix: _("This is not a valid IPv6 prefix."),
|
||||
domain: _("This is not a valid domain name."),
|
||||
hostname: _("This is not a valid hostname."),
|
||||
DUID: _("This is not a valid DUID."),
|
||||
MAC: _("This is not a valid MAC address."),
|
||||
MultipleEmails: _("Doesn't contain a list of emails separated by commas."),
|
||||
|
@ -23,7 +24,8 @@ const REs = {
|
|||
IPv4: /^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
||||
IPv6: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]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0-9][A-Za-z0-9.-]{1,255}$/,
|
||||
domain: /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/,
|
||||
hostname: /^[a-z\d]([a-z\d-]{0,61}[a-z\d])?(\.[a-z\d]([a-z\d-]{0,61}[a-z\d])?)*$/i,
|
||||
DUID: /^([0-9a-fA-F]{2}){4}([0-9a-fA-F]{2})*$/,
|
||||
MAC: /^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$/,
|
||||
MultipleEmails: /^([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+ *)( *, *[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+ *)*$/,
|
||||
|
@ -40,6 +42,7 @@ const validateIPv4Address = createValidator("IPv4");
|
|||
const validateIPv6Address = createValidator("IPv6");
|
||||
const validateIPv6Prefix = createValidator("IPv6Prefix");
|
||||
const validateDomain = createValidator("domain");
|
||||
const validateHostname = createValidator("hostname");
|
||||
const validateDUID = createValidator("DUID");
|
||||
const validateMAC = createValidator("MAC");
|
||||
const validateMultipleEmails = createValidator("MultipleEmails");
|
||||
|
@ -49,6 +52,7 @@ export {
|
|||
validateIPv6Address,
|
||||
validateIPv6Prefix,
|
||||
validateDomain,
|
||||
validateHostname,
|
||||
validateDUID,
|
||||
validateMAC,
|
||||
validateMultipleEmails,
|
||||
|
|
Loading…
Reference in New Issue
Block a user