using FrostFS.Container; using FrostFS.Session; using Google.Protobuf; using Grpc.Core; using Moq; using FrostFS.SDK.Cryptography; using FrostFS.SDK.ClientV2; using FrostFS.SDK.ModelsV2.Netmap; using FrostFS.SDK.ClientV2.Mappers.GRPC.Netmap; using FrostFS.SDK.ClientV2.Mappers.GRPC; namespace FrostFS.SDK.Tests; public class GetContainerMock(string key) : ContainerServiceBase(key) { public override Mock GetMock() { var mock = new Mock(); var grpcVersion = Version.ToGrpcMessage(); var getResponse = new GetResponse { Body = new GetResponse.Types.Body { Container = new Container.Container { Version = grpcVersion, Nonce = ByteString.CopyFrom(ContainerGuid.ToBytes()), BasicAcl = (uint)Acl, PlacementPolicy = PlacementPolicy.ToGrpcMessage() } }, MetaHeader = new ResponseMetaHeader { Version = grpcVersion, Epoch = 100, Ttl = 1 } }; getResponse.VerifyHeader = GetResponseVerificationHeader(getResponse); var metadata = new Metadata(); var getContainerResponse = new AsyncUnaryCall( Task.FromResult(getResponse), Task.FromResult(metadata), () => new Grpc.Core.Status(StatusCode.OK, string.Empty), () => metadata, () => { }); mock.Setup(x => x.GetAsync( It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) .Returns((GetRequest r, Metadata m, DateTime? dt, CancellationToken ct) => { Verifier.CheckRequest(r); return getContainerResponse; }); return mock; } private ResponseVerificationHeader GetResponseVerificationHeader(GetResponse response) { var verifyHeader = new ResponseVerificationHeader { MetaSignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = FrostFS.Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData(response.MetaHeader.ToByteArray())) }, BodySignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = FrostFS.Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData(response.GetBody().ToByteArray())) }, OriginSignature = new Refs.Signature { Key = ByteString.CopyFrom(Key.PublicKey()), Scheme = FrostFS.Refs.SignatureScheme.EcdsaRfc6979Sha256, Sign = ByteString.CopyFrom(Key.SignData([])) } }; return verifyHeader; } } // objectServiceClientMock.Setup( // x => x.Put(It.IsAny(), It.IsAny(), It.IsAny())) // .Returns((Metadata m, DateTime dt, CancellationToken ct) => // { // return new AsyncClientStreamingCall(null, null, null, null, null, null); // //IClientStreamWriter requestStream, Task responseAsync, Task responseHeadersAsync, Func getStatusFunc, Func getTrailersFunc, Action disposeAction // }); // return objectServiceClientMock; // } // } // public virtual global::FrostFS.Object.HeadResponse Head(global::FrostFS.Object.HeadRequest request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken)) // { // return Head(request, new grpc::CallOptions(headers, deadline, cancellationToken)); // } // objectServiceClientMock.Setup(x => x.Head(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) // .Returns((Object.DeleteRequest r, Metadata m, DateTime dt, CancellationToken ct) => // { // return new // { // Body = new Object.DeleteResponse.Types.Body // { // Tombstone = new Refs.Address // { // ContainerId = new Refs.ContainerID { Value = ByteString.CopyFrom([1, 2, 3]) }, // ObjectId = new Refs.ObjectID { Value = ByteString.CopyFrom([4, 5, 6]) } // } // } // }; // }); // objectServiceClientMock.Setup(x => x.Delete(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) // .Returns((Object.DeleteRequest r, Metadata m, DateTime? dt, CancellationToken ct) => // { // return new Object.DeleteResponse // { // Body = new Object.DeleteResponse.Types.Body // { // Tombstone = new Refs.Address // { // ContainerId = new Refs.ContainerID { Value = ByteString.CopyFrom([1, 2, 3]) }, // ObjectId = new Refs.ObjectID { Value = ByteString.CopyFrom([4, 5, 6]) } // } // }, // MetaHeader = new ResponseMetaHeader() // { // }, // VerifyHeader = new ResponseVerificationHeader() // { // MetaSignature = new Refs.Signature // { // Key = ByteString.CopyFrom(_key.PublicKey()), // Scheme = Refs.SignatureScheme.EcdsaRfc6979Sha256, // Sign = ByteString.CopyFrom(_key.SignData(Array.Empty())) // // ByteString.CopyFrom(_key.SignData(grpcHeader.Split.Parent.ToByteArray())), // } // } // }; // });