Browse Source

Merge pull request #9117 from abpframework/liangshiwei/blob

Blob AWS container name support dots
pull/9121/head
maliming 5 years ago
committed by GitHub
parent
commit
ec035c8bde
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs
  2. 32
      framework/test/Volo.Abp.BlobStoring.Aws.Tests/Volo/Abp/BlobStoring/Aws/DefaultAwsBlobNamingNormalizerProvider_Tests.cs

30
framework/src/Volo.Abp.BlobStoring.Aws/Volo/Abp/BlobStoring/Aws/AwsBlobNamingNormalizer.cs

@ -17,17 +17,28 @@ namespace Volo.Abp.BlobStoring.Aws
// 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 +48,6 @@ namespace Volo.Abp.BlobStoring.Aws
}
}
if (containerName.Length > 63)
{
containerName = containerName.Substring(0, 63);
}
return containerName;
}
}

32
framework/test/Volo.Abp.BlobStoring.Aws.Tests/Volo/Abp/BlobStoring/Aws/DefaultAwsBlobNamingNormalizerProvider_Tests.cs

@ -21,22 +21,21 @@ namespace Volo.Abp.BlobStoring.Aws
}
[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.Aws
filename.Length.ShouldBeGreaterThanOrEqualTo(3);
}
[Fact]
public void NormalizeContainerName_Max_Length()
{
@ -53,5 +51,25 @@ namespace Volo.Abp.BlobStoring.Aws
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");
}
}
}

Loading…
Cancel
Save