mirror of https://github.com/abpframework/abp.git
committed by
GitHub
10 changed files with 519 additions and 29 deletions
@ -1 +1,25 @@ |
|||||
namespace Volo.Abp.BlobStoring.Aws; |
namespace Volo.Abp.BlobStoring.Aws; |
||||
|
|
||||
|
/* |
||||
|
To run this integration test, populate user secrets (id `9f0d2c00-80c1-435b-bfab-2c39c8249091`) |
||||
|
with credentials for real AWS S3 or an S3-compatible service (Cloudflare R2, MinIO, etc.): |
||||
|
|
||||
|
{ |
||||
|
"Aws:AccessKeyId": "...", |
||||
|
"Aws:SecretAccessKey": "...", |
||||
|
"Aws:Region": "us-east-1", // "auto" for Cloudflare R2
|
||||
|
"Aws:ServiceURL": "", // e.g. https://<account>.r2.cloudflarestorage.com for R2, http://localhost:9000 for MinIO
|
||||
|
"Aws:DisablePayloadSigning": "false", // set "true" for R2 (requires HTTPS); leave "false" for MinIO and AWS S3
|
||||
|
"Aws:ContainerName": "", // leave empty to let the test create a unique bucket; set to a pre-existing bucket for services that disallow bucket creation
|
||||
|
"Aws:CreateContainerIfNotExists": "true" // set "false" when using an existing bucket
|
||||
|
} |
||||
|
|
||||
|
When `ContainerName` is supplied, the test prefixes every object with `abp-aws-test-run-{guid}/` |
||||
|
so cleanup deletes only what this run created (the bucket itself is left untouched). |
||||
|
|
||||
|
Then uncomment the class below: |
||||
|
|
||||
|
public class AwsBlobContainer_Tests : BlobContainer_Tests<AbpBlobStoringAwsTestModule> |
||||
|
{ |
||||
|
} |
||||
|
*/ |
||||
|
|||||
@ -0,0 +1,72 @@ |
|||||
|
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); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_Default_DisablePayloadSigning_To_False() |
||||
|
{ |
||||
|
var containerConfiguration = new BlobContainerConfiguration(); |
||||
|
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration); |
||||
|
|
||||
|
awsConfiguration.DisablePayloadSigning.ShouldBeFalse(); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public void Should_Set_And_Get_DisablePayloadSigning() |
||||
|
{ |
||||
|
var containerConfiguration = new BlobContainerConfiguration(); |
||||
|
var awsConfiguration = new AwsBlobProviderConfiguration(containerConfiguration); |
||||
|
|
||||
|
awsConfiguration.DisablePayloadSigning = true; |
||||
|
|
||||
|
awsConfiguration.DisablePayloadSigning.ShouldBeTrue(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,114 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
using Amazon.Runtime; |
||||
|
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?.TrimEnd('/').ShouldBe(serviceUrl); |
||||
|
((AmazonS3Config)s3Client.Config).ForcePathStyle.ShouldBeTrue(); |
||||
|
} |
||||
|
|
||||
|
[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?.TrimEnd('/').ShouldBe("https://minio.example.com:9000"); |
||||
|
((AmazonS3Config)s3Client.Config).ForcePathStyle.ShouldBeTrue(); |
||||
|
} |
||||
|
|
||||
|
[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?.TrimEnd('/').ShouldBe("https://r2.cloudflarestorage.com"); |
||||
|
config.ForcePathStyle.ShouldBeTrue(); |
||||
|
config.RequestChecksumCalculation.ShouldBe(RequestChecksumCalculation.WHEN_REQUIRED); |
||||
|
config.ResponseChecksumValidation.ShouldBe(ResponseChecksumValidation.WHEN_REQUIRED); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue