aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorpn04 <33034498+pn04@users.noreply.github.com>2022-10-13 00:36:56 +0530
committerpn04 <33034498+pn04@users.noreply.github.com>2022-10-13 00:36:56 +0530
commit66523b27f6120836ba82cfb6f56b679d7b37f58a (patch)
treea6a508162642409548ed0f928bbde36c68deb9d5 /src
parentdddcc1314d2260a21fe62e61b92f446a15357b04 (diff)
downloadslskd-66523b27f6120836ba82cfb6f56b679d7b37f58a.tar.gz
added a DirectoryIsRelative validation attribute
*added DirectoryIsRelative attribute to check if a directory is relative *added DirectoryIsRelative to ContentPath *added unit test cases
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs38
-rw-r--r--src/slskd/Core/Options.cs1
2 files changed, 39 insertions, 0 deletions
diff --git a/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs b/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs
new file mode 100644
index 00000000..e4e13bc8
--- /dev/null
+++ b/src/slskd/Common/Validation/DirectoryIsRelativeAttribute.cs
@@ -0,0 +1,38 @@
+// <copyright file="DirectoryIsRelativeAttribute.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+namespace slskd.Validation
+{
+ using System.ComponentModel.DataAnnotations;
+ using System.IO;
+
+ /// <summary>
+ /// Validates that the specified path is relative.
+ /// </summary>
+ public class DirectoryIsRelativeAttribute : ValidationAttribute
+ {
+ protected override ValidationResult IsValid(object value, ValidationContext validationContext)
+ {
+ if (Path.IsPathRooted(value?.ToString()))
+ {
+ return new ValidationResult($"The {validationContext.DisplayName} field specifies a non-realtive directory path: '{value}'.");
+ }
+
+ return ValidationResult.Success;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs
index 4c146d32..484a514b 100644
--- a/src/slskd/Core/Options.cs
+++ b/src/slskd/Core/Options.cs
@@ -1167,6 +1167,7 @@ namespace slskd
[Description("path to static web content")]
[StringLength(255, MinimumLength = 1)]
[DirectoryExists]
+ [DirectoryIsRelative]
[RequiresRestart]
public string ContentPath { get; init; } = "wwwroot";