frostfs-sdk-csharp/src/FrostFS.SDK.Tests/Mocks/ContainerServiceMocks/ContainerServiceBase.cs
Pavel Gross c9a75ea025
All checks were successful
DCO / DCO (pull_request) Successful in 46s
[#24] Client: Implement pool part1
first iteration - base classes and methods

Signed-off-by: Pavel Gross <p.gross@yadro.com>
2024-10-21 10:48:00 +03:00

88 lines
2.9 KiB
C#

using System.Security.Cryptography;
using FrostFS.Container;
using FrostFS.Object;
using FrostFS.SDK.ClientV2;
using FrostFS.SDK.ClientV2.Mappers.GRPC;
using FrostFS.SDK.Cryptography;
using FrostFS.Session;
using Google.Protobuf;
using Grpc.Core;
using Moq;
namespace FrostFS.SDK.Tests;
public abstract class ServiceBase(string key)
{
public string StringKey { get; private set; } = key;
public ECDsa Key { get; private set; } = key.LoadWif();
public FrostFsVersion Version { get; set; } = DefaultVersion;
public FrostFsPlacementPolicy PlacementPolicy { get; set; } = DefaultPlacementPolicy;
public static FrostFsVersion DefaultVersion { get; } = new(2, 13);
public static FrostFsPlacementPolicy DefaultPlacementPolicy { get; } = new FrostFsPlacementPolicy(true, new FrostFsReplica(1));
#pragma warning disable CA2227 // this is specific object, should be treated as is
public Metadata? Metadata { get; set; }
#pragma warning restore CA2227
public DateTime? DateTime { get; protected set; }
public CancellationToken CancellationToken { get; protected set; }
public CancellationTokenSource CancellationTokenSource { get; protected set; } = new CancellationTokenSource();
public static Metadata ResponseMetaData => [];
protected ResponseVerificationHeader GetResponseVerificationHeader(IResponse response)
{
ArgumentNullException.ThrowIfNull(response);
var verifyHeader = new ResponseVerificationHeader
{
MetaSignature = new Refs.Signature
{
Key = ByteString.CopyFrom(Key.PublicKey()),
Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256,
Sign = ByteString.CopyFrom(Key.SignData(response.MetaHeader.ToByteArray()))
},
BodySignature = new Refs.Signature
{
Key = ByteString.CopyFrom(Key.PublicKey()),
Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256,
Sign = ByteString.CopyFrom(Key.SignData(response.GetBody().ToByteArray()))
},
OriginSignature = new Refs.Signature
{
Key = ByteString.CopyFrom(Key.PublicKey()),
Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256,
Sign = ByteString.CopyFrom(Key.SignData([]))
}
};
return verifyHeader;
}
public ResponseMetaHeader ResponseMetaHeader => new()
{
Version = Version.ToMessage(),
Epoch = 100,
Ttl = 1
};
}
public abstract class ContainerServiceBase(string key) : ServiceBase(key)
{
public Guid ContainerGuid { get; set; } = Guid.NewGuid();
public abstract Mock<ContainerService.ContainerServiceClient> GetMock();
}
public abstract class ObjectServiceBase(string key) : ServiceBase(key)
{
public abstract Mock<ObjectService.ObjectServiceClient> GetMock();
public Guid ContainerGuid { get; set; } = Guid.NewGuid();
}