mirror of https://github.com/abpframework/abp.git
committed by
GitHub
8 changed files with 324 additions and 21 deletions
@ -0,0 +1,52 @@ |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Aws; |
|||
|
|||
public class AwsBlobProviderConfiguration_Tests : AbpBlobStoringAwsTestCommonBase |
|||
{ |
|||
[Fact] |
|||
public void Should_Set_And_Get_ServiceURL() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration); |
|||
const string serviceUrl = "https://minio.example.com:9000"; |
|||
|
|||
// Act
|
|||
awsConfiguration.ServiceURL = serviceUrl; |
|||
|
|||
// Assert
|
|||
awsConfiguration.ServiceURL.ShouldBe(serviceUrl); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Return_Null_When_ServiceURL_Not_Set() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration); |
|||
|
|||
// Act & Assert
|
|||
awsConfiguration.ServiceURL.ShouldBeNull(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void Should_Configure_ServiceURL_Using_UseAws_Extension() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
const string serviceUrl = "https://spaces.digitalocean.com"; |
|||
|
|||
// Act
|
|||
containerConfiguration.UseAws(config => |
|||
{ |
|||
config.ServiceURL = serviceUrl; |
|||
config.Region = "us-east-1"; |
|||
}); |
|||
|
|||
// Assert
|
|||
var awsConfig = containerConfiguration.GetAwsConfiguration(); |
|||
awsConfig.ServiceURL.ShouldBe(serviceUrl); |
|||
} |
|||
} |
|||
@ -0,0 +1,116 @@ |
|||
using System.Threading.Tasks; |
|||
using Amazon.S3; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Shouldly; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.BlobStoring.Aws; |
|||
|
|||
public class DefaultAmazonS3ClientFactory_Tests : AbpBlobStoringAwsTestBase |
|||
{ |
|||
private readonly IAmazonS3ClientFactory _amazonS3ClientFactory; |
|||
|
|||
public DefaultAmazonS3ClientFactory_Tests() |
|||
{ |
|||
_amazonS3ClientFactory = GetRequiredService<IAmazonS3ClientFactory>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_S3Client_With_Custom_ServiceURL() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
const string serviceUrl = "https://minio.example.com:9000"; |
|||
|
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration) |
|||
{ |
|||
AccessKeyId = "test-access-key", |
|||
SecretAccessKey = "test-secret-key", |
|||
Region = "us-east-1", |
|||
ServiceURL = serviceUrl |
|||
}; |
|||
|
|||
// Act
|
|||
using var s3Client = await _amazonS3ClientFactory.GetAmazonS3Client(awsConfiguration); |
|||
|
|||
// Assert
|
|||
s3Client.ShouldNotBeNull(); |
|||
s3Client.Config.ServiceURL.ShouldBe(serviceUrl + "/"); // AWS SDK automatically appends trailing slash
|
|||
((AmazonS3Config)s3Client.Config).ForcePathStyle.ShouldBeTrue(); // Should be enabled for S3-compatible services
|
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_S3Client_Without_Custom_ServiceURL() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
|
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration) |
|||
{ |
|||
AccessKeyId = "test-access-key", |
|||
SecretAccessKey = "test-secret-key", |
|||
Region = "us-east-1" |
|||
// ServiceURL not set
|
|||
}; |
|||
|
|||
// Act
|
|||
using var s3Client = await _amazonS3ClientFactory.GetAmazonS3Client(awsConfiguration); |
|||
|
|||
// Assert
|
|||
s3Client.ShouldNotBeNull(); |
|||
s3Client.Config.ServiceURL.ShouldBeNull(); // Should use default AWS S3 service
|
|||
((AmazonS3Config)s3Client.Config).ForcePathStyle.ShouldBeFalse(); // Should be false for AWS S3
|
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Create_S3Client_Without_Region_For_S3Compatible_Services() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
|
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration) |
|||
{ |
|||
AccessKeyId = "test-access-key", |
|||
SecretAccessKey = "test-secret-key", |
|||
ServiceURL = "https://minio.example.com:9000" |
|||
// Region not set - should work for S3-compatible services
|
|||
}; |
|||
|
|||
// Act
|
|||
using var s3Client = await _amazonS3ClientFactory.GetAmazonS3Client(awsConfiguration); |
|||
|
|||
// Assert
|
|||
s3Client.ShouldNotBeNull(); |
|||
s3Client.Config.ServiceURL.ShouldBe("https://minio.example.com:9000/"); // AWS SDK automatically appends trailing slash
|
|||
((AmazonS3Config)s3Client.Config).ForcePathStyle.ShouldBeTrue(); // Should be enabled for S3-compatible services
|
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Set_Checksum_Properties_For_S3Compatible_Services() |
|||
{ |
|||
// Arrange
|
|||
var containerConfiguration = new BlobContainerConfiguration(); |
|||
|
|||
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration) |
|||
{ |
|||
AccessKeyId = "test-access-key", |
|||
SecretAccessKey = "test-secret-key", |
|||
ServiceURL = "https://r2.cloudflarestorage.com", |
|||
Region = "auto" |
|||
}; |
|||
|
|||
// Act
|
|||
using var s3Client = await _amazonS3ClientFactory.GetAmazonS3Client(awsConfiguration); |
|||
|
|||
// Assert
|
|||
s3Client.ShouldNotBeNull(); |
|||
var config = (AmazonS3Config)s3Client.Config; |
|||
config.ServiceURL.ShouldBe("https://r2.cloudflarestorage.com/"); |
|||
config.ForcePathStyle.ShouldBeTrue(); |
|||
|
|||
// Verify checksum properties are set for S3-compatible services (required for Cloudflare R2)
|
|||
// We just verify they are not null/default, indicating they have been set
|
|||
config.RequestChecksumCalculation.ShouldNotBe(default); |
|||
config.ResponseChecksumValidation.ShouldNotBe(default); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue