How to use filterInvalidSubdomainLabel method in fast-check-monorepo

Best JavaScript code snippet using fast-check-monorepo

domain.ts

Source:domain.ts Github

copy

Full Screen

1import { array } from './array';2import {3 buildLowerAlphaArbitrary,4 buildLowerAlphaNumericArbitrary,5} from './_internals/builders/CharacterRangeArbitraryBuilder';6import { option } from './option';7import { stringOf } from './stringOf';8import { tuple } from './tuple';9import { Arbitrary } from '../check/arbitrary/definition/Arbitrary';10import { filterInvalidSubdomainLabel } from './_internals/helpers/InvalidSubdomainLabelFiIter';11import { resolveSize, relativeSizeToSize, Size, SizeForArbitrary } from './_internals/helpers/MaxLengthFromMinLength';12import { adapter, AdapterOutput } from './_internals/AdapterArbitrary';13import { safeJoin, safeSlice, safeSplit, safeSubstring } from '../utils/globals';14/** @internal */15function toSubdomainLabelMapper([f, d]: [string, [string, string] | null]): string {16 return d === null ? f : `${f}${d[0]}${d[1]}`;17}18/** @internal */19function toSubdomainLabelUnmapper(value: unknown): [string, [string, string] | null] {20 if (typeof value !== 'string' || value.length === 0) {21 throw new Error('Unsupported');22 }23 if (value.length === 1) {24 return [value[0], null];25 }26 return [value[0], [safeSubstring(value, 1, value.length - 1), value[value.length - 1]]];27}28/** @internal */29function subdomainLabel(size: Size) {30 const alphaNumericArb = buildLowerAlphaNumericArbitrary([]);31 const alphaNumericHyphenArb = buildLowerAlphaNumericArbitrary(['-']);32 // Rq: maxLength = 61 because max length of a label is 63 according to RFC 103433 // and we add 2 characters to this generated value34 // According to RFC 1034 (confirmed by RFC 1035):35 // <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]36 // <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>37 // <let-dig-hyp> ::= <let-dig> | "-"38 // <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case39 // <digit> ::= any one of the ten digits 0 through 940 // "The labels must follow the rules for ARPANET host names. They must start with a letter, end with a letter or digit, and have as interior41 // characters only letters, digits, and hyphen. There are also some restrictions on the length. Labels must be 63 characters or less."42 // But RFC 1123 relaxed the constraint:43 // "The syntax of a legal Internet host name was specified in RFC-952[DNS:4]. One aspect of host name syntax is hereby changed: the44 // restriction on the first character is relaxed to allow either a letter or a digit. Host software MUST support this more liberal syntax."45 return tuple(46 alphaNumericArb,47 option(tuple(stringOf(alphaNumericHyphenArb, { size, maxLength: 61 }), alphaNumericArb))48 )49 .map(toSubdomainLabelMapper, toSubdomainLabelUnmapper)50 .filter(filterInvalidSubdomainLabel);51}52/** @internal */53function labelsMapper(elements: [string[], string]): string {54 return `${safeJoin(elements[0], '.')}.${elements[1]}`;55}56/** @internal */57function labelsUnmapper(value: unknown): [string[], string] {58 if (typeof value !== 'string') {59 throw new Error('Unsupported type');60 }61 const lastDotIndex = value.lastIndexOf('.');62 return [safeSplit(safeSubstring(value, 0, lastDotIndex), '.'), safeSubstring(value, lastDotIndex + 1)];63}64/** @internal */65function labelsAdapter(labels: [string[], string]): AdapterOutput<[string[], string]> {66 // labels[0].length is always >=167 const [subDomains, suffix] = labels;68 let lengthNotIncludingIndex = suffix.length;69 for (let index = 0; index !== subDomains.length; ++index) {70 lengthNotIncludingIndex += 1 + subDomains[index].length;71 // Required by RFC 1034:72 // To simplify implementations, the total number of octets that represent73 // a domain name (i.e., the sum of all label octets and label lengths) is limited to 255.74 // It seems that this restriction has been relaxed in modern web browsers.75 if (lengthNotIncludingIndex > 255) {76 return { adapted: true, value: [safeSlice(subDomains, 0, index), suffix] };77 }78 }79 return { adapted: false, value: labels };80}81/**82 * Constraints to be applied on {@link domain}83 * @remarks Since 2.22.084 * @public85 */86export interface DomainConstraints {87 /**88 * Define how large the generated values should be (at max)89 * @remarks Since 2.22.090 */91 size?: Exclude<SizeForArbitrary, 'max'>;92}93/**94 * For domains95 * having an extension with at least two lowercase characters96 *97 * According to {@link https://www.ietf.org/rfc/rfc1034.txt | RFC 1034},98 * {@link https://www.ietf.org/rfc/rfc1035.txt | RFC 1035},99 * {@link https://www.ietf.org/rfc/rfc1123.txt | RFC 1123} and100 * {@link https://url.spec.whatwg.org/ | WHATWG URL Standard}101 *102 * @param constraints - Constraints to apply when building instances (since 2.22.0)103 *104 * @remarks Since 1.14.0105 * @public106 */107export function domain(constraints: DomainConstraints = {}): Arbitrary<string> {108 const resolvedSize = resolveSize(constraints.size);109 const resolvedSizeMinusOne = relativeSizeToSize('-1', resolvedSize);110 // A list of public suffixes can be found here: https://publicsuffix.org/list/public_suffix_list.dat111 // our current implementation does not follow this list and generate a fully randomized suffix112 // which is probably not in this list (probability would be low)113 const alphaNumericArb = buildLowerAlphaArbitrary([]);114 const publicSuffixArb = stringOf(alphaNumericArb, { minLength: 2, maxLength: 63, size: resolvedSizeMinusOne });115 return (116 // labels have between 1 and 63 characters117 // domains are made of dot-separated labels and have up to 255 characters so that are made of up-to 128 labels118 adapter(119 tuple(120 array(subdomainLabel(resolvedSize), { size: resolvedSizeMinusOne, minLength: 1, maxLength: 127 }),121 publicSuffixArb122 ),123 labelsAdapter124 ).map(labelsMapper, labelsUnmapper)125 );...

Full Screen

Full Screen

InvalidSubdomainLabelFiIter.spec.ts

Source:InvalidSubdomainLabelFiIter.spec.ts Github

copy

Full Screen

...7 const alphaChar = () => fc.mapToConstant({ num: 26, build: (v) => String.fromCharCode(v + 0x61) });8 it('should accept any subdomain composed of only alphabet characters and with at most 63 characters', () =>9 fc.assert(10 fc.property(fc.stringOf(alphaChar(), { minLength: 1, maxLength: 63 }), (subdomainLabel) => {11 expect(filterInvalidSubdomainLabel(subdomainLabel)).toBe(true);12 })13 ));14 it('should reject any subdomain with strictly more than 63 characters', () =>15 fc.assert(16 fc.property(fc.stringOf(alphaChar(), { minLength: 64 }), (subdomainLabel) => {17 expect(filterInvalidSubdomainLabel(subdomainLabel)).toBe(false);18 })19 ));20 it('should reject any subdomain starting by "xn--"', () =>21 fc.assert(22 fc.property(fc.stringOf(alphaChar(), { maxLength: 63 - 'xn--'.length }), (subdomainLabelEnd) => {23 const subdomainLabel = `xn--${subdomainLabelEnd}`;24 expect(filterInvalidSubdomainLabel(subdomainLabel)).toBe(false);25 })26 ));27 it('should not reject subdomains if they start by a substring of "xn--"', () =>28 fc.assert(29 fc.property(30 fc.stringOf(alphaChar(), { maxLength: 63 - 'xn--'.length }),31 fc.nat('xn--'.length - 1),32 (subdomainLabelEnd, keep) => {33 const subdomainLabel = `${'xn--'.substring(0, keep)}${subdomainLabelEnd}`;34 expect(filterInvalidSubdomainLabel(subdomainLabel)).toBe(true);35 }36 )37 ));...

Full Screen

Full Screen

InvalidSubdomainLabelFiIter.ts

Source:InvalidSubdomainLabelFiIter.ts Github

copy

Full Screen

1/** @internal */2export function filterInvalidSubdomainLabel(subdomainLabel: string): boolean {3 // Here our definition of a subdomain is <label> and "[l]abels must be 63 characters or less"4 // According RFC 1034 a subdomain should be defined as follows:5 // - <subdomain> ::= <label> | <subdomain> "." <label>6 // - <label> ::= <letter> [ [ <ldh-str> ] <let-dig> ]7 // - <ldh-str> ::= <let-dig-hyp> | <let-dig-hyp> <ldh-str>8 // - <let-dig-hyp> ::= <let-dig> | "-"9 // - <let-dig> ::= <letter> | <digit>10 // - <letter> ::= any one of the 52 alphabetic characters A through Z in upper case and a through z in lower case11 // - <digit> ::= any one of the ten digits 0 through 912 // If we strictly follow RFC 1034, 9gag would be an invalid domain. Support for such domain has been added by ....13 if (subdomainLabel.length > 63) {14 return false; // invalid, it seems that this restriction has been relaxed in modern web browsers15 }16 // We discard any subdomain starting by xn--...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var filterInvalidSubdomainLabel = require('fast-check-monorepo').filterInvalidSubdomainLabel;2console.log(filterInvalidSubdomainLabel('test'));3console.log(filterInvalidSubdomainLabel('test3'));4console.log(filterInvalidSubdomainLabel('test.test'));5console.log(filterInvalidSubdomainLabel('test.test3'));6console.log(filterInvalidSubdomainLabel('test3.test'));7console.log(filterInvalidSubdomainLabel('test3.test3'));8console.log(filterInvalidSubdomainLabel('test.test.test'));9console.log(filterInvalidSubdomainLabel('test.test.test3'));10console.log(filterInvalidSubdomainLabel('test.test3.test'));11console.log(filterInvalidSubdomainLabel('test.test3.test3'));12console.log(filterInvalidSubdomainLabel('test3.test.test'));13console.log(filterInvalidSubdomainLabel('test3.test.test3'));14console.log(filterInvalidSubdomainLabel('test3.test3.test'));15console.log(filterInvalidSubdomainLabel('test3.test3.test3'));16var filterInvalidSubdomainLabel = require('fast-check-monorepo').filterInvalidSubdomainLabel;17console.log(filterInvalidSubdomainLabel('test'));18console.log(filterInvalidSubdomainLabel('test3'));19console.log(filterInvalidSubdomainLabel('test.test'));20console.log(filterInvalidSubdomainLabel('test.test3'));21console.log(filterInvalidSubdomainLabel('test3.test'));22console.log(filterInvalidSubdomainLabel('test3.test3'));23console.log(filterInvalidSubdomainLabel('test.test.test'));24console.log(filterInvalidSubdomainLabel('test.test.test3'));25console.log(filterInvalidSubdomainLabel('test.test3.test'));26console.log(filterInvalidSubdomainLabel('test.test3.test3'));27console.log(filterInvalidSubdomainLabel('test3.test.test'));28console.log(filterInvalidSubdomainLabel('test3.test.test3'));29console.log(filterInvalidSubdomainLabel('test3.test3.test'));30console.log(filterInvalidSubdomainLabel('test3.test3.test3'));

Full Screen

Using AI Code Generation

copy

Full Screen

1const { filterInvalidSubdomainLabel } = require('./filterInvalidSubdomainLabel');2const fc = require('fast-check');3const { expect } = require('chai');4describe('filterInvalidSubdomainLabel', () => {5 it('should return false when the provided string is not a valid subdomain label', () => {6 fc.assert(7 fc.property(8 .string()9 .filter((s) => s.length > 0)10 .filter((s) => s.length <= 63)11 .filter((s) => !s.startsWith('-'))12 .filter((s) => !s.endsWith('-'))13 .filter((s) => s.indexOf('--') === -1)14 .filter((s) => !/[^a-z0-9-]/gi.test(s)),15 (s) => {16 expect(filterInvalidSubdomainLabel(s)).to.equal(false);17 }18 );19 });20});21const { filterInvalidSubdomainLabel } = require('./filterInvalidSubdomainLabel');22const fc = require('fast-check');23const { expect } = require('chai');24describe('filterInvalidSubdomainLabel', () => {25 it('should return true when the provided string is not a valid subdomain label', () => {26 fc.assert(27 fc.property(28 .string()29 .filter((s) => s.length > 0)30 .filter((s) => s.length <= 63)31 .filter((s) => !s.startsWith('-'))32 .filter((s) => !s.endsWith('-'))33 .filter((s) => s.indexOf('--') === -1)34 .filter((s) => !/[^a-z0-9-]/gi.test(s)),35 (s) => {36 expect(filterInvalidSubdomainLabel(s)).to.equal(true);37 }38 );39 });40});41const filterInvalidSubdomainLabel = (label) => {42 if (43 label.startsWith('-') ||44 label.endsWith('-') ||45 label.indexOf('--') !== -1 ||46 /[^a-z0-9-]/gi.test(label)47 ) {48 return false;49 }50 return true;51};52module.exports = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const fc = require('fast-check');2const { filterInvalidSubdomainLabel } = require('fast-check-monorepo/lib/check/arbitrary/DomainArbitrary.js');3const { stringOf } = require('fast-check-monorepo/lib/check/arbitrary/CharacterArbitrary.js');4const { convertToNext } = require('fast-check-monorepo/lib/check/arbitrary/definition/Converters.js');5const { convertFromNext } = require('fast-check-monorepo/lib/check/arbitrary/definition/Converters.js');6const stringOfSubdomainLabel = convertFromNext(7 filterInvalidSubdomainLabel(8 convertToNext(stringOf(fc.char())).map((s) => `${s}.`)9);10fc.assert(11 fc.property(stringOfSubdomainLabel(), (s) => {12 console.log(s);13 return true;14 })15);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');2const test = filterInvalidSubdomainLabel('test');3console.log(test);4const { filterInvalidSubdomainLabel } = require('fast-check');5const test = filterInvalidSubdomainLabel('test');6console.log(test);7const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');8const test = filterInvalidSubdomainLabel('test');9console.log(test);10{11 "compilerOptions": {12 "paths": {13 }14 },15}16{17 "compilerOptions": {18 },19}20{21 "compilerOptions": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');2const test = filterInvalidSubdomainLabel('test');3console.log(test);4const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');5const test = filterInvalidSubdomainLabel('test');6console.log(test);7const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');8const test = filterInvalidSubdomainLabel('test');9console.log(test);10const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');11const test = filterInvalidSubdomainLabel('test');12console.log(test);13const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');14const test = filterInvalidSubdomainLabel('test');15console.log(test);16const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');17const test = filterInvalidSubdomainLabel('test');18console.log(test);19const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');20const test = filterInvalidSubdomainLabel('test');21console.log(test);22const { filterInvalidSubdomainLabel } = require('fast-check-monorepo');23const test = filterInvalidSubdomainLabel('test');24console.log(test

Full Screen

Using AI Code Generation

copy

Full Screen

1var fastcheck = require("fast-check");2var label = fastcheck.filterInvalidSubdomainLabel;3console.log("label:", label);4var fastcheck = require("fast-check");5var label = fastcheck.filterInvalidSubdomainLabel;6console.log("label:", label);7var fastcheck = require("fast-check");8var label = fastcheck.filterInvalidSubdomainLabel;9console.log("label:", label);10var fastcheck = require("fast-check");11var label = fastcheck.filterInvalidSubdomainLabel;12console.log("label:", label);13var fastcheck = require("fast-check");14var label = fastcheck.filterInvalidSubdomainLabel;15console.log("label:", label);16var fastcheck = require("fast-check");

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fast-check-monorepo automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful