Bug Fix #79 Ban '/' from serial numbers
This commit is contained in:
@@ -69,6 +69,9 @@ namespace Disco.Services
|
|||||||
// - Assigned User Id
|
// - Assigned User Id
|
||||||
// - Batch
|
// - Batch
|
||||||
|
|
||||||
|
if (d.SerialNumber.Contains("/") || d.SerialNumber.Contains(@"\"))
|
||||||
|
throw new ArgumentException(@"The device serial number cannot contain '/' or '\' characters.", nameof(d));
|
||||||
|
|
||||||
// Enforce Authorization
|
// Enforce Authorization
|
||||||
var auth = UserService.CurrentAuthorization;
|
var auth = UserService.CurrentAuthorization;
|
||||||
if (!auth.Has(Claims.Device.Properties.AssetNumber))
|
if (!auth.Has(Claims.Device.Properties.AssetNumber))
|
||||||
|
|||||||
@@ -189,9 +189,13 @@ namespace Disco.Services.Devices.Enrolment
|
|||||||
sessionId = OpenSessionId;
|
sessionId = OpenSessionId;
|
||||||
}
|
}
|
||||||
EnrolmentLog.LogSessionDeviceInfo(sessionId, Request);
|
EnrolmentLog.LogSessionDeviceInfo(sessionId, Request);
|
||||||
|
|
||||||
MacEnrolResponse response = new MacEnrolResponse();
|
MacEnrolResponse response = new MacEnrolResponse();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (Request.DeviceSerialNumber.Contains("/") || Request.DeviceSerialNumber.Contains(@"\"))
|
||||||
|
throw new EnrolmentSafeException(@"The serial number cannot contain '/' or '\' characters.");
|
||||||
|
|
||||||
EnrolmentLog.LogSessionProgress(sessionId, 10, "Querying Database");
|
EnrolmentLog.LogSessionProgress(sessionId, 10, "Querying Database");
|
||||||
Device RepoDevice = Database.Devices.Include("AssignedUser").Include("DeviceProfile").Include("DeviceProfile").Where(d => d.SerialNumber == Request.DeviceSerialNumber).FirstOrDefault();
|
Device RepoDevice = Database.Devices.Include("AssignedUser").Include("DeviceProfile").Include("DeviceProfile").Where(d => d.SerialNumber == Request.DeviceSerialNumber).FirstOrDefault();
|
||||||
if (!Trusted)
|
if (!Trusted)
|
||||||
@@ -307,6 +311,9 @@ namespace Disco.Services.Devices.Enrolment
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (Request.SerialNumber.Contains("/") || Request.SerialNumber.Contains(@"\"))
|
||||||
|
throw new EnrolmentSafeException(@"The serial number cannot contain '/' or '\' characters.");
|
||||||
|
|
||||||
EnrolmentLog.LogSessionProgress(sessionId, 10, "Loading User Data");
|
EnrolmentLog.LogSessionProgress(sessionId, 10, "Loading User Data");
|
||||||
if (!string.IsNullOrWhiteSpace(Username))
|
if (!string.IsNullOrWhiteSpace(Username))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ namespace Disco.Services.Devices.Importing.Fields
|
|||||||
{
|
{
|
||||||
parsedValue = Value.Trim();
|
parsedValue = Value.Trim();
|
||||||
if (parsedValue.Length > maxLength)
|
if (parsedValue.Length > maxLength)
|
||||||
return Error(string.Format("Cannot be more than {0} characters", maxLength));
|
return Error($"Cannot be more than {maxLength} characters");
|
||||||
|
if (parsedValue.Contains(@"/"))
|
||||||
|
return Error(@"The '/' character is not allowed.");
|
||||||
|
if (parsedValue.Contains(@"\"))
|
||||||
|
return Error(@"The '\' character is not allowed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Duplicate
|
// Duplicate
|
||||||
@@ -38,7 +42,7 @@ namespace Disco.Services.Devices.Importing.Fields
|
|||||||
.Where(r => IsDeviceSerialNumberValid(r.Item2))
|
.Where(r => IsDeviceSerialNumberValid(r.Item2))
|
||||||
.FirstOrDefault(r => r.Item2.Equals(parsedValue, StringComparison.OrdinalIgnoreCase));
|
.FirstOrDefault(r => r.Item2.Equals(parsedValue, StringComparison.OrdinalIgnoreCase));
|
||||||
if (duplicate != null)
|
if (duplicate != null)
|
||||||
return Error(string.Format("This Device Serial Number was already present on Row {0}", duplicate.Item1 + 1));
|
return Error($"This Device Serial Number was already present on Row {duplicate.Item1 + 1}");
|
||||||
|
|
||||||
// No action required
|
// No action required
|
||||||
return Success(EntityState.Unchanged);
|
return Success(EntityState.Unchanged);
|
||||||
|
|||||||
@@ -67,6 +67,10 @@ namespace Disco.Web.Controllers
|
|||||||
{
|
{
|
||||||
ModelState.AddModelError("Device.SerialNumber", "The Serial Number is Required");
|
ModelState.AddModelError("Device.SerialNumber", "The Serial Number is Required");
|
||||||
}
|
}
|
||||||
|
else if (m.Device.SerialNumber.Contains("/") || m.Device.SerialNumber.Contains(@"\"))
|
||||||
|
{
|
||||||
|
ModelState.AddModelError("Device.SerialNumber", @"The Serial Number cannot contain '/' or '\' characters");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Ensure Existing Device Doesn't Exist
|
// Ensure Existing Device Doesn't Exist
|
||||||
|
|||||||
Reference in New Issue
Block a user