Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Adliance.AzureBlobSimulator

env:
VERSION: 1.0.0.${{ github.run_number }}
VERSION: 1.1.0.${{ github.run_number }}

on:
push:
Expand All @@ -18,7 +18,7 @@ jobs:
- name: 'Setup .NET'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '9.0.x'
dotnet-version: '10.0.x'
- name: 'Run tests'
run: dotnet test --configuration Release

Expand Down
31 changes: 0 additions & 31 deletions Adliance.AzureBlobSimulator.sln

This file was deleted.

10 changes: 10 additions & 0 deletions Adliance.AzureBlobSimulator.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Solution>
<Folder Name="/Solution Items/">
<File Path=".gitignore" />
<File Path="docker-build-push.yml" />
<File Path="dockerfile" />
<File Path="README.md" />
</Folder>
<Project Path="src/Adliance.AzureBlobSimulator/Adliance.AzureBlobSimulator.csproj" />
<Project Path="test/Adliance.AzureBlobSimulator.Tests/Adliance.AzureBlobSimulator.Tests.csproj" />
</Solution>
4 changes: 2 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
ARG VERSION=0.0.0.0
RUN dotnet tool install -g dotnet-setversion
ENV PATH="${PATH}:/root/.dotnet/tools"
Expand All @@ -7,7 +7,7 @@ WORKDIR /src/Adliance.AzureBlobSimulator
RUN setversion $VERSION
RUN dotnet publish "Adliance.AzureBlobSimulator.csproj" -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS final
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
EXPOSE 80
WORKDIR /app
ENV ASPNETCORE_HTTP_PORTS=80
Expand Down
21 changes: 9 additions & 12 deletions src/Adliance.AzureBlobSimulator/Adliance.AzureBlobSimulator.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adliance.Buddy.CodeStyle" Version="8.0.0.10" />
</ItemGroup>

</Project>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Adliance.Buddy.CodeStyle" Version="8.0.0.10" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Adliance.Buddy.CodeStyle" Version="8.0.0.10" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.27.0" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="coverlet.collector" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Testcontainers" Version="4.10.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.3">
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Adliance.AzureBlobSimulator\Adliance.AzureBlobSimulator.csproj" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public async Task Can_Get_Properties_of_Blob()
var containerPath = Path.Combine(TestStoragePath, containerName);
Directory.CreateDirectory(containerPath);
await File.WriteAllBytesAsync(Path.Combine(containerPath, blobName), "Hello World!"u8.ToArray());
;

var containerClient = BlobServiceClient.GetBlobContainerClient(containerName);
var blobClient = containerClient.GetBlobClient(blobName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,72 @@
using Azure.Storage.Blobs.Models;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;

namespace Adliance.AzureBlobSimulator.Tests.Controllers;

public class ContainersControllerTests(WebApplicationFactory<Program> factory) : ControllerTestBase(factory)
{
[Fact]
public async Task Can_Get_List_of_Containers()
public async Task GetsContainerListSuccessfully()
{
var containerNames = new[]
var containerNames = new Dictionary<string, string>
{
"container1",
"container2",
"test-container"
//<ContainerName, ContainerFolderName>
{ "container1", "folder1" },
{ "container2", "folder2" },
{ "test-container", "test-folder" }
};

foreach (var containerName in containerNames)
foreach (var containerPath in containerNames.Values.Select(folder => Path.Combine(TestStoragePath, folder)))
{
var containerPath = Path.Combine(TestStoragePath, containerName);
Directory.CreateDirectory(containerPath);
}

// create new factory to test different folder name and container name
var customFactory = Factory.WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration((_, config) =>
{
//overwrite existing config for LocalPath to prevent autodetection
var dict = new Dictionary<string, string?>
{
["Storage:LocalPath"] = Path.Combine(TestStoragePath, "empty")
};

var i = 0;
foreach (var (name, folder) in containerNames)
{
dict[$"Storage:Containers:{i}:Name"] = name;
dict[$"Storage:Containers:{i}:LocalPath"] = Path.GetFullPath(Path.Combine(TestStoragePath, folder));
i++;
}

config.AddInMemoryCollection(dict);
});
});

Directory.CreateDirectory(Path.Combine(TestStoragePath, "empty"));

var options = new Azure.Storage.Blobs.BlobClientOptions
{
Transport = new Azure.Core.Pipeline.HttpClientTransport(customFactory.CreateClient())
};
var client = new Azure.Storage.Blobs.BlobServiceClient(new Uri("http://localhost"), new Azure.Storage.StorageSharedKeyCredential(StorageAccountName, StorageAccountKey), options);

var containers = new List<BlobContainerItem>();
await foreach (var container in BlobServiceClient.GetBlobContainersAsync()) containers.Add(container);
await foreach (var container in client.GetBlobContainersAsync())
{
containers.Add(container);
}

Assert.NotEmpty(containers);
Assert.Equal(2 + containerNames.Length, containers.Count);
Assert.Equal(2 + containerNames.Count, containers.Count);
Assert.Contains(containers, c => c.Name == "$logs");
Assert.Contains(containers, c => c.Name == "$blobchangefeed");
foreach (var containerName in containerNames) Assert.Contains(containers, c => c.Name == containerName);
foreach (var (name, _) in containerNames)
{
Assert.Contains(containers, c => c.Name == name);
}
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;

namespace Adliance.AzureBlobSimulator.Tests.SharedAccessSignature;
Expand All @@ -20,41 +21,47 @@ public class SasAuthenticationMiddlewareTests

public SasAuthenticationMiddlewareTests()
{
var builder = new WebHostBuilder()
.ConfigureServices(services =>
var host = new HostBuilder()
.ConfigureWebHost(webBuilder =>
{
services.Configure<StorageOptions>(options =>
{
options.Accounts =
[
new StorageAccountOptions
webBuilder
.UseTestServer()
.ConfigureServices(services =>
{
services.Configure<StorageOptions>(options =>
{
Name = "testaccount",
Key = Convert.ToBase64String(
Encoding.UTF8.GetBytes("1234567890123456"))
}
];
});

services.AddSingleton<SasValidatorService>();
})
.Configure(app =>
{
app.UseMiddleware<SasAuthenticationMiddleware>();
options.Accounts =
[
new StorageAccountOptions
{
Name = "testaccount",
Key = Convert.ToBase64String(
Encoding.UTF8.GetBytes("1234567890123456"))
}
];
});

services.AddSingleton<SasValidatorService>();
})
.Configure(app =>
{
app.UseMiddleware<SasAuthenticationMiddleware>();

app.Run(context =>
{
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
});
app.Run(context =>
{
context.Response.StatusCode = 200;
return Task.CompletedTask;
});
});
})
.Start();

var server = new TestServer(builder);
_client = server.CreateClient();
_client = host.GetTestClient();

var options = host.Services.GetRequiredService<IOptions<StorageOptions>>();
var env = new TestHostEnvironment();
var options = server.Services.GetRequiredService<IOptions<StorageOptions>>();
var validator = new SasValidatorService(options, null, env);

_sasHelper = new SasHelper(options, validator);
}

Expand Down
Loading