Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Test 23.10.0 release. #80

Closed
wants to merge 18 commits into from
Closed
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
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
os: [ubuntu-latest]
test: [""]
configuration: [release]
docker-tag: ['ci', 'lts', 'previous-lts']
docker-tag: ['22.10.4-focal', '21.10.10-focal']
runs-on: ${{ matrix.os }}
name: build-${{ matrix.os }}/${{ matrix.framework }}/${{ matrix.docker-tag }}/EventStore.ClientAPI${{ matrix.test }}
steps:
Expand All @@ -49,10 +49,10 @@ jobs:
- name: Restore
run: |
dotnet restore
- name: Vulnerability Scan
run: |
dotnet list package --vulnerable --include-transitive --framework=${{ matrix.framework }} | tee vulnerabilities.txt
! cat vulnerabilities.txt | grep -q "has the following vulnerable packages"
# - name: Vulnerability Scan
# run: |
# dotnet list package --vulnerable --include-transitive --framework=${{ matrix.framework }} | tee vulnerabilities.txt
# ! cat vulnerabilities.txt | grep -q "has the following vulnerable packages"
- name: Compile
run: |
dotnet build --configuration ${{ matrix.configuration }} --framework ${{ matrix.framework }} src/EventStore.ClientAPI${{ matrix.test }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Net;
using System.Net.Http;
using EventStore.ClientAPI.Internal;
using EventStore.ClientAPI.SystemData;

namespace EventStore.ClientAPI {
partial class EventStoreClientAPIClusterFixture {
Expand All @@ -25,9 +26,11 @@ public IEventStoreConnection CreateConnectionWithGossipSeeds(
Func<ConnectionSettingsBuilder, ConnectionSettingsBuilder> configureSettings = default,
int port = 2113,
bool useDnsEndPoint = false,
int maxDiscoverAttempts = 1) {
int maxDiscoverAttempts = 1,
bool authenticated = true) {

var settings = (configureSettings ?? DefaultConfigureSettings)(DefaultBuilder)
var user = authenticated ? DefaultUserCredentials.Admin : null;
var settings = (configureSettings ?? DefaultConfigureSettings)(DefaultBuilder).SetDefaultUserCredentials(user)
.Build();
var gossipSeeds = GetGossipSeedEndPointsExceptFor(-1, port, useDnsEndPoint);
var clusterSettings = new ClusterSettingsBuilder()
Expand All @@ -47,7 +50,8 @@ public IEventStoreConnection CreateConnectionWithConnectionString(
bool useSsl,
string configureSettings = default,
int port = 2113,
bool useDnsEndPoint = false) {
bool useDnsEndPoint = false,
bool authenticated = true) {

var settings = configureSettings ?? DefaultConfigureSettingsForConnectionString;
var host = useDnsEndPoint ? "localhost" : IPAddress.Loopback.ToString();
Expand All @@ -65,7 +69,10 @@ public IEventStoreConnection CreateConnectionWithConnectionString(
settings += "CustomHttpMessageHandler=SkipCertificateValidation;";

var connectionString = $"GossipSeeds={gossipSeedsString};{settings}";
return EventStoreConnection.Create(connectionString);
var user = authenticated ? DefaultUserCredentials.Admin : null;
var builder = ConnectionSettings.Create()
.SetDefaultUserCredentials(user);
return EventStoreConnection.Create(connectionString, builder);
}
}
}
14 changes: 11 additions & 3 deletions test/EventStore.ClientAPI.Tests/EventStoreClientAPIFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public EventStoreClientAPIFixture() {
? _cluster.Connection
: _singleNode.Connection;

public IEventStoreConnection AnonymousConnection =>
UseCluster
? _cluster.AnonymousConnection
: _singleNode.AnonymousConnection;

public IService EventStore =>
UseCluster
? _cluster.EventStore
Expand All @@ -48,18 +53,21 @@ public IEnumerable<EventData> CreateTestEvents(int count = 1, int metadataSize =
public IEventStoreConnection CreateConnection(
Func<ConnectionSettingsBuilder, ConnectionSettingsBuilder> configureSettings,
bool useStandardPort,
int clusterMaxDiscoverAttempts = 1) =>
int clusterMaxDiscoverAttempts = 1,
bool authenticated = true) =>

UseCluster
? _cluster.CreateConnectionWithGossipSeeds(
configureSettings,
useStandardPort ? 2113 : 2118,
useDnsEndPoint: true,
maxDiscoverAttempts: clusterMaxDiscoverAttempts)
maxDiscoverAttempts: clusterMaxDiscoverAttempts,
authenticated: authenticated)
: _singleNode.CreateConnection(
configureSettings,
useStandardPort ? 1113 : 1114,
useDnsEndPoint: true);
useDnsEndPoint: true,
authenticated: authenticated);

public IEventStoreConnection CreateConnectionWithConnectionString(
string configureSettings,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using System;
using System.Net;
using EventStore.ClientAPI.SystemData;

namespace EventStore.ClientAPI {
partial class EventStoreClientAPISingleNodeFixture {
private const bool UseLoggerBridge = true;

public IEventStoreConnection CreateConnection(
Func<ConnectionSettingsBuilder, ConnectionSettingsBuilder> configureSettings = default,
int? port = default, bool useDnsEndPoint = true) {
var settings = (configureSettings ?? DefaultConfigureSettings)(DefaultBuilder).Build();
int? port = default, bool useDnsEndPoint = true, bool authenticated = true) {

UserCredentials user = authenticated ? DefaultUserCredentials.Admin : null;
var settings = (configureSettings ?? DefaultConfigureSettings)(DefaultBuilder).SetDefaultUserCredentials(user).Build();
return EventStoreConnection.Create(
settings,
useDnsEndPoint
Expand All @@ -17,14 +20,16 @@ public IEventStoreConnection CreateConnection(
}

public IEventStoreConnection CreateConnectionWithConnectionString(string configureSettings = default,
int? port = default, bool useDnsEndPoint = false) {
int? port = default, bool useDnsEndPoint = false, bool authenticated = true) {
var settings = configureSettings ?? DefaultConfigureSettingsForConnectionString;
var host = useDnsEndPoint ? "localhost" : IPAddress.Loopback.ToString();
port ??= 1113;

settings += "UseSslConnection=true;ValidateServer=false;";

return EventStoreConnection.Create($"ConnectTo=tcp://{host}:{port};{settings}");
var auth = authenticated ? "admin:changeit@" : "";

return EventStoreConnection.Create($"ConnectTo=tcp://{auth}{host}:{port};{settings}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Threading.Tasks;
using EventStore.ClientAPI.Exceptions;

namespace EventStore.ClientAPI;

public static class EventStoreConnectionTestExtensions {
public static async Task WaitForUsers(this IEventStoreConnection connection) {
int attempts = 0;
while (true) {
try {
await connection.ReadStreamEventsForwardAsync("$users", 0, 100, false, DefaultUserCredentials.Admin);
return;
} catch (NotAuthenticatedException) {
if (attempts++ > 500)
throw;
await Task.Delay(TimeSpan.FromMilliseconds(100));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Model.Builders;
using Ductus.FluentDocker.Services;
using EventStore.ClientAPI.Exceptions;
using EventStore.ClientAPI.SystemData;
using Polly;
using Xunit;

Expand All @@ -18,6 +20,7 @@ public partial class EventStoreClientAPISingleNodeFixture : IAsyncLifetime {
private readonly IContainerService _eventStore;

public IEventStoreConnection Connection { get; }
public IEventStoreConnection AnonymousConnection { get; }
public IContainerService EventStore => _eventStore;

public EventStoreClientAPISingleNodeFixture() {
Expand All @@ -41,7 +44,8 @@ public EventStoreClientAPISingleNodeFixture() {
.ExposePort(2113, 2113)
.MountVolume(HostCertificatePath, "/etc/eventstore/certs", MountType.ReadOnly)
.Build();
Connection = CreateConnection(settings => settings.UseSsl(true).DisableServerCertificateValidation(), 1113);
Connection = CreateConnection(settings => settings.UseSsl(true).SetDefaultUserCredentials(DefaultUserCredentials.Admin).DisableServerCertificateValidation(), 1113);
AnonymousConnection = CreateConnection(settings => settings.UseSsl(true).DisableServerCertificateValidation(), 1113, authenticated: false);
}

public async Task InitializeAsync() {
Expand Down Expand Up @@ -70,10 +74,13 @@ await Policy.Handle<Exception>()
throw;
}
await Connection.ConnectAsync();
await Connection.WaitForUsers();
await AnonymousConnection.ConnectAsync();
}

public Task DisposeAsync() {
Connection.Dispose();
AnonymousConnection.Dispose();
_eventStore.Dispose();
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public partial class EventStoreClientAPIClusterFixture : IAsyncLifetime {
private readonly ICompositeService _eventStoreCluster;

public IEventStoreConnection Connection { get; }
public IEventStoreConnection AnonymousConnection { get; }
public ICompositeService EventStore => _eventStoreCluster;

public EventStoreClientAPIClusterFixture() {
_eventStoreCluster = BuildCluster();
Connection = CreateConnectionWithConnectionString(useSsl: true);
AnonymousConnection = CreateConnectionWithConnectionString(useSsl: true, authenticated: false);
}

private ICompositeService BuildCluster() {
Expand Down Expand Up @@ -66,10 +68,13 @@ await Policy.Handle<Exception>()
throw;
}
await Connection.ConnectAsync();
await Connection.WaitForUsers();
await AnonymousConnection.ConnectAsync();
}

public Task DisposeAsync() {
Connection.Dispose();
AnonymousConnection.Dispose();
_eventStoreCluster.Stop();
_eventStoreCluster.Dispose();
return Task.CompletedTask;
Expand Down
16 changes: 11 additions & 5 deletions test/EventStore.ClientAPIAcceptanceTests/connect.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System.Threading.Tasks;
using EventStore.ClientAPI.Exceptions;
using Polly;
using Xunit;

namespace EventStore.ClientAPI {
public class connect : EventStoreClientAPITest {

Check warning on line 8 in test/EventStore.ClientAPIAcceptanceTests/connect.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu-latest/net7.0/22.10.4-focal/EventStore.ClientAPI

The type name 'connect' only contains lower-cased ascii characters. Such names may become reserved for the language.

Check warning on line 8 in test/EventStore.ClientAPIAcceptanceTests/connect.cs

View workflow job for this annotation

GitHub Actions / build-ubuntu-latest/net7.0/21.10.10-focal/EventStore.ClientAPI

The type name 'connect' only contains lower-cased ascii characters. Such names may become reserved for the language.
private readonly EventStoreClientAPIFixture _fixture;

public connect(EventStoreClientAPIFixture fixture) {
Expand Down Expand Up @@ -129,6 +130,7 @@
useStandardPort: true,
useDnsEndPoint: false);
await connection.ConnectAsync().WithTimeout();
await connection.WaitForUsers();
var writeResult =
await connection.AppendToStreamAsync(streamName, ExpectedVersion.Any, _fixture.CreateTestEvents());
Assert.True(writeResult.LogPosition.PreparePosition > 0);
Expand All @@ -146,17 +148,19 @@
using var connection = _fixture.CreateConnection(
builder => builder.UseSsl(true)
.DisableServerCertificateValidation()
.WithConnectionTimeoutOf(TimeSpan.FromSeconds(10))
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(20))
.WithConnectionTimeoutOf(TimeSpan.FromSeconds(20))
.SetReconnectionDelayTo(TimeSpan.FromMilliseconds(40))
.KeepReconnecting()
.KeepRetrying()
.FailOnNoServerResponse(),
.FailOnNoServerResponse()
.SetDefaultUserCredentials(DefaultUserCredentials.Admin),
useStandardPort: true,
clusterMaxDiscoverAttempts: -1);

connection.Disconnected += (_, _) => disconnectedSource.TrySetResult(true);

await connection.ConnectAsync().WithTimeout();
await connection.WaitForUsers();

// can definitely write without throwing
await WriteAnEventAsync().WithTimeout();
Expand All @@ -172,13 +176,15 @@

_fixture.EventStore.Start();

await connection.WaitForUsers();

// same writeTask can complete now by reconnecting and retrying
var writeResult = await writeTask.WithTimeout(TimeSpan.FromMilliseconds(100 * 1000));
var writeResult = await writeTask.WithTimeout(TimeSpan.FromMilliseconds(120 * 1000));

Assert.True(writeResult.LogPosition.PreparePosition > 0);

Task<WriteResult> WriteAnEventAsync() => connection
.AppendToStreamAsync(streamName, ExpectedVersion.Any, _fixture.CreateTestEvents());
.AppendToStreamAsync(streamName, ExpectedVersion.Any, _fixture.CreateTestEvents(), DefaultUserCredentials.Admin);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public connect_to_persistent_subscription(EventStoreClientAPIFixture fixture) {
[Fact]
public async Task that_does_not_exist_throws() {
var streamName = GetStreamName();
var connection = _fixture.Connection;
var connection = _fixture.AnonymousConnection;

var ex = await Record.ExceptionAsync(() => connection.ConnectToPersistentSubscriptionAsync(
streamName, Group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public create_persistent_subscription(EventStoreClientAPIFixture fixture) {
[Fact]
public async Task without_credentials_throws() {
var streamName = GetStreamName();
var connection = _fixture.Connection;
var connection = _fixture.AnonymousConnection;

await Assert.ThrowsAsync<AccessDeniedException>(() => connection.CreatePersistentSubscriptionAsync(
streamName, Group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public delete_persistent_subscription(EventStoreClientAPIFixture fixture) {
[Fact]
public async Task without_credentials_fails() {
var streamName = GetStreamName();
var connection = _fixture.Connection;
var connection = _fixture.AnonymousConnection;

await connection.CreatePersistentSubscriptionAsync(streamName, Group,
PersistentSubscriptionSettings.Create(), DefaultUserCredentials.Admin).WithTimeout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task writes_to_the_correct_stream() {

[Fact]
public async Task without_permission_throws() {
var connection = _fixture.Connection;
var connection = _fixture.AnonymousConnection;
await Assert.ThrowsAsync<AccessDeniedException>(() => connection.SetSystemSettingsAsync(new SystemSettings(
new StreamAcl(
Guid.NewGuid().ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public update_persistent_subscription(EventStoreClientAPIFixture fixture) {
[Fact]
public async Task without_credentials_throws() {
var streamName = GetStreamName();
var connection = _fixture.Connection;
var connection = _fixture.AnonymousConnection;

await connection.CreatePersistentSubscriptionAsync(streamName, Group,
PersistentSubscriptionSettings.Create(), DefaultUserCredentials.Admin).WithTimeout();
Expand Down
Loading