Skip to content

Commit

Permalink
Improve authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanbuijtene committed Jul 25, 2023
1 parent 69e4b0e commit fdf60c2
Show file tree
Hide file tree
Showing 46 changed files with 256 additions and 47 deletions.
8 changes: 6 additions & 2 deletions src/EventStore.Client.Common/EventStoreCallOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public static CallOptions CreateStreaming(EventStoreClientSettings settings,
Create(settings, deadline, userCredentials, cancellationToken);

// deadline falls back to connection DefaultDeadline
public static CallOptions CreateNonStreaming(EventStoreClientSettings settings,
CancellationToken cancellationToken) => Create(settings, settings.DefaultDeadline,
settings.DefaultCredentials, cancellationToken);

public static CallOptions CreateNonStreaming(EventStoreClientSettings settings, TimeSpan? deadline,
UserCredentials? userCredentials, CancellationToken cancellationToken) => Create(settings,
deadline ?? settings.DefaultDeadline, userCredentials, cancellationToken);
Expand All @@ -28,10 +32,10 @@ private static CallOptions Create(EventStoreClientSettings settings, TimeSpan? d
: bool.FalseString
}
},
credentials: (settings.DefaultCredentials ?? userCredentials) == null
credentials: (userCredentials ?? settings.DefaultCredentials) == null
? null
: CallCredentials.FromInterceptor(async (_, metadata) => {
var credentials = settings.DefaultCredentials ?? userCredentials;
var credentials = userCredentials ?? settings.DefaultCredentials;
var authorizationHeader = await settings.OperationOptions
.GetAuthenticationHeaderValue(credentials!, CancellationToken.None)
Expand Down
2 changes: 1 addition & 1 deletion src/EventStore.Client/ChannelSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ChannelSelector(
ChannelCache channelCache) {
_inner = settings.ConnectivitySettings.IsSingleNode
? new SingleNodeChannelSelector(settings, channelCache)
: new GossipChannelSelector(settings, channelCache, new GrpcGossipClient());
: new GossipChannelSelector(settings, channelCache, new GrpcGossipClient(settings));
}

public Task<ChannelBase> SelectChannelAsync(CancellationToken cancellationToken) =>
Expand Down
14 changes: 10 additions & 4 deletions src/EventStore.Client/GrpcGossipClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

namespace EventStore.Client {
internal class GrpcGossipClient : IGossipClient {
public async ValueTask<ClusterMessages.ClusterInfo> GetAsync(ChannelBase channel,
CancellationToken cancellationToken) {
var client = new Gossip.Gossip.GossipClient(channel);
private readonly EventStoreClientSettings _settings;

public GrpcGossipClient(EventStoreClientSettings settings) {
_settings = settings;
}

using var call = client.ReadAsync(new Empty(), cancellationToken: cancellationToken);
public async ValueTask<ClusterMessages.ClusterInfo> GetAsync(ChannelBase channel, CancellationToken ct) {
var client = new Gossip.Gossip.GossipClient(channel);
using var call = client.ReadAsync(
new Empty(),
EventStoreCallOptions.CreateNonStreaming(_settings, ct));
var result = await call.ResponseAsync.ConfigureAwait(false);

return new(result.Members.Select(x =>
Expand Down
57 changes: 57 additions & 0 deletions test/EventStore.Client.Operations.Tests/AuthenticationTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;

namespace EventStore.Client {
public class AuthenticationTests : IClassFixture<AuthenticationTests.Fixture> {
private readonly Fixture _fixture;

public AuthenticationTests(Fixture fixture) {
_fixture = fixture;
}

public static IEnumerable<object?[]> AuthenticationCases() {
var fails = false;
var succeeds = true;

// no user credentials
yield return new object?[] {1, TestCredentials.Root, null, succeeds};
yield return new object?[] {2, TestCredentials.TestUser1, null, fails};
yield return new object?[] {3, null, null, fails};

// unprivileged user credentials
yield return new object?[] {4, TestCredentials.Root, TestCredentials.TestUser1, fails};
yield return new object?[] {5, TestCredentials.TestUser1, TestCredentials.TestUser1, fails};
yield return new object?[] {6, null, TestCredentials.TestUser1, fails};

// root user credentials
yield return new object?[] {7, TestCredentials.Root, TestCredentials.Root, succeeds};
yield return new object?[] {8, TestCredentials.TestUser1, TestCredentials.Root, succeeds};
yield return new object?[] {9, null, TestCredentials.Root, succeeds};
}

[Theory, MemberData(nameof(AuthenticationCases))]
public async Task system_call(int caseNr, UserCredentials? defaultCreds, UserCredentials? user, bool succeeds) {

_fixture.Settings.DefaultCredentials = defaultCreds;
_fixture.Settings.ConnectionName = $"Authentication case #{caseNr}";

await using var client = new EventStoreOperationsClient(_fixture.Settings);

var result = await Record.ExceptionAsync(() =>
client.SetNodePriorityAsync(1, userCredentials: user));

if (succeeds) {
Assert.Null(result);
return;
}

Assert.NotNull(result);

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net5.0/lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 19 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net7.0/ci

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 73 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 80 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 19 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net5.0/previous-lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 19 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net7.0/lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 73 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 80 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 20 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net6.0/previous-lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 20 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net6.0/ci

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 20 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net7.0/previous-lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 19 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net5.0/ci

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 20 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76

Check failure on line 49 in test/EventStore.Client.Operations.Tests/AuthenticationTests.cs

View workflow job for this annotation

GitHub Actions / test / EventStore.Client.Operations/ubuntu-latest/net6.0/lts

EventStore.Client.AuthenticationTests.system_call

Assert.Null() Failure Expected: (null) Actual: EventStore.Client.NotAuthenticatedException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") ---> Grpc.Core.RpcException: Status(StatusCode="Unauthenticated", Detail="Unauthenticated") --- End of inner exception stack trace --- at EventStore.Client.Interceptors.TypedExceptionInterceptor.<AsyncUnaryCall>b__5_0[TRequest,TResponse](Task`1 t) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/Interceptors/TypedExceptionInterceptor.cs:line 62 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at EventStore.Client.GrpcServerCapabilitiesClient.GetAsync(CallInvoker callInvoker, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/GrpcServerCapabilitiesClient.cs:line 35 at EventStore.Client.EventStoreClientBase.GetChannelInfoExpensive(ReconnectionRequired reconnectionRequired, Action`1 onReconnectionRequired, IChannelSelector channelSelector, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 75 at EventStore.Client.SharingProvider`2.FillBoxAsync(TaskCompletionSource`1 box, TInput input) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/SharingProvider.cs:line 98 at EventStore.Client.TaskExtensions.WithCancellation[T](Task`1 task, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/TaskExtensions.cs:line 20 at EventStore.Client.EventStoreClientBase.GetChannelInfo(CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client/EventStoreClientBase.cs:line 84 at EventStore.Client.EventStoreOperationsClient.SetNodePriorityAsync(Int32 nodePriority, Nullable`1 deadline, UserCredentials userCredentials, CancellationToken cancellationToken) in /home/runner/work/EventStore-Client-Dotnet/EventStore-Client-Dotnet/src/EventStore.Client.Operations/EventStoreOperationsClient.Admin.cs:line 76 at Xunit.Record.ExceptionAsync(Func`1 testCode) in C:\Dev\xunit\xunit\src\xunit.core\Record.cs:line 76
}

public class Fixture : EventStoreClientFixture {
protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ namespace EventStore.Client {
public abstract class EventStoreClientFixture : EventStoreClientFixtureBase {
public EventStoreOperationsClient Client { get; }
public EventStoreClient StreamsClient { get; }
public new EventStoreClientSettings Settings => base.Settings;

protected EventStoreClientFixture(EventStoreClientSettings? settings = null) : base(settings) {
protected EventStoreClientFixture(EventStoreClientSettings? settings = null)
: base(settings, noDefaultCredentials: true) {

Client = new EventStoreOperationsClient(Settings);
StreamsClient = new EventStoreClient(Settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ public abstract class EventStoreClientFixture : EventStoreClientFixtureBase {
public EventStoreClient StreamsClient { get; }
public EventStoreUserManagementClient UserManagementClient { get; }

protected EventStoreClientFixture(EventStoreClientSettings? settings = null, bool skipPSWarmUp=false) : base(settings) {
protected EventStoreClientFixture(EventStoreClientSettings? settings = null, bool skipPSWarmUp=false, bool noDefaultCredentials=false)
: base(settings, noDefaultCredentials: noDefaultCredentials){

_skipPsWarmUp = skipPSWarmUp;

Client = new EventStorePersistentSubscriptionsClient(Settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public Task throws_access_denied() =>
}).WithTimeout();

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() =>
Client.CreateToAllAsync(
"agroupname55",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public Task throws_access_denied() =>
}).WithTimeout();

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() =>
Client.CreateToAllAsync(
"agroupname55",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public create_without_permissions(Fixture fixture) {
private readonly Fixture _fixture;

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ public async Task returns_result_with_normal_user_credentials() {
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override async Task Given() {
if (SupportsPSToAll.No) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task returns_result_with_normal_user_credentials() {
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(skipPSWarmUp: true) {
public Fixture () : base(skipPSWarmUp: true, noDefaultCredentials: true) {
}

protected override async Task Given() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true) {
}

protected override async Task Given() {
if (SupportsPSToAll.No) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override async Task Given() {
await Client.CreateToAllAsync(Group, new PersistentSubscriptionSettings(),
userCredentials: TestCredentials.Root);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public Task throws_access_denied() =>
}).WithTimeout();

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() =>
Client.CreateToStreamAsync(
Stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public create_without_permissions(Fixture fixture) {
private readonly Fixture _fixture;

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ public async Task returns_result_for_normal_user() {
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true) {
}

protected override Task Given() =>
Client.CreateToStreamAsync(
groupName: GroupName,
Expand Down Expand Up @@ -174,7 +177,7 @@ await Client.SubscribeToStreamAsync(
for (int i = 0; i < 15; i++) {
await StreamsClient.AppendToStreamAsync(StreamName, StreamState.Any, new [] {
new EventData(Uuid.NewUuid(), "test-event", ReadOnlyMemory<byte>.Empty)
});
}, userCredentials: TestCredentials.Root);
}

await tcs.Task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task returns_result_with_normal_user_credentials() {
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(skipPSWarmUp: true) {
public Fixture () : base(skipPSWarmUp: true, noDefaultCredentials: true) {
}

protected override async Task Given() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true) {
}

protected override Task Given() =>
Client.CreateToStreamAsync(
StreamName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ await Assert.ThrowsAsync<AccessDeniedException>(
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true){
}

protected override async Task Given() {
await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, CreateTestEvents());
await StreamsClient.AppendToStreamAsync(Stream, StreamState.NoStream, CreateTestEvents(),
userCredentials: TestCredentials.Root);
await Client.CreateToStreamAsync(Stream, Group, new PersistentSubscriptionSettings(),
userCredentials: TestCredentials.Root);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(async () =>
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true) {
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public abstract class EventStoreClientFixture : EventStoreClientFixtureBase {
public EventStoreClient StreamsClient { get; }
public EventStoreProjectionManagementClient Client { get; }

protected EventStoreClientFixture(EventStoreClientSettings? settings = null) : base(settings,
new Dictionary<string, string> {
protected EventStoreClientFixture(EventStoreClientSettings? settings = null, bool noDefaultCredentials = false) :
base(settings, new Dictionary<string, string> {
["EVENTSTORE_RUN_PROJECTIONS"] = "ALL",
["EVENTSTORE_START_STANDARD_PROJECTIONS"] = "True"
}) {
}, noDefaultCredentials) {
Client = new EventStoreProjectionManagementClient(Settings);
UserManagementClient = new EventStoreUserManagementClient(Settings);
StreamsClient = new EventStoreClient(Settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public async Task throws_when_given_no_credentials() {
}

public class Fixture : EventStoreClientFixture {
public Fixture () : base(noDefaultCredentials: true) {
}

protected override Task Given() => Task.CompletedTask;
protected override Task When() => Task.CompletedTask;
}
Expand Down
17 changes: 17 additions & 0 deletions test/EventStore.Client.Streams.Tests/AnonymousAccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace EventStore.Client;

public class AnonymousAccess {
private static readonly Version LegacySince = new Version(23, 6);
private static readonly string SkipMessage =
"Anonymous access is turned off since v23.6.0!";

internal class FactAttribute : Deprecation.FactAttribute {
public FactAttribute() : base(LegacySince, SkipMessage) { }
}

internal class TheoryAttribute : Deprecation.TheoryAttribute {
public TheoryAttribute() : base(LegacySince, SkipMessage) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace EventStore.Client {
public abstract class EventStoreClientFixture : EventStoreClientFixtureBase {
public EventStoreClient Client { get; }
protected EventStoreClientFixture(EventStoreClientSettings? settings = null,
Dictionary<string, string>? env = null) : base(settings, env) {
Dictionary<string, string>? env = null, bool noDefaultCredentials = false)
: base(settings, env, noDefaultCredentials) {

Client = new EventStoreClient(Settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public abstract class SecurityFixture : EventStoreClientFixture {

public EventStoreUserManagementClient UserManagementClient { get; }

protected SecurityFixture() {
protected SecurityFixture() : base(noDefaultCredentials: true) {
UserManagementClient = new EventStoreUserManagementClient(Settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task delete_of_all_is_never_allowed() {
await Assert.ThrowsAsync<AccessDeniedException>(() => _fixture.DeleteStream(SecurityFixture.AllStream, userCredentials: TestCredentials.TestAdmin));
}

[Fact]
[AnonymousAccess.Fact]
public async Task deleting_normal_no_acl_stream_with_no_user_is_allowed() {
var streamId = await _fixture.CreateStreamWithMeta(new StreamMetadata());
await _fixture.DeleteStream(streamId);
Expand Down Expand Up @@ -89,7 +89,7 @@ await _fixture.CreateStreamWithMeta(
}


[Fact]
[AnonymousAccess.Fact]
public async Task deleting_normal_all_stream_with_no_user_is_allowed() {
var streamId =
await _fixture.CreateStreamWithMeta(
Expand Down Expand Up @@ -188,7 +188,7 @@ public async Task deleting_system_admin_stream_with_admin_user_is_allowed() {
}


[Fact]
[AnonymousAccess.Fact]
public async Task deleting_system_all_stream_with_no_user_is_allowed() {
var streamId = await _fixture.CreateStreamWithMeta(streamId: $"${_fixture.GetStreamName()}",
metadata: new StreamMetadata(acl: new StreamAcl(deleteRole: SystemRoles.All)));
Expand Down
Loading

0 comments on commit fdf60c2

Please sign in to comment.