Skip to content

Commit

Permalink
mark anonymous tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pvanbuijtene committed Jul 24, 2023
1 parent 52c5150 commit f52aefb
Show file tree
Hide file tree
Showing 34 changed files with 158 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public abstract class EventStoreClientFixture : EventStoreClientFixtureBase {
public EventStoreOperationsClient Client { get; }
public EventStoreClient StreamsClient { get; }

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 @@ -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 @@ -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 @@ -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
39 changes: 39 additions & 0 deletions test/EventStore.Client.Streams.Tests/Deprecation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;

namespace EventStore.Client;

internal class Deprecation {
internal class FactAttribute : Xunit.FactAttribute {
private readonly Version _legacySince;
private readonly string _skipMessage;

public FactAttribute(Version since, string skipMessage) {
_legacySince = since;
_skipMessage = skipMessage;
}

public override string? Skip {
get => EventStoreTestServer.Version >= _legacySince
? _skipMessage
: null;
set => throw new NotSupportedException();
}
}

internal class TheoryAttribute : Xunit.TheoryAttribute {
private readonly Version _legacySince;
private readonly string _skipMessage;

public TheoryAttribute(Version since, string skipMessage) {
_legacySince = since;
_skipMessage = skipMessage;
}

public override string? Skip {
get => EventStoreTestServer.Version >= _legacySince
? _skipMessage
: null;
set => throw new NotSupportedException();
}
}
}
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
17 changes: 17 additions & 0 deletions test/EventStore.Client.Streams.Tests/NoAuthentication.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;

namespace EventStore.Client;

public class NoAuthentication {
private static readonly Version LegacySince = new Version(23, 6);
private static readonly string SkipMessage =
"Anonymous access is no longer supported 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 @@ -19,9 +19,7 @@ public abstract class SecurityFixture : EventStoreClientFixture {

public EventStoreUserManagementClient UserManagementClient { get; }

protected SecurityFixture() {
// make sure credentials aren't changing the test results./
Settings.DefaultCredentials = null;
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]
[NoAuthentication.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]
[NoAuthentication.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]
[NoAuthentication.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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ public async Task multiple_roles_are_handled_correctly() {
await Assert.ThrowsAsync<AccessDeniedException>(() => _fixture.AppendStream("usr-stream", TestCredentials.TestUser2));
await _fixture.AppendStream("usr-stream", userCredentials: TestCredentials.TestAdmin);

await _fixture.DeleteStream("usr-stream1");
await _fixture.DeleteStream("usr-stream2", userCredentials: TestCredentials.TestUser1);
await _fixture.DeleteStream("usr-stream3", TestCredentials.TestUser2);
await _fixture.DeleteStream("usr-stream4", userCredentials: TestCredentials.TestAdmin);
}

[NoAuthentication.Fact]
public async Task multiple_roles_are_handled_correctly_without_authentication() {
await _fixture.DeleteStream("usr-stream1");
}


public class Fixture : SecurityFixture {
protected override Task When() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task operations_on_system_stream_succeeds_for_user() {
await _fixture.DeleteStream(stream, userCredentials: TestCredentials.TestUser1);
}

[Fact]
[NoAuthentication.Fact]
public async Task operations_on_system_stream_fail_for_anonymous_user() {
var stream = $"${_fixture.GetStreamName()}";
await _fixture.AppendStream(stream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task reading_stream_meta_with_admin_user_credentials_succeeds() {
}


[Fact]
[NoAuthentication.Fact]
public async Task reading_no_acl_stream_meta_succeeds_when_no_credentials_are_passed() {
await _fixture.ReadMeta(SecurityFixture.NoAclStream);
}
Expand All @@ -62,9 +62,8 @@ public async Task reading_no_acl_stream_meta_succeeds_when_any_existing_user_cre
public async Task reading_no_acl_stream_meta_succeeds_when_admin_user_credentials_are_passed() {
await _fixture.ReadMeta(SecurityFixture.NoAclStream, userCredentials: TestCredentials.TestAdmin);
}


[Fact]

[NoAuthentication.Fact]
public async Task reading_all_access_normal_stream_meta_succeeds_when_no_credentials_are_passed() {
await _fixture.ReadMeta(SecurityFixture.NormalAllStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public async Task reading_stream_with_admin_user_credentials_succeeds() {
}


[Fact]
[NoAuthentication.Fact]
public async Task reading_no_acl_stream_succeeds_when_no_credentials_are_passed() {
await _fixture.AppendStream(SecurityFixture.NoAclStream);

Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task reading_no_acl_stream_succeeds_when_admin_user_credentials_are
}


[Fact]
[NoAuthentication.Fact]
public async Task reading_all_access_normal_stream_succeeds_when_no_credentials_are_passed() {
await _fixture.AppendStream(SecurityFixture.NormalAllStream);
await _fixture.ReadEvent(SecurityFixture.NormalAllStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
_fixture.AppendStream("user-w-restricted", TestCredentials.TestUser2));
await _fixture.AppendStream("user-w-restricted", userCredentials: TestCredentials.TestAdmin);

await _fixture.AppendStream("user-w-all");
await _fixture.AppendStream("user-w-all", userCredentials: TestCredentials.TestUser1);
await _fixture.AppendStream("user-w-all", TestCredentials.TestUser2);
await _fixture.AppendStream("user-w-all", userCredentials: TestCredentials.TestAdmin);


await _fixture.ReadEvent("user-no-acl");
await _fixture.ReadEvent("user-no-acl", userCredentials: TestCredentials.TestUser1);
await _fixture.ReadEvent("user-no-acl", TestCredentials.TestUser2);
await _fixture.ReadEvent("user-no-acl", userCredentials: TestCredentials.TestAdmin);
Expand All @@ -98,6 +95,13 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
await _fixture.ReadEvent("user-r-restricted", userCredentials: TestCredentials.TestAdmin);
}

[NoAuthentication.Fact]
public async Task acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated() {
await _fixture.AppendStream("user-w-all");

await _fixture.ReadEvent("user-no-acl");

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.

Check failure on line 102 in test/EventStore.Client.Streams.Tests/Security/stream_security_inheritance.cs

View workflow job for this annotation

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

EventStore.Client.Security.stream_security_inheritance.acl_inheritance_is_working_properly_on_user_streams_when_not_authenticated

EventStore.Client.StreamNotFoundException : Event stream 'user-no-acl' was not found.
}

[Fact]
public async Task acl_inheritance_is_working_properly_on_system_streams() {
await Assert.ThrowsAsync<AccessDeniedException>(() => _fixture.AppendStream("$sys-no-acl"));
Expand Down Expand Up @@ -125,7 +129,6 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
_fixture.AppendStream("$sys-w-restricted", TestCredentials.TestUser2));
await _fixture.AppendStream("$sys-w-restricted", userCredentials: TestCredentials.TestAdmin);

await _fixture.AppendStream("$sys-w-all");
await _fixture.AppendStream("$sys-w-all", userCredentials: TestCredentials.TestUser1);
await _fixture.AppendStream("$sys-w-all", TestCredentials.TestUser2);
await _fixture.AppendStream("$sys-w-all", userCredentials: TestCredentials.TestAdmin);
Expand All @@ -137,5 +140,10 @@ await Assert.ThrowsAsync<AccessDeniedException>(() =>
_fixture.ReadEvent("$sys-no-acl", TestCredentials.TestUser2));
await _fixture.ReadEvent("$sys-no-acl", userCredentials: TestCredentials.TestAdmin);
}

[NoAuthentication.Fact]
public async Task acl_inheritance_is_working_properly_on_system_streams_when_not_authenticated() {
await _fixture.AppendStream("$sys-w-all");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task reading_stream_with_admin_user_credentials_succeeds() {
await _fixture.SubscribeToStream(SecurityFixture.ReadStream, userCredentials: TestCredentials.TestAdmin);
}

[Fact]
[NoAuthentication.Fact]
public async Task subscribing_to_no_acl_stream_succeeds_when_no_credentials_are_passed() {
await _fixture.AppendStream(SecurityFixture.NoAclStream);
await _fixture.SubscribeToStream(SecurityFixture.NoAclStream);
Expand All @@ -69,7 +69,7 @@ public async Task subscribing_to_no_acl_stream_succeeds_when_admin_user_credenti
}


[Fact]
[NoAuthentication.Fact]
public async Task subscribing_to_all_access_normal_stream_succeeds_when_no_credentials_are_passed() {
await _fixture.AppendStream(SecurityFixture.NormalAllStream);
await _fixture.SubscribeToStream(SecurityFixture.NormalAllStream);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task operations_on_system_stream_with_acl_set_to_admins_succeed_for
}


[Fact]
[NoAuthentication.Fact]
public async Task operations_on_system_stream_with_acl_set_to_all_succeed_for_not_authenticated_user() {
await _fixture.AppendStream(SecurityFixture.SystemAllStream);
await _fixture.ReadEvent(SecurityFixture.SystemAllStream);
Expand Down
Loading

0 comments on commit f52aefb

Please sign in to comment.