too much for one commit

This commit is contained in:
Nils Blomgren
2026-05-13 14:01:32 +02:00
parent a96dd33039
commit 328d494530
394 changed files with 98104 additions and 78 deletions

View File

@@ -0,0 +1,116 @@
using EntKube.Clusters.Infrastructure.Cleura;
using FluentAssertions;
using System.Text.Json;
namespace EntKube.Clusters.Tests.Features;
public class CleuraObjectStorageTests
{
[Fact]
public void ParseKeystoneTokenResponse_ExtractsUserId()
{
// After authenticating with Keystone, the response includes the user ID
// which is needed to create EC2 credentials.
string json = """
{
"token": {
"user": {
"id": "abc123",
"name": "testuser",
"domain": { "id": "domainid", "name": "CCP_Domain_1_268" }
},
"catalog": [],
"expires_at": "2026-05-08T12:00:00Z"
}
}
""";
KeystoneTokenResponse? response = JsonSerializer.Deserialize<KeystoneTokenResponse>(json,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
response.Should().NotBeNull();
response!.Token.User.Id.Should().Be("abc123");
response.Token.User.Name.Should().Be("testuser");
}
[Fact]
public void ParseEc2CredentialResponse_ExtractsAccessAndSecret()
{
// Creating EC2 credentials returns the access/secret key pair
// that serves as S3-compatible credentials.
string json = """
{
"credential": {
"access": "AKIAIOSFODNN7EXAMPLE",
"secret": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"user_id": "abc123",
"project_id": "project456",
"tenant_id": "project456"
}
}
""";
Ec2CredentialResponse? response = JsonSerializer.Deserialize<Ec2CredentialResponse>(json,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
response.Should().NotBeNull();
response!.Credential.Access.Should().Be("AKIAIOSFODNN7EXAMPLE");
response.Credential.Secret.Should().Be("wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY");
response.Credential.ProjectId.Should().Be("project456");
}
[Fact]
public void S3EndpointUrl_ForRegion_FormatsCorrectly()
{
// Cleura S3 endpoints follow the pattern https://s3-{region}.citycloud.com
string endpoint = CleuraS3Client.GetS3Endpoint("Sto2");
endpoint.Should().Be("https://s3-sto2.citycloud.com");
}
[Fact]
public void S3EndpointUrl_ForFra1_FormatsCorrectly()
{
string endpoint = CleuraS3Client.GetS3Endpoint("Fra1");
endpoint.Should().Be("https://s3-fra1.citycloud.com");
}
[Fact]
public void ParseEc2CredentialListResponse_ReturnsMultiple()
{
// Listing credentials returns all existing EC2 credential pairs for the user/project.
string json = """
{
"credentials": [
{
"access": "KEY1",
"secret": "SECRET1",
"user_id": "u1",
"project_id": "p1",
"tenant_id": "p1"
},
{
"access": "KEY2",
"secret": "SECRET2",
"user_id": "u1",
"project_id": "p2",
"tenant_id": "p2"
}
]
}
""";
Ec2CredentialListResponse? response = JsonSerializer.Deserialize<Ec2CredentialListResponse>(json,
new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
response.Should().NotBeNull();
response!.Credentials.Should().HaveCount(2);
response.Credentials[0].Access.Should().Be("KEY1");
response.Credentials[1].ProjectId.Should().Be("p2");
}
}