diff --git a/backend/src/Notifo.Domain.Integrations.Abstractions/IntegrationProperty.cs b/backend/src/Notifo.Domain.Integrations.Abstractions/IntegrationProperty.cs index 80db4098..7dd9f64e 100644 --- a/backend/src/Notifo.Domain.Integrations.Abstractions/IntegrationProperty.cs +++ b/backend/src/Notifo.Domain.Integrations.Abstractions/IntegrationProperty.cs @@ -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; } @@ -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; diff --git a/backend/tests/Notifo.Domain.Tests/Integrations/IntegrationPropertyTests.cs b/backend/tests/Notifo.Domain.Tests/Integrations/IntegrationPropertyTests.cs index 2e41cdc5..9b647ea9 100644 --- a/backend/tests/Notifo.Domain.Tests/Integrations/IntegrationPropertyTests.cs +++ b/backend/tests/Notifo.Domain.Tests/Integrations/IntegrationPropertyTests.cs @@ -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 { @@ -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:password@test.pl/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 {