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

Refactor/refactor validation for emailAdress and website #122

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f95e9a6
refactor: email validation
RuthDiG Apr 16, 2024
6ddd188
fix: Email-Validation and add a test for it
RuthDiG May 6, 2024
64df3f4
fix: Website Validation and add a test for it
RuthDiG May 6, 2024
fde68a4
Merge remote-tracking branch 'origin/main' into refactor/refactor-val…
RuthDiG May 7, 2024
aa49e8a
feat: change regexp from Url
RuthDiG May 7, 2024
532278b
Merge branch 'main' into refactor/refactor-validation-for-AbstractEma…
mergify[bot] May 7, 2024
ea00966
chore: version bump
RuthDiG May 7, 2024
8b35b32
refactor: test for website
RuthDiG May 8, 2024
ee5b37b
refactor: changed wording of the test
RuthDiG May 13, 2024
7bf9bfd
refactor: Tests for Email and Website
RuthDiG May 14, 2024
76e95e1
refactor: change string in regexp
RuthDiG May 14, 2024
407b174
refactor: test for Website and AbstractURL
RuthDiG May 15, 2024
ef0e007
Merge branch 'main' into refactor/refactor-validation-for-AbstractEma…
RuthDiG May 16, 2024
24b3c14
refactor: name and AbstractURL without escape
RuthDiG May 16, 2024
73b6374
Merge branch 'main' into refactor/refactor-validation-for-AbstractEma…
RuthDiG Jun 4, 2024
a8fa603
refactor: Change Tests and RegExp
RuthDiG Jun 5, 2024
e045ae1
chore: version bump
RuthDiG Jun 5, 2024
2c2b4ed
feat: make regexp more readable
RuthDiG Jun 5, 2024
825bbee
fix: changed an error
RuthDiG Jun 5, 2024
5427a52
Merge branch 'main' into refactor/refactor-validation-for-AbstractEma…
mergify[bot] Jun 6, 2024
f1b4fdf
fix: error and last changes
RuthDiG Jun 6, 2024
151cfe4
Merge remote-tracking branch 'origin/main' into refactor/refactor-val…
RuthDiG Jun 7, 2024
b324923
feat: last changes
RuthDiG Jun 7, 2024
677088f
chore: version bump
RuthDiG Jun 7, 2024
0ce518a
fix: delete unnecessary file
RuthDiG Jun 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/content/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/content",
"version": "2.9.0",
"version": "2.9.1",
"description": "The content library defines data structures that can be transmitted using the transport library.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ export abstract class AbstractEMailAddress extends AbstractString {
@serialize()
@validate({
min: 3,
max: 100,
regExp: new RegExp("^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,}$", "i")
max: 254,
regExp: new RegExp(
"^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:[.][a-z0-9!#$%&'*+/=?^_`{|}~-]+){0,}@(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])+[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9](?:[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9])$",
"i"
)
})
public override value: string;

public static override get valueHints(): ValueHints {
return super.valueHints.copyWith({
min: 3,
max: 100,
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
pattern: "/^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,}$/i"
pattern:
"^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:[.][a-z0-9!#$%&'*+/=?^_`{|}~-]+){0,}@(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])+[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9](?:[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[a-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9])$/i"
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/content/src/attributes/types/strings/AbstractURL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export abstract class AbstractURL extends AbstractString {
max: 1024,
regExp: new RegExp(
// eslint-disable-next-line no-useless-escape
/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/
/^(?:|[A-Za-z]{3,9}:(?:\/\/)?|[:](?:\/\/)?|(?:\/\/))(?:(www[.])(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])|((?!www.)(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])))[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9])(\:[0-9]+){0,}(?:[/][\w\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df\-_?#@!\$&'\(\)\*\+,;=]{0,}){0,}$/
)
})
public override value: string;
Expand All @@ -19,7 +19,7 @@ export abstract class AbstractURL extends AbstractString {
min: 3,
max: 1024,
pattern:
"/((([A-Za-z]{3,9}:(?:\\/\\/)?)(?:[-;:&=\\+\\$,\\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\\+\\$,\\w]+@)[A-Za-z0-9.-]+)((?:\\/[\\+~%\\/.\\w\\-_]*)?\\??(?:[-\\+=&;%@.\\w_]*)#?(?:[\\w]*))?)/"
"/^(?:|[A-Za-z]{3,9}:(?://)?|[:](?://)?|(?://))(?:(www[.])(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])|((?!www.)(?:[a-z0-9\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9]){0,1}[.])))[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9](?:[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9-]{0,61}[A-Za-z\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df0-9])(:[0-9]+){0,}(?:[/][w\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00df-_?#@!$&'()*+,;=]{0,}){0,}$/"
});
}

Expand Down
59 changes: 59 additions & 0 deletions packages/content/test/attributes/EmailAddress.test.ts
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ParsingError } from "@js-soft/ts-serval";
import { EMailAddress } from "../../src";

describe("creation of RepositoryAttributes of Attribute Value Type EMailAddress", function () {
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
test("can create a RepositoryAttribute of Attribute Value Type EMailAddress", function () {
const validEMailAdress = EMailAddress.from({
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
value: "peter123@inwind.it"
});
expect(validEMailAdress.value.toString()).toBe("peter123@inwind.it");
});
test("can create a RepositoryAttribute of Attribute Value Type EMailAddress with the German 'ä' in its domain", function () {
const validEMailAdress = EMailAddress.from({
value: "peter123@inwänd.it"
});
expect(validEMailAdress.value.toString()).toBe("peter123@inwänd.it");
});
test("returns an error when trying to create an Attribute Value Type EMailAddress with a blank in the value for EMailAddress", function () {
const invalidEMailAdressCall = () => {
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
EMailAddress.from({
value: "Hugo Becker@gmx.de"
});
};
expect(invalidEMailAdressCall).toThrow(
new ParsingError(
"EMailAddress",
"value",
"Value does not match regular expression /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:[.][a-z0-9!#$%&'*+/=?^_`{|}~-]+){0,}@(?:[a-z0-9ÄäÖöÜüß](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9]){0,1}[.])+[a-zÄäÖöÜüß0-9](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9])$/i"
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
)
);
});
test("returns an error when trying to create an Attribute Value Type EMailAddress without the right ending in the value for EMailAddress", function () {
const invalidEMailAdressCall = () => {
EMailAddress.from({
value: "Becker@gmx"
});
};
expect(invalidEMailAdressCall).toThrow(
new ParsingError(
"EMailAddress",
"value",
"Value does not match regular expression /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:[.][a-z0-9!#$%&'*+/=?^_`{|}~-]+){0,}@(?:[a-z0-9ÄäÖöÜüß](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9]){0,1}[.])+[a-zÄäÖöÜüß0-9](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9])$/i"
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
)
);
});
test("returns an error when trying to create an Attribute Value Type EMailAddress with a - before the . in the value for EMailAddress", function () {
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
const invalidEMailAdressCall = () => {
EMailAddress.from({
value: "Becker@gmx-.de"
});
};
expect(invalidEMailAdressCall).toThrow(
new ParsingError(
"EMailAddress",
"value",
"Value does not match regular expression /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:[.][a-z0-9!#$%&'*+/=?^_`{|}~-]+){0,}@(?:[a-z0-9ÄäÖöÜüß](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9]){0,1}[.])+[a-zÄäÖöÜüß0-9](?:[a-zÄäÖöÜüß0-9-]{0,61}[a-zÄäÖöÜüß0-9])$/i"
)
);
});
});
79 changes: 79 additions & 0 deletions packages/content/test/attributes/Website.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { ParsingError } from "@js-soft/ts-serval";
import { Website } from "../../src";

describe("creation of RepositoryAttributes of Attribute Value Type Website", function () {
test("can create a RepositoryAttribute of Attribute Value Type Website with the beginning www.", function () {
const validWebsite = Website.from({
value: "www.inwind.it"
});
expect(validWebsite.value.toString()).toBe("www.inwind.it");
});
test("can create a RepositoryAttribute of Attribute Value Type Website", function () {
const validWebsite = Website.from({
value: "https://inwind.it"
});
expect(validWebsite.value.toString()).toBe("https://inwind.it");
});
test("can create a RepositoryAttribute of Attribute Value Type Website with the German 'ä' in its domain", function () {
const validWebsite = Website.from({
value: "https://inwänd.it"
});
expect(validWebsite.value.toString()).toBe("https://inwänd.it");
});
test("can create a RepositoryAttribute of Attribute Value Type Website without www.", function () {
Milena-Czierlinski marked this conversation as resolved.
Show resolved Hide resolved
const validWebsite = Website.from({
value: "//google.it"
});
expect(validWebsite.value.toString()).toBe("//google.it");
});
test("can create a RepositoryAttribute of Attribute Value Type Website with a enhanced path", function () {
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
const validWebsite = Website.from({
value: "https://enmeshed.de/blog/meilenstein-enmeshed-als-komponente-ablage-in-mein-bildungsraum-geht-in-die-testphase-der-beta-version/"
});
expect(validWebsite.value.toString()).toBe(
"https://enmeshed.de/blog/meilenstein-enmeshed-als-komponente-ablage-in-mein-bildungsraum-geht-in-die-testphase-der-beta-version/"
);
});
test("returns an error when trying to create an Attribute Value Type Website wich contains more than only the address of the website", function () {
const invalidWebsiteCall = () => {
Website.from({
value: "Hugo https://inwind.it"
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
});
};
expect(invalidWebsiteCall).toThrow(
new ParsingError(
"Website",
"value",
"Value does not match regular expression /^(?:|[A-Za-z]{3,9}:(?:\\/\\/)?|[:](?:\\/\\/)?|(?:\\/\\/))(?:(www[.])(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])|((?!www.)(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])))[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9])(\\:[0-9]+){0,}(?:[/][\\w\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df\\-_?#@!\\$&'\\(\\)\\*\\+,;=]{0,}){0,}$/"
)
);
});
test("returns an error when trying to create an Attribute Value Type Website without the right ending when it starts with www.", function () {
const invalidWebsiteCall = () => {
Website.from({
value: "www.google"
});
};
expect(invalidWebsiteCall).toThrow(
new ParsingError(
"Website",
"value",
"Value does not match regular expression /^(?:|[A-Za-z]{3,9}:(?:\\/\\/)?|[:](?:\\/\\/)?|(?:\\/\\/))(?:(www[.])(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])|((?!www.)(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])))[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9])(\\:[0-9]+){0,}(?:[/][\\w\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df\\-_?#@!\\$&'\\(\\)\\*\\+,;=]{0,}){0,}$/"
)
);
});
test("returns an error when trying to create an Attribute Value Type Website with a - before the . in the value for Website", function () {
RuthDiG marked this conversation as resolved.
Show resolved Hide resolved
const invalidWebsiteCall = () => {
Website.from({
value: "google-.de"
});
};
expect(invalidWebsiteCall).toThrow(
new ParsingError(
"Website",
"value",
"Value does not match regular expression /^(?:|[A-Za-z]{3,9}:(?:\\/\\/)?|[:](?:\\/\\/)?|(?:\\/\\/))(?:(www[.])(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])|((?!www.)(?:[a-z0-9\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9]){0,1}[.])))[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9](?:[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9-]{0,61}[A-Za-z\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df0-9])(\\:[0-9]+){0,}(?:[/][\\w\\u00c4\\u00e4\\u00d6\\u00f6\\u00dc\\u00fc\\u00df\\-_?#@!\\$&'\\(\\)\\*\\+,;=]{0,}){0,}$/"
)
);
});
});
4 changes: 2 additions & 2 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nmshd/runtime",
"version": "4.6.0",
"version": "4.6.1",
"description": "The enmeshed client runtime.",
"homepage": "https://enmeshed.eu",
"repository": {
Expand Down Expand Up @@ -57,7 +57,7 @@
"@js-soft/ts-serval": "2.0.10",
"@js-soft/ts-utils": "^2.3.3",
"@nmshd/consumption": "3.10.0",
"@nmshd/content": "2.9.0",
"@nmshd/content": "2.9.1",
"@nmshd/crypto": "2.0.6",
"@nmshd/transport": "2.5.0",
"ajv": "^8.13.0",
Expand Down