Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ public static IEnumerable<PolicyVerificationParameters> PolicyTests()
yield return CreateOperation(Operations.Node.Options);
yield return CreateOperation(Operations.Node.Statistics.Read);
yield return CreateOperation(Operations.Node.Statistics.Replication);
yield return CreateOperation(Operations.Node.Statistics.Tcp);
yield return CreateOperation(Operations.Node.Statistics.Custom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using EventStore.Core.Bus;
using EventStore.Core.Certificates;
using EventStore.Core.Messaging;
using EventStore.Core.Tests.Services.Transport.Tcp;
using EventStore.Core.Tests.Helpers;
using Microsoft.AspNetCore.Builder;

namespace EventStore.Core.Tests.ClientOperations;
Expand All @@ -26,8 +26,8 @@ public void CreateTestNode()
var options = new ClusterVNodeOptions()
.ReduceMemoryUsageForTests()
.RunOnDisk(_dbPath)
.Secure(new X509Certificate2Collection(ssl_connections.GetRootCertificate()),
ssl_connections.GetServerCertificate());
.Secure(new X509Certificate2Collection(TestCertificates.GetRootCertificate()),
TestCertificates.GetServerCertificate());
_node = new ClusterVNode<TStreamId>(options, logFormatFactory,
new AuthenticationProviderFactory(
c => new InternalAuthenticationProviderFactory(c, options.DefaultUser)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using EventStore.ClientAPI.Common.Utils;
using EventStore.Common.Utils;
using EventStore.Core.Data;
using EventStore.Core.Messages;
using EventStore.Core.Messaging;
Expand Down
66 changes: 66 additions & 0 deletions src/EventStore.Core.Tests/Helpers/TestCertificates.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Net;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace EventStore.Core.Tests.Helpers;

public static class TestCertificates
{
private static readonly X509Certificate2 Root = CreateRootCertificate("Test Root CA");
private static readonly X509Certificate2 Server = CreateServerCertificate("localhost", Root);
private static readonly X509Certificate2 OtherServer = CreateServerCertificate("other-node", Root);
private static readonly X509Certificate2 UntrustedRoot = CreateRootCertificate("Untrusted Test Root CA");
private static readonly X509Certificate2 Untrusted = CreateServerCertificate("untrusted", UntrustedRoot);

public static X509Certificate2 GetRootCertificate() =>
X509CertificateLoader.LoadCertificate(Root.Export(X509ContentType.Cert));

public static X509Certificate2 GetServerCertificate() => CloneWithPrivateKey(Server);

public static X509Certificate2 GetOtherServerCertificate() => CloneWithPrivateKey(OtherServer);

public static X509Certificate2 GetUntrustedCertificate() => CloneWithPrivateKey(Untrusted);

private static X509Certificate2 CreateRootCertificate(string commonName)
{
using var key = RSA.Create(2048);
var request = new CertificateRequest(
$"CN={commonName}", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
request.CertificateExtensions.Add(new X509BasicConstraintsExtension(true, false, 0, true));
request.CertificateExtensions.Add(new X509KeyUsageExtension(
X509KeyUsageFlags.KeyCertSign | X509KeyUsageFlags.CrlSign, true));
request.CertificateExtensions.Add(new X509SubjectKeyIdentifierExtension(request.PublicKey, false));

using var certificate = request.CreateSelfSigned(
DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddYears(1));
return CloneWithPrivateKey(certificate);
}

private static X509Certificate2 CreateServerCertificate(string commonName, X509Certificate2 issuer)
{
using var key = RSA.Create(2048);
var request = new CertificateRequest(
$"CN={commonName}", key, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
request.CertificateExtensions.Add(new X509BasicConstraintsExtension(false, false, 0, true));
request.CertificateExtensions.Add(new X509KeyUsageExtension(
X509KeyUsageFlags.DigitalSignature | X509KeyUsageFlags.KeyEncipherment, true));
request.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(
[new Oid("1.3.6.1.5.5.7.3.1"), new Oid("1.3.6.1.5.5.7.3.2")], true));
var names = new SubjectAlternativeNameBuilder();
names.AddDnsName(commonName);
names.AddDnsName("localhost");
names.AddIpAddress(IPAddress.Loopback);
request.CertificateExtensions.Add(names.Build());

var serial = RandomNumberGenerator.GetBytes(16);
using var certificate = request.Create(
issuer, DateTimeOffset.UtcNow.AddDays(-1), DateTimeOffset.UtcNow.AddMonths(6), serial);
using var certificateWithKey = certificate.CopyWithPrivateKey(key);
return CloneWithPrivateKey(certificateWithKey);
}

private static X509Certificate2 CloneWithPrivateKey(X509Certificate2 certificate) =>
X509CertificateLoader.LoadPkcs12(
certificate.Export(X509ContentType.Pkcs12), string.Empty, X509KeyStorageFlags.Exportable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ private void ProcessWrite<T>(IEnvelope envelope, Guid correlationId, string stre
_streams[streamId] = list;
}

if (expectedVersion != EventStore.ClientAPI.ExpectedVersion.Any)
if (expectedVersion != EventStore.Core.Data.ExpectedVersion.Any)
{
if (expectedVersion != list.Count - 1)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using EventStore.ClientAPI;
using EventStore.Core.Tests.ClientAPI.Helpers;
using EventStore.Core.Tests.Helpers;
using Grpc.Health.V1;
using Grpc.Net.Client;
Expand Down Expand Up @@ -128,11 +126,5 @@ private async Task StartNodeAndWaitForReadiness()
{
await _node.Start();
_nodeStarted = true;
await _node.WaitForTcpEndPoint().WithTimeout(ReadinessTimeout);

using var connection = await TestConnectionLifecycle.ReconnectUntilReady(
() => TestConnection.CreateMiniNodeClient(_node.TcpEndPoint),
conn => conn.ReadAllEventsForwardAsync(Position.Start, 1, false, DefaultData.AdminCredentials),
ReadinessTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Threading.Tasks;
using EventStore.Client;
using EventStore.Client.Streams;
using EventStore.ClientAPI;
using EventStore.ClientAPI.SystemData;
using EventStore.Core.Services.Transport.Grpc;
using Google.Protobuf;
using Grpc.Core;
Expand Down Expand Up @@ -94,38 +92,4 @@ await call.RequestStream.WriteAsync(new AppendReq
public void work() => Assert.AreEqual(StatusCode.OK, _status.StatusCode);
}

[TestFixture(typeof(LogFormat.V2), typeof(string))]
public class via_tcp_should : authenticated_requests_made_from_a_follower<TLogFormat, TStreamId>
{
private Exception _caughtException;

protected override async Task Given()
{
var node = GetFollowers()[0];
await Task.WhenAll(node.AdminUserCreated, node.Started);

using var connection = EventStoreConnection.Create(ConnectionSettings.Create()
.DisableServerCertificateValidation()
.PreferFollowerNode(),
node.ExternalTcpEndPoint);
await connection.ConnectAsync();

try
{
await connection.AppendToStreamAsync(ProtectedStream, ExpectedVersion.NoStream,
new UserCredentials("admin", "changeit"),
new EventData(Guid.NewGuid(), "-", false, Array.Empty<byte>(), Array.Empty<byte>()));
}
catch (Exception ex)
{
_caughtException = ex;
}

await base.Given();
}

[Test]
[Retry(5)]
public void work() => Assert.Null(_caughtException);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using EventStore.ClientAPI;
using EventStore.ClientAPI.SystemData;
using EventStore.Core.Bus;
using EventStore.Core.Tests.Helpers;
using NUnit.Framework;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ private async Task<Guid> GetLastEpochId(Guid? previousEpochId)
IndexDirectory = GetFilePathFor("epoch-index"),
});

await _node.WaitForTcpEndPoint().WaitAsync(RestartTimeout);
var wait = Stopwatch.StartNew();
while (wait.Elapsed < RestartTimeout)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EventStore.ClientAPI;
using EventStore.ClientAPI.Common;
using EventStore.Core.Bus;
using EventStore.Core.Data;
using EventStore.Core.Helpers;
Expand All @@ -15,10 +13,10 @@
using EventStore.Core.Messages;
using EventStore.Core.Messaging;
using EventStore.Core.Metrics;
using EventStore.Core.Services;
using EventStore.Core.Services.PersistentSubscription;
using EventStore.Core.Services.PersistentSubscription.ConsumerStrategy;
using EventStore.Core.Services.Storage.ReaderIndex;
using EventStore.Core.Tests.ClientAPI;
using EventStore.Core.Tests.Services.Replication;
using EventStore.Core.Tests.TransactionLog;
using EventStore.Core.TransactionLog.LogRecords;
Expand Down Expand Up @@ -2606,58 +2604,6 @@ public void retrying_parked_messages_with_stop_at_replays_parkedEvents_until_tha
}
}

[Ignore("very long test")]
[TestFixture(typeof(LogFormat.V2), typeof(string))]
public class DeadlockTest<TLogFormat, TStreamId> : SpecificationWithMiniNode<TLogFormat, TStreamId>
{
protected override Task Given()
{
_conn = BuildConnection(_node);
return _conn.ConnectAsync();
}

protected override Task When() => Task.CompletedTask;

[Test]
public async Task read_whilst_ack_doesnt_deadlock_with_request_response_dispatcher()
{
var persistentSubscriptionSettings = PersistentSubscriptionSettings.Create().Build();
var userCredentials = DefaultData.AdminCredentials;
await _conn.CreatePersistentSubscriptionAsync("TestStream", "TestGroup", persistentSubscriptionSettings,
userCredentials);

const int count = 5000;
await _conn.AppendToStreamAsync("TestStream", ExpectedVersion.Any, CreateEvent().Take(count));


var received = 0;
var manualResetEventSlim = new ManualResetEventSlim();
var sub1 = _conn.ConnectToPersistentSubscription("TestStream", "TestGroup", (sub, ev) =>
{
received++;
if (received == count)
{
manualResetEventSlim.Set();
}

return Task.CompletedTask;
},
(sub, reason, ex) => { });
Assert.IsTrue(manualResetEventSlim.Wait(TimeSpan.FromSeconds(30)),
"Failed to receive all events in 2 minutes. Assume event store is deadlocked.");
sub1.Stop(TimeSpan.FromSeconds(10));
_conn.Close();
}

private static IEnumerable<EventData> CreateEvent()
{
while (true)
{
yield return new EventData(Guid.NewGuid(), "testtype", false, new byte[0], new byte[0]);
}
}
}

public class CheckpointingWithSkippedEvents
{
[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace EventStore.Core.Tests.Services.Replication.LeaderReplication;

public class when_non_tcp_replica_subscribes : WithReplicationService
public class when_replica_subscribes : WithReplicationService
{
private static readonly ReplicationSessionStatistics Statistics = new(
SendQueueSize: 7,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using EventStore.ClientAPI.Common.Utils;
using EventStore.Common.Utils;
using EventStore.Core.Bus;
using EventStore.Core.Data;
using EventStore.Core.Messages;
Expand Down
Loading
Loading