Skip to content

Commit

Permalink
Introduce static field for the PropertyFormat to improve readability,…
Browse files Browse the repository at this point in the history
… add a test case (#251)

* Introduce static field with allowed HttpUrl schemas

* Rename HttpUrl PropertyFormat tests

* Move the using statements down to ensure consistency

* Add a non-HTTP URL test case for HttpUrl PropertyFormat
  • Loading branch information
Arciiix authored Aug 28, 2024
1 parent c9d7cf7 commit 6600430
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Notifo.Domain.Integrations;

public sealed record IntegrationProperty(string Name, PropertyType Type)
{
private static readonly string[] AllowedHttpUrlSchemes = { "http", "https" };

public string? DefaultValue { get; init; }

public string? EditorDescription { get; init; }
Expand Down Expand Up @@ -185,10 +187,7 @@ private bool TryGetString(string? input, [MaybeNullWhen(true)] out string error,

break;
case PropertyFormat.HttpUrl:
// We only allow "http" and "https" schemas to enable the usage of URL field for HttpClient requests.
if (!Uri.TryCreate(input, UriKind.Absolute, out var uri)
|| (!string.Equals(uri.Scheme, "http", StringComparison.OrdinalIgnoreCase) && !string.Equals(uri.Scheme, "https", StringComparison.OrdinalIgnoreCase))
)
if (!Uri.TryCreate(input, UriKind.Absolute, out var uri) || !AllowedHttpUrlSchemes.Contains(uri.Scheme, StringComparer.OrdinalIgnoreCase))
{
error = Texts.IntegrationPropertyFormatHttpUrl;
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public void Should_not_fail_if_undefined_value_is_not_an_allowed_value(string? i
[InlineData("localhost.com/test")]
[InlineData("192.168.0.101")]
[InlineData("randomString")]
public void Should_fail_if_url_is_invalid(string? input)
[InlineData("mqtt://localhost:1883/")]
public void Should_fail_if_http_url_is_invalid(string? input)
{
var source = new Dictionary<string, string>
{
Expand All @@ -182,7 +183,7 @@ public void Should_fail_if_url_is_invalid(string? input)
[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)
public void Should_get_http_url_if_value_is_valid(string? input)
{
var source = new Dictionary<string, string>
{
Expand Down

0 comments on commit 6600430

Please sign in to comment.