-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce PropertyFormat to avoid validation errors that can lead to …
…internal exceptions (#248)
- Loading branch information
Showing
27 changed files
with
243 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
backend/src/Notifo.Domain.Integrations.Abstractions/PropertyFormat.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// ========================================================================== | ||
// Notifo.io | ||
// ========================================================================== | ||
// Copyright (c) Sebastian Stehle | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
namespace Notifo.Domain.Integrations; | ||
|
||
public enum PropertyFormat | ||
{ | ||
None, | ||
Email, | ||
HttpUrl | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/Notifo.Domain.Integrations.Abstractions/Resources/Texts.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
backend/src/Notifo.Domain.Integrations.Abstractions/ValidationPatterns.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// ========================================================================== | ||
// Notifo.io | ||
// ========================================================================== | ||
// Copyright (c) Sebastian Stehle | ||
// All rights reserved. Licensed under the MIT license. | ||
// ========================================================================== | ||
|
||
namespace Notifo.Domain.Integrations; | ||
|
||
public static class ValidationPatterns | ||
{ | ||
// Taken from Yup's source code (validation library used on the front-end side). | ||
public const string Email = @"^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
backend/src/Notifo.Domain.Integrations/Resources/Texts.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,77 @@ public void Should_not_fail_if_undefined_value_is_not_an_allowed_value(string? i | |
Assert.Equal("allowed", property.GetString(source)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("localhost.com/test")] | ||
[InlineData("192.168.0.101")] | ||
[InlineData("randomString")] | ||
public void Should_fail_if_url_is_invalid(string? input) | ||
{ | ||
var source = new Dictionary<string, string> | ||
{ | ||
["key"] = input! | ||
}; | ||
|
||
var property = new IntegrationProperty("key", PropertyType.Text) | ||
{ | ||
Format = PropertyFormat.HttpUrl | ||
}; | ||
|
||
Assert.Throws<ValidationException>(() => property.GetString(source)); | ||
} | ||
|
||
[Theory] | ||
[InlineData("http://192.168.0.101/")] | ||
[InlineData("http://localhost/test")] | ||
[InlineData("https://example.com/test?query=example")] | ||
[InlineData("http://login:[email protected]/random")] | ||
public void Should_get_url_if_value_is_valid(string? input) | ||
{ | ||
var source = new Dictionary<string, string> | ||
{ | ||
["key"] = input! | ||
}; | ||
|
||
var property = new IntegrationProperty("key", PropertyType.Text) | ||
{ | ||
Format = PropertyFormat.HttpUrl | ||
}; | ||
|
||
Assert.Equal(input, property.GetString(source)); | ||
} | ||
|
||
[Fact] | ||
public void Should_fail_if_email_is_invalid() | ||
{ | ||
var source = new Dictionary<string, string> | ||
{ | ||
["key"] = "invalidEmail" | ||
}; | ||
|
||
var property = new IntegrationProperty("key", PropertyType.Text) | ||
{ | ||
Format = PropertyFormat.Email | ||
}; | ||
|
||
Assert.Throws<ValidationException>(() => property.GetString(source)); | ||
} | ||
|
||
[Fact] | ||
public void Should_get_email_if_value_is_valid() | ||
{ | ||
var source = new Dictionary<string, string> | ||
{ | ||
["key"] = "[email protected]" | ||
}; | ||
|
||
var property = new IntegrationProperty("key", PropertyType.Text) | ||
{ | ||
Format = PropertyFormat.Email | ||
}; | ||
|
||
Assert.Equal(source["key"], property.GetString(source)); | ||
} | ||
|
||
[Fact] | ||
public void Should_get_value_if_all_requirements_are_met() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.