Skip to content

Commit

Permalink
modified the secure-with-tls sample connstring
Browse files Browse the repository at this point in the history
  • Loading branch information
RagingKore committed Dec 7, 2023
1 parent 5586432 commit 9085fd7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion samples/secure-with-tls/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// take the address from environment variable (when run with Docker) or use localhost by default
var connectionString = Environment.GetEnvironmentVariable("ESDB__CONNECTION__STRING")
?? "esdb://admin:changeit@localhost:2113?tls=true";
?? "esdb://admin:changeit@localhost:2113?tls=true&tlsVerifyCert=false";

Console.WriteLine($"Connecting to EventStoreDB at: {connectionString}");

Expand Down
2 changes: 1 addition & 1 deletion samples/secure-with-tls/docker-compose.app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
build: ./
environment:
# URL should match the DNS name in certificate and container name
- ESDB__CONNECTION__STRING=esdb://admin:changeit@eventstore:2113?Tls=true
- ESDB__CONNECTION__STRING=esdb://admin:changeit@eventstore:2113?Tls=true&tlsVerifyCert=false
depends_on:
eventstore:
condition: service_healthy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace EventStore.Client.Streams.Tests;

[Trait("Category", "Stream")]
public class subscribe_to_stream (ITestOutputHelper output, SubscriptionsFixture fixture) : EventStoreTests<SubscriptionsFixture>(output, fixture) {
public class subscribe_to_stream(ITestOutputHelper output, SubscriptionsFixture fixture) : EventStoreTests<SubscriptionsFixture>(output, fixture) {
[Fact]
public async Task receives_all_events_from_start() {
var streamName = Fixture.GetStreamName();
Expand All @@ -11,15 +11,15 @@ public async Task receives_all_events_from_start() {

var seedEvents = Fixture.CreateTestEvents(10).ToArray();
var pageSize = seedEvents.Length / 2;

var availableEvents = new HashSet<Uuid>(seedEvents.Select(x => x.EventId));

await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents.Take(pageSize));

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync(streamName, FromStream.Start, OnReceived, false, OnDropped)
.WithTimeout();

await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.StreamExists, seedEvents.Skip(pageSize));

await receivedAllEvents.Task.WithTimeout();
Expand All @@ -32,41 +32,41 @@ public async Task receives_all_events_from_start() {
subscription.Dispose();
var result = await subscriptionDropped.Task.WithTimeout();
result.ShouldBe(SubscriptionDroppedResult.Disposed());

return;

Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct) {
availableEvents.RemoveWhere(x => x == re.OriginalEvent.EventId);

if (availableEvents.Count == 0) {
receivedAllEvents.TrySetResult(true);
Fixture.Log.Information("Received all {TotalEventsCount} expected events", seedEvents.Length);
}

return Task.CompletedTask;
}

void OnDropped(StreamSubscription sub, SubscriptionDroppedReason reason, Exception? ex) =>
subscriptionDropped.SetResult(new(reason, ex));
}

[Fact]
public async Task receives_all_events_from_position() {
var streamName = Fixture.GetStreamName();

var receivedAllEvents = new TaskCompletionSource<bool>();
var subscriptionDropped = new TaskCompletionSource<SubscriptionDroppedResult>();

var seedEvents = Fixture.CreateTestEvents(10).ToArray();
var pageSize = seedEvents.Length / 2;

// only the second half of the events will be received
var availableEvents = new HashSet<Uuid>(seedEvents.Skip(pageSize).Select(x => x.EventId));

var writeResult = await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents.Take(pageSize));
var streamPosition = StreamPosition.FromStreamRevision(writeResult.NextExpectedStreamRevision);
var checkpoint = FromStream.After(streamPosition);

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync(streamName, checkpoint, OnReceived, false, OnDropped)
.WithTimeout();
Expand All @@ -83,24 +83,24 @@ public async Task receives_all_events_from_position() {
subscription.Dispose();
var result = await subscriptionDropped.Task.WithTimeout();
result.ShouldBe(SubscriptionDroppedResult.Disposed());

return;

Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct) {
availableEvents.RemoveWhere(x => x == re.OriginalEvent.EventId);

if (availableEvents.Count == 0) {
receivedAllEvents.TrySetResult(true);
Fixture.Log.Information("Received all {TotalEventsCount} expected events", pageSize);
}

return Task.CompletedTask;
}

void OnDropped(StreamSubscription sub, SubscriptionDroppedReason reason, Exception? ex) =>
subscriptionDropped.SetResult(new(reason, ex));
}

[Fact]
public async Task receives_all_events_from_non_existing_stream() {
var streamName = Fixture.GetStreamName();
Expand All @@ -109,13 +109,13 @@ public async Task receives_all_events_from_non_existing_stream() {
var subscriptionDropped = new TaskCompletionSource<SubscriptionDroppedResult>();

var seedEvents = Fixture.CreateTestEvents(10).ToArray();

var availableEvents = new HashSet<Uuid>(seedEvents.Select(x => x.EventId));

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync(streamName, FromStream.Start, OnReceived, false, OnDropped)
.WithTimeout();

await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);

await receivedAllEvents.Task.WithTimeout();
Expand All @@ -128,17 +128,17 @@ public async Task receives_all_events_from_non_existing_stream() {
subscription.Dispose();
var result = await subscriptionDropped.Task.WithTimeout();
result.ShouldBe(SubscriptionDroppedResult.Disposed());

return;

Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct) {
availableEvents.RemoveWhere(x => x == re.OriginalEvent.EventId);

if (availableEvents.Count == 0) {
receivedAllEvents.TrySetResult(true);
Fixture.Log.Information("Received all {TotalEventsCount} expected events", seedEvents.Length);
}

return Task.CompletedTask;
}

Expand All @@ -154,23 +154,23 @@ public async Task allow_multiple_subscriptions_to_same_stream() {

var seedEvents = Fixture.CreateTestEvents(5).ToArray();

var targetEventsCount = seedEvents.Length*2;
var targetEventsCount = seedEvents.Length * 2;

await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);

using var subscription1 = await Fixture.Streams
.SubscribeToStreamAsync(streamName, FromStream.Start, OnReceived)
.WithTimeout();

using var subscription2 = await Fixture.Streams
.SubscribeToStreamAsync(streamName, FromStream.Start, OnReceived)
.WithTimeout();

await receivedAllEvents.Task.WithTimeout();

Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct) {
if (--targetEventsCount == 0) {
receivedAllEvents.TrySetResult(true);
receivedAllEvents.TrySetResult(true);
Fixture.Log.Information("Received all {TotalEventsCount} expected events", seedEvents.Length);
}

Expand All @@ -180,10 +180,10 @@ Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct)

[Fact]
public async Task drops_when_disposed() {
var streamName = Fixture.GetStreamName();
var streamName = Fixture.GetStreamName();

var subscriptionDropped = new TaskCompletionSource<SubscriptionDroppedResult>();

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync(
streamName,
Expand All @@ -197,7 +197,7 @@ public async Task drops_when_disposed() {
// if the subscription dropped before time, raise the reason why
if (subscriptionDropped.Task.IsCompleted)
subscriptionDropped.Task.IsCompleted.ShouldBe(false, subscriptionDropped.Task.Result.ToString());

// stop the subscription
subscription.Dispose();
var result = await subscriptionDropped.Task.WithTimeout();
Expand All @@ -207,7 +207,7 @@ public async Task drops_when_disposed() {
[Fact]
public async Task drops_when_subscriber_error() {
var streamName = Fixture.GetStreamName();

var expectedResult = SubscriptionDroppedResult.SubscriberError();

var subscriptionDropped = new TaskCompletionSource<SubscriptionDroppedResult>();
Expand All @@ -231,9 +231,9 @@ public async Task drops_when_subscriber_error() {
[Fact]
public async Task drops_when_stream_tombstoned() {
var streamName = Fixture.GetStreamName();

var subscriptionDropped = new TaskCompletionSource<SubscriptionDroppedResult>();

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync(
streamName,
Expand All @@ -250,7 +250,7 @@ public async Task drops_when_stream_tombstoned() {
var result = await subscriptionDropped.Task.WithTimeout();
result.Error.ShouldBeOfType<StreamDeletedException>().Stream.ShouldBe(streamName);
}

[Fact]
public async Task receives_all_events_with_resolved_links() {
var streamName = Fixture.GetStreamName();
Expand All @@ -260,13 +260,13 @@ public async Task receives_all_events_with_resolved_links() {

var seedEvents = Fixture.CreateTestEvents(3).ToArray();
var availableEvents = new HashSet<Uuid>(seedEvents.Select(x => x.EventId));

await Fixture.Streams.AppendToStreamAsync(streamName, StreamState.NoStream, seedEvents);

using var subscription = await Fixture.Streams
.SubscribeToStreamAsync($"$et-{EventStoreFixture.TestEventType}", FromStream.Start, OnReceived, true, OnDropped)
.WithTimeout();;
.WithTimeout();

await receivedAllEvents.Task.WithTimeout();

// if the subscription dropped before time, raise the reason why
Expand All @@ -277,7 +277,7 @@ public async Task receives_all_events_with_resolved_links() {
subscription.Dispose();
var result = await subscriptionDropped.Task.WithTimeout();
result.ShouldBe(SubscriptionDroppedResult.Disposed());

return;

Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct) {
Expand All @@ -286,12 +286,12 @@ Task OnReceived(StreamSubscription sub, ResolvedEvent re, CancellationToken ct)
Fixture.Log.Debug("Received unexpected event {EventId} from stream {StreamId}", re.Event.EventId, re.OriginalEvent.EventStreamId);
return Task.CompletedTask;
}

if (availableEvents.Count == 0) {
receivedAllEvents.TrySetResult(true);
Fixture.Log.Information("Received all {TotalEventsCount} expected events", seedEvents.Length);
}

return Task.CompletedTask;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ protected override ContainerBuilder Configure() {
.WithEnvironment(env)
.MountVolume(certsPath, "/etc/eventstore/certs", MountType.ReadOnly)
.ExposePort(port, 2113);
//.WaitForMessageInLog("'admin' user added to $users.", FromSeconds(60));
}

/// <summary>
Expand Down

0 comments on commit 9085fd7

Please sign in to comment.