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

Introduce static field for the PropertyFormat to improve readability, add a test case #251

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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