Skip to content

Commit

Permalink
fix(validation): validator for looser validation on account names (#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-cahill committed Nov 22, 2022
1 parent 13934b6 commit 93d6859
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/dependency-manager/spec/utils/slugs.ts
Expand Up @@ -17,6 +17,10 @@ export class Slugs {
public static ArchitectSlugRegexBase = `(?!-)(?!.{0,${Slugs.SLUG_CHAR_LIMIT}}--)[a-z0-9-]{1,${Slugs.SLUG_CHAR_LIMIT}}(?<!-)`;
public static ArchitectSlugValidator = new RegExp(`^${Slugs.ArchitectSlugRegexBase}$`);

public static ArchitectSlugDescriptionCaseInsensitive = `must contain only alphanumeric and single hyphens or underscores in the middle; max length ${Slugs.SLUG_CHAR_LIMIT}`;
public static ArchitectSlugRegexBaseCaseInsensitive = `(?!-)(?!.{0,${Slugs.SLUG_CHAR_LIMIT}}--)[A-Za-z0-9-]{1,${Slugs.SLUG_CHAR_LIMIT}}(?<!-)`;
public static ArchitectSlugValidatorCaseInsensitive = new RegExp(`^${Slugs.ArchitectSlugRegexBaseCaseInsensitive}$`);

public static LabelMax = 63;
public static LabelSlugDescription = `max length ${Slugs.LabelMax} characters, must begin and end with an alphanumeric character ([a-z0-9A-Z]), could contain dashes (-), underscores (_), dots (.), and alphanumerics between.`;
public static LabelValueSlugRegexNoMaxLength = '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?';
Expand Down
30 changes: 28 additions & 2 deletions test/dependency-manager/utils/slug-validators.test.ts
Expand Up @@ -18,6 +18,13 @@ describe('slugs validators', () => {
'2',
];

const case_insensitive_valid_slugs = [
...valid_slugs,
'MyUsername',
'anOtherUs3rn4me',
'Dashed-Username'
];

const valid_tags = [
valid_tag,
'1-0-0',
Expand Down Expand Up @@ -54,13 +61,20 @@ describe('slugs validators', () => {
'other;punctuation',
];

const invalid_slugs = [
const case_insensitive_invalid_slugs = [
invalid_slug,
'-leading-dashes',
'trailingdashes-',
'something-33-characters-loooooong',
'other.punctuation',
...globally_invalid_punctuation
...globally_invalid_punctuation,
];

const invalid_slugs = [
'MyUsername',
'anOtherUs3rn4me',
'Dashed-Username',
...case_insensitive_invalid_slugs,
];

const invalid_tags = [
Expand All @@ -80,6 +94,18 @@ describe('slugs validators', () => {
}
});

it(`valid slugs are acceptable to ArchitectSlugValidatorCaseInsensitive`, async () => {
for (const slug of case_insensitive_valid_slugs) {
expect(Slugs.ArchitectSlugValidatorCaseInsensitive.test(slug)).to.be.true
}
});

it(`invalid slugs are NOT acceptable to ArchitectSlugValidatorCaseInsensitive`, async () => {
for (const slug of case_insensitive_invalid_slugs) {
expect(Slugs.ArchitectSlugValidatorCaseInsensitive.test(slug)).to.be.false
}
});

it(`valid tags are acceptable to ComponentTagValidator`, async () => {
for (const tag of valid_tags) {
expect(Slugs.ComponentTagValidator.test(tag)).to.be.true
Expand Down

0 comments on commit 93d6859

Please sign in to comment.