Update BlobNamingNormalizers

pull/9120/head
liangshiwei 4 years ago
parent ec035c8bde
commit 42a3cb69bc

@ -19,6 +19,12 @@ namespace Volo.Abp.BlobStoring.Aliyun
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names must be from 3 through 63 characters long.
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
// Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
@ -39,11 +45,6 @@ namespace Volo.Abp.BlobStoring.Aliyun
}
}
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
return containerName;
}
}

@ -17,6 +17,12 @@ namespace Volo.Abp.BlobStoring.Azure
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names must be from 3 through 63 characters long.
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
// Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
@ -37,11 +43,6 @@ namespace Volo.Abp.BlobStoring.Azure
}
}
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
return containerName;
}
}

@ -1,4 +1,5 @@
using System.Globalization;
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Localization;
@ -17,17 +18,28 @@ namespace Volo.Abp.BlobStoring.Minio
// All letters in a container name must be lowercase.
containerName = containerName.ToLower();
// Container names can contain only letters, numbers, and the dash (-) character.
containerName = Regex.Replace(containerName, "[^a-z0-9-]", string.Empty);
// Container names must be from 3 through 63 characters long.
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
// Bucket names can consist only of lowercase letters, numbers, dots (.), and hyphens (-).
containerName = Regex.Replace(containerName, "[^a-z0-9-.]", string.Empty);
// Every dash (-) character must be immediately preceded and followed by a letter or number;
// consecutive dashes are not permitted in container names.
// Container names must start or end with a letter or number
containerName = Regex.Replace(containerName, "-{2,}", "-");
// Bucket names must begin and end with a letter or number.
// Bucket names must not be formatted as an IP address (for example, 192.168.5.4).
// Bucket names can't start or end with hyphens adjacent to period
// Bucket names can't start or end with dots adjacent to period
containerName = Regex.Replace(containerName, "\\.{2,}", ".");
containerName = Regex.Replace(containerName, "-\\.", string.Empty);
containerName = Regex.Replace(containerName, "\\.-", string.Empty);
containerName = Regex.Replace(containerName, "^-", string.Empty);
containerName = Regex.Replace(containerName, "-$", string.Empty);
containerName = Regex.Replace(containerName, "^\\.", string.Empty);
containerName = Regex.Replace(containerName, "\\.$", string.Empty);
containerName = Regex.Replace(containerName, "^(?:(?:^|\\.)(?:2(?:5[0-5]|[0-4]\\d)|1?\\d?\\d)){4}$", String.Empty);
// Container names must be from 3 through 63 characters long.
if (containerName.Length < 3)
{
var length = containerName.Length;
@ -37,11 +49,6 @@ namespace Volo.Abp.BlobStoring.Minio
}
}
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
return containerName;
}
}

@ -54,5 +54,13 @@ namespace Volo.Abp.BlobStoring.Aliyun
filename.Length.ShouldBeLessThanOrEqualTo(63);
}
[Fact]
public void NormalizeContainerName_Max_Length_Dash()
{
var filename = "-this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a--b-p-";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a-b");
}
}
}

@ -71,5 +71,15 @@ namespace Volo.Abp.BlobStoring.Aws
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this.is.my.container.name");
}
[Fact]
public void NormalizeContainerName_Max_Length_Dash()
{
var filename = "-this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a--b-p-";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a--b");
}
}
}

@ -36,7 +36,6 @@ namespace Volo.Abp.BlobStoring.Azure
filename.ShouldBe("this-is-my-container-name");
}
[Fact]
public void NormalizeContainerName_Min_Length()
{
@ -53,5 +52,13 @@ namespace Volo.Abp.BlobStoring.Azure
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.Length.ShouldBeLessThanOrEqualTo(63);
}
[Fact]
public void NormalizeContainerName_Max_Length_Dash()
{
var filename = "-this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a--b-p-";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a-b");
}
}
}

@ -21,22 +21,21 @@ namespace Volo.Abp.BlobStoring.Minio
}
[Fact]
public void NormalizeContainerName_Only_Letters_Numbers_Dash()
public void NormalizeContainerName_Only_Letters_Numbers_Dash_Dots()
{
var filename = ",./this-i,./s-my-c,./ont,./ai+*/.=!@#$n^&*er-name.+/";
var filename = ",./this-i,/s-my-c,/ont,/ai+*/=!@#$n^&*er.name+/";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name");
filename.ShouldBe("this-is-my-container.name");
}
[Fact]
public void NormalizeContainerName_Dash()
{
var filename = "-this--is----my-container----name-";
var filename = "-this.--is-.-.-my--container---name-";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name");
filename.ShouldBe("this-is-my--container---name");
}
[Fact]
public void NormalizeContainerName_Min_Length()
{
@ -45,7 +44,6 @@ namespace Volo.Abp.BlobStoring.Minio
filename.Length.ShouldBeGreaterThanOrEqualTo(3);
}
[Fact]
public void NormalizeContainerName_Max_Length()
{
@ -53,5 +51,33 @@ namespace Volo.Abp.BlobStoring.Minio
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.Length.ShouldBeLessThanOrEqualTo(63);
}
[Fact]
public void NormalizeContainerName_Must_Not_Be_Ip_Address()
{
var filename = "192.168.5.4";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("000");
filename = "a.192.168.5.4";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("a.192.168.5.4");
}
[Fact]
public void NormalizeContainerName_Dots()
{
var filename = ".this..is.-.my.container....name.";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this.is.my.container.name");
}
[Fact]
public void NormalizeContainerName_Max_Length_Dash()
{
var filename = "-this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p-a--b-p-";
filename = _blobNamingNormalizer.NormalizeContainerName(filename);
filename.ShouldBe("this-is-my-container-name-abpabpabpabpabpabpabpabp-a-b-p--a-b");
}
}
}

Loading…
Cancel
Save