Pavel Gross
ee20798379
All checks were successful
DCO / DCO (pull_request) Successful in 46s
Signed-off-by: Pavel Gross <p.gross@yadro.com>
87 lines
No EOL
3 KiB
C#
87 lines
No EOL
3 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
|
|
using FrostFS.SDK.ClientV2;
|
|
using FrostFS.SDK.ClientV2.Mappers.GRPC;
|
|
|
|
namespace FrostFS.SDK.Tests;
|
|
|
|
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Default Value is correct for tests")]
|
|
public class SessionTest : SessionTestsBase
|
|
{
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public async void CreateSessionTest(bool useContext)
|
|
{
|
|
var exp = 100u;
|
|
PrmSessionCreate param;
|
|
|
|
if (useContext)
|
|
{
|
|
var ctx = new CallContext
|
|
{
|
|
CancellationToken = Mocker.CancellationTokenSource.Token,
|
|
Timeout = TimeSpan.FromSeconds(20),
|
|
OwnerId = OwnerId,
|
|
Key = ECDsaKey,
|
|
Version = Mocker.Version
|
|
};
|
|
|
|
param = new PrmSessionCreate(exp, ctx);
|
|
|
|
param.XHeaders.Add("headerKey1", "headerValue1");
|
|
}
|
|
else
|
|
{
|
|
param = new PrmSessionCreate(exp);
|
|
}
|
|
|
|
var validTimeoutFrom = DateTime.UtcNow.AddSeconds(20);
|
|
|
|
var result = await GetClient().CreateSessionAsync(param);
|
|
|
|
var validTimeoutTo = DateTime.UtcNow.AddSeconds(20);
|
|
|
|
Assert.NotNull(result);
|
|
Assert.NotNull(result.Token);
|
|
|
|
var session = new Session.SessionToken().Deserialize(result.Token);
|
|
|
|
Assert.Equal(Mocker.SessionId, session.Body.Id);
|
|
Assert.Equal(Mocker.SessionKey, session.Body.SessionKey);
|
|
|
|
Assert.Equal(OwnerId.ToMessage(), session.Body.OwnerId);
|
|
Assert.Equal(exp, session.Body.Lifetime.Exp);
|
|
Assert.Equal(exp, session.Body.Lifetime.Iat);
|
|
Assert.Equal(exp, session.Body.Lifetime.Nbf);
|
|
Assert.Null(session.Body.Container);
|
|
|
|
Assert.NotNull(Mocker.CreateSessionRequest);
|
|
|
|
Assert.Equal(OwnerId.ToMessage(), Mocker.CreateSessionRequest.Body.OwnerId);
|
|
Assert.Equal(exp, Mocker.CreateSessionRequest.Body.Expiration);
|
|
Assert.NotNull(Mocker.CreateSessionRequest.MetaHeader);
|
|
Assert.Equal(Mocker.Version.ToMessage(), Mocker.CreateSessionRequest.MetaHeader.Version);
|
|
|
|
Assert.Null(Mocker.Metadata);
|
|
|
|
if (useContext)
|
|
{
|
|
Assert.Single(Mocker.CreateSessionRequest.MetaHeader.XHeaders);
|
|
Assert.Equal(param.XHeaders.Keys[0], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Key);
|
|
Assert.Equal(param.XHeaders[param.XHeaders.Keys[0]], Mocker.CreateSessionRequest.MetaHeader.XHeaders.First().Value);
|
|
|
|
Assert.Equal(Mocker.CancellationTokenSource.Token, Mocker.CancellationToken);
|
|
Assert.NotNull(Mocker.DateTime);
|
|
|
|
Assert.True(Mocker.DateTime.Value >= validTimeoutFrom);
|
|
Assert.True(Mocker.DateTime.Value <= validTimeoutTo);
|
|
Assert.True(validTimeoutTo.Ticks >= Mocker.DateTime.Value.Ticks);
|
|
}
|
|
else
|
|
{
|
|
Assert.Empty(Mocker.CreateSessionRequest.MetaHeader.XHeaders);
|
|
Assert.Null(Mocker.DateTime);
|
|
}
|
|
}
|
|
} |