Skip to content

Commit 6af77db

Browse files
committed
[DEVEX-222] Made old SetStreamMetadata and ConditionalAppend methods obsolete
1 parent 66e4996 commit 6af77db

File tree

6 files changed

+120
-39
lines changed

6 files changed

+120
-39
lines changed

src/KurrentDB.Client/Streams/KurrentDBClientExtensions.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public static Task SetSystemSettingsAsync(
5252
/// <param name="cancellationToken"></param>
5353
/// <returns></returns>
5454
/// <exception cref="ArgumentNullException"></exception>
55+
[Obsolete(
56+
"This method may be removed in future releases. Use the overload with SetSystemSettingsOptions options",
57+
false
58+
)]
5559
public static Task SetSystemSettingsAsync(
5660
this KurrentDBClient dbClient,
5761
SystemSettings settings,
@@ -118,13 +122,16 @@ public static async Task<ConditionalWriteResult> ConditionalAppendToStreamAsync(
118122
/// <param name="cancellationToken"></param>
119123
/// <returns></returns>
120124
/// <exception cref="ArgumentNullException"></exception>
125+
126+
[Obsolete(
127+
"This method may be removed in future releases. Use the overload with AppendToStreamOptions options",
128+
false
129+
)]
121130
public static Task<ConditionalWriteResult> ConditionalAppendToStreamAsync(
122131
this KurrentDBClient dbClient,
123132
string streamName,
124133
StreamState expectedState,
125-
#pragma warning disable CS0618 // Type or member is obsolete
126134
IEnumerable<EventData> eventData,
127-
#pragma warning restore CS0618 // Type or member is obsolete
128135
TimeSpan? deadline = null,
129136
UserCredentials? userCredentials = null,
130137
CancellationToken cancellationToken = default

test/KurrentDB.Client.Tests/Security/MultipleRoleSecurityTests.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@ public class MultipleRoleSecurityTests(ITestOutputHelper output, MultipleRoleSec
1010
[Fact]
1111
public async Task multiple_roles_are_handled_correctly() {
1212
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("usr-stream"));
13-
await Assert.ThrowsAsync<StreamNotFoundException>(() => Fixture.ReadEvent("usr-stream", TestCredentials.TestUser1));
14-
await Assert.ThrowsAsync<StreamNotFoundException>(() => Fixture.ReadEvent("usr-stream", TestCredentials.TestUser2));
15-
await Assert.ThrowsAsync<StreamNotFoundException>(() => Fixture.ReadEvent("usr-stream", TestCredentials.TestAdmin));
13+
await Assert.ThrowsAsync<StreamNotFoundException>(
14+
() => Fixture.ReadEvent("usr-stream", TestCredentials.TestUser1)
15+
);
16+
17+
await Assert.ThrowsAsync<StreamNotFoundException>(
18+
() => Fixture.ReadEvent("usr-stream", TestCredentials.TestUser2)
19+
);
20+
21+
await Assert.ThrowsAsync<StreamNotFoundException>(
22+
() => Fixture.ReadEvent("usr-stream", TestCredentials.TestAdmin)
23+
);
1624

1725
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("usr-stream"));
1826
await Fixture.AppendStream("usr-stream", TestCredentials.TestUser1);
19-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("usr-stream", TestCredentials.TestUser2));
27+
await Assert.ThrowsAsync<AccessDeniedException>(
28+
() => Fixture.AppendStream("usr-stream", TestCredentials.TestUser2)
29+
);
30+
2031
await Fixture.AppendStream("usr-stream", TestCredentials.TestAdmin);
2132

2233
await Fixture.DeleteStream("usr-stream2", TestCredentials.TestUser1);
@@ -32,13 +43,16 @@ public class CustomFixture : SecurityFixture {
3243
protected override async Task When() {
3344
var settings = new SystemSettings(
3445
new(
35-
new[] { "user1", "user2" },
36-
new[] { "$admins", "user1" },
37-
new[] { "user1", SystemRoles.All }
46+
["user1", "user2"],
47+
["$admins", "user1"],
48+
["user1", SystemRoles.All]
3849
)
3950
);
4051

41-
await Streams.SetSystemSettingsAsync(settings, userCredentials: TestCredentials.TestAdmin);
52+
await Streams.SetSystemSettingsAsync(
53+
settings,
54+
new SetSystemSettingsOptions { UserCredentials = TestCredentials.TestAdmin }
55+
);
4256
}
4357
}
4458
}

test/KurrentDB.Client.Tests/Security/OverridenSystemStreamSecurityForAllTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
namespace KurrentDB.Client.Tests;
66

77
[Trait("Category", "Target:Security")]
8-
public class OverridenSystemStreamSecurityForAllTests(ITestOutputHelper output, OverridenSystemStreamSecurityForAllTests.CustomFixture fixture)
8+
public class OverridenSystemStreamSecurityForAllTests(
9+
ITestOutputHelper output,
10+
OverridenSystemStreamSecurityForAllTests.CustomFixture fixture
11+
)
912
: KurrentTemporaryTests<OverridenSystemStreamSecurityForAllTests.CustomFixture>(output, fixture) {
1013
[Fact]
1114
public async Task operations_on_system_stream_succeeds_for_user() {
@@ -68,7 +71,10 @@ protected override Task When() {
6871
)
6972
);
7073

71-
return Streams.SetSystemSettingsAsync(settings, userCredentials: TestCredentials.TestAdmin);
74+
return Streams.SetSystemSettingsAsync(
75+
settings,
76+
new SetSystemSettingsOptions { UserCredentials = TestCredentials.TestAdmin }
77+
);
7278
}
7379
}
7480
}

test/KurrentDB.Client.Tests/Security/OverridenSystemStreamSecurityTests.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
namespace KurrentDB.Client.Tests;
55

66
[Trait("Category", "Target:Security")]
7-
public class OverridenSystemStreamSecurityTests(ITestOutputHelper output, OverridenSystemStreamSecurityTests.CustomFixture fixture)
7+
public class OverridenSystemStreamSecurityTests(
8+
ITestOutputHelper output,
9+
OverridenSystemStreamSecurityTests.CustomFixture fixture
10+
)
811
: KurrentTemporaryTests<OverridenSystemStreamSecurityTests.CustomFixture>(output, fixture) {
912
[Fact]
1013
public async Task operations_on_system_stream_succeed_for_authorized_user() {
@@ -27,7 +30,10 @@ public async Task operations_on_system_stream_succeed_for_authorized_user() {
2730
public async Task operations_on_system_stream_fail_for_not_authorized_user() {
2831
var stream = $"${Fixture.GetStreamName()}";
2932
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent(stream, TestCredentials.TestUser2));
30-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadStreamForward(stream, TestCredentials.TestUser2));
33+
await Assert.ThrowsAsync<AccessDeniedException>(
34+
() => Fixture.ReadStreamForward(stream, TestCredentials.TestUser2)
35+
);
36+
3137
await Assert.ThrowsAsync<AccessDeniedException>(
3238
() =>
3339
Fixture.ReadStreamBackward(stream, TestCredentials.TestUser2)
@@ -38,7 +44,9 @@ await Assert.ThrowsAsync<AccessDeniedException>(
3844
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadMeta(stream, TestCredentials.TestUser2));
3945
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.WriteMeta(stream, TestCredentials.TestUser2));
4046

41-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.SubscribeToStream(stream, TestCredentials.TestUser2));
47+
await Assert.ThrowsAsync<AccessDeniedException>(
48+
() => Fixture.SubscribeToStream(stream, TestCredentials.TestUser2)
49+
);
4250

4351
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.DeleteStream(stream, TestCredentials.TestUser2));
4452
}
@@ -84,7 +92,10 @@ protected override Task When() {
8492
userStreamAcl: default
8593
);
8694

87-
return Streams.SetSystemSettingsAsync(settings, userCredentials: TestCredentials.TestAdmin);
95+
return Streams.SetSystemSettingsAsync(
96+
settings,
97+
new SetSystemSettingsOptions { UserCredentials = TestCredentials.TestAdmin }
98+
);
8899
}
89100
}
90101
}

test/KurrentDB.Client.Tests/Security/OverridenUserStreamSecurityTests.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
namespace KurrentDB.Client.Tests;
55

66
[Trait("Category", "Target:Security")]
7-
public class OverridenUserStreamSecurityTests(ITestOutputHelper output, OverridenUserStreamSecurityTests.CustomFixture fixture)
7+
public class OverridenUserStreamSecurityTests(
8+
ITestOutputHelper output,
9+
OverridenUserStreamSecurityTests.CustomFixture fixture
10+
)
811
: KurrentTemporaryTests<OverridenUserStreamSecurityTests.CustomFixture>(output, fixture) {
912
[Fact]
1013
public async Task operations_on_user_stream_succeeds_for_authorized_user() {
@@ -27,14 +30,21 @@ public async Task operations_on_user_stream_succeeds_for_authorized_user() {
2730
public async Task operations_on_user_stream_fail_for_not_authorized_user() {
2831
var stream = Fixture.GetStreamName();
2932
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent(stream, TestCredentials.TestUser2));
30-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadStreamForward(stream, TestCredentials.TestUser2));
31-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadStreamBackward(stream, TestCredentials.TestUser2));
33+
await Assert.ThrowsAsync<AccessDeniedException>(
34+
() => Fixture.ReadStreamForward(stream, TestCredentials.TestUser2)
35+
);
36+
37+
await Assert.ThrowsAsync<AccessDeniedException>(
38+
() => Fixture.ReadStreamBackward(stream, TestCredentials.TestUser2)
39+
);
3240

3341
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream(stream, TestCredentials.TestUser2));
3442
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadMeta(stream, TestCredentials.TestUser2));
3543
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.WriteMeta(stream, TestCredentials.TestUser2));
3644

37-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.SubscribeToStream(stream, TestCredentials.TestUser2));
45+
await Assert.ThrowsAsync<AccessDeniedException>(
46+
() => Fixture.SubscribeToStream(stream, TestCredentials.TestUser2)
47+
);
3848

3949
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.DeleteStream(stream, TestCredentials.TestUser2));
4050
}
@@ -75,7 +85,10 @@ public async Task operations_on_user_stream_succeed_for_admin() {
7585
public class CustomFixture : SecurityFixture {
7686
protected override Task When() {
7787
var settings = new SystemSettings(new("user1", "user1", "user1", "user1", "user1"));
78-
return Streams.SetSystemSettingsAsync(settings, userCredentials: TestCredentials.TestAdmin);
88+
return Streams.SetSystemSettingsAsync(
89+
settings,
90+
new SetSystemSettingsOptions { UserCredentials = TestCredentials.TestAdmin }
91+
);
7992
}
8093
}
8194
}

test/KurrentDB.Client.Tests/Security/StreamSecurityInheritanceTests.cs

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,25 @@
55
namespace KurrentDB.Client.Tests;
66

77
[Trait("Category", "Target:Security")]
8-
public class StreamSecurityInheritanceTests(ITestOutputHelper output, StreamSecurityInheritanceTests.CustomFixture fixture)
8+
public class StreamSecurityInheritanceTests(
9+
ITestOutputHelper output,
10+
StreamSecurityInheritanceTests.CustomFixture fixture
11+
)
912
: KurrentTemporaryTests<StreamSecurityInheritanceTests.CustomFixture>(output, fixture) {
1013
[RetryFact]
1114
public async Task acl_inheritance_is_working_properly_on_user_streams() {
1215
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-no-acl"));
1316
await Fixture.AppendStream("user-no-acl", TestCredentials.TestUser1);
14-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-no-acl", TestCredentials.TestUser2));
17+
await Assert.ThrowsAsync<AccessDeniedException>(
18+
() => Fixture.AppendStream("user-no-acl", TestCredentials.TestUser2)
19+
);
1520

1621
await Fixture.AppendStream("user-no-acl", TestCredentials.TestAdmin);
1722

1823
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-w-diff"));
19-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-w-diff", TestCredentials.TestUser1));
24+
await Assert.ThrowsAsync<AccessDeniedException>(
25+
() => Fixture.AppendStream("user-w-diff", TestCredentials.TestUser1)
26+
);
2027

2128
await Fixture.AppendStream("user-w-diff", TestCredentials.TestUser2);
2229
await Fixture.AppendStream("user-w-diff", TestCredentials.TestAdmin);
@@ -28,9 +35,13 @@ public async Task acl_inheritance_is_working_properly_on_user_streams() {
2835

2936
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-w-restricted"));
3037

31-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-w-restricted", TestCredentials.TestUser1));
38+
await Assert.ThrowsAsync<AccessDeniedException>(
39+
() => Fixture.AppendStream("user-w-restricted", TestCredentials.TestUser1)
40+
);
3241

33-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("user-w-restricted", TestCredentials.TestUser2));
42+
await Assert.ThrowsAsync<AccessDeniedException>(
43+
() => Fixture.AppendStream("user-w-restricted", TestCredentials.TestUser2)
44+
);
3445

3546
await Fixture.AppendStream("user-w-restricted", TestCredentials.TestAdmin);
3647

@@ -45,7 +56,9 @@ public async Task acl_inheritance_is_working_properly_on_user_streams() {
4556
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("user-r-restricted"));
4657
await Fixture.AppendStream("user-r-restricted", TestCredentials.TestUser1);
4758
await Fixture.ReadEvent("user-r-restricted", TestCredentials.TestUser1);
48-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("user-r-restricted", TestCredentials.TestUser2));
59+
await Assert.ThrowsAsync<AccessDeniedException>(
60+
() => Fixture.ReadEvent("user-r-restricted", TestCredentials.TestUser2)
61+
);
4962

5063
await Fixture.ReadEvent("user-r-restricted", TestCredentials.TestAdmin);
5164
}
@@ -63,12 +76,16 @@ public async Task acl_inheritance_is_working_properly_on_user_streams_when_not_a
6376
public async Task acl_inheritance_is_working_properly_on_system_streams() {
6477
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-no-acl"));
6578
await Fixture.AppendStream("$sys-no-acl", TestCredentials.TestUser1);
66-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-no-acl", TestCredentials.TestUser2));
79+
await Assert.ThrowsAsync<AccessDeniedException>(
80+
() => Fixture.AppendStream("$sys-no-acl", TestCredentials.TestUser2)
81+
);
6782

6883
await Fixture.AppendStream("$sys-no-acl", TestCredentials.TestAdmin);
6984

7085
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-w-diff"));
71-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-w-diff", TestCredentials.TestUser1));
86+
await Assert.ThrowsAsync<AccessDeniedException>(
87+
() => Fixture.AppendStream("$sys-w-diff", TestCredentials.TestUser1)
88+
);
7289

7390
await Fixture.AppendStream("$sys-w-diff", TestCredentials.TestUser2);
7491
await Fixture.AppendStream("$sys-w-diff", TestCredentials.TestAdmin);
@@ -79,8 +96,13 @@ public async Task acl_inheritance_is_working_properly_on_system_streams() {
7996
await Fixture.AppendStream("$sys-w-multiple", TestCredentials.TestAdmin);
8097

8198
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-w-restricted"));
82-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-w-restricted", TestCredentials.TestUser1));
83-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.AppendStream("$sys-w-restricted", TestCredentials.TestUser2));
99+
await Assert.ThrowsAsync<AccessDeniedException>(
100+
() => Fixture.AppendStream("$sys-w-restricted", TestCredentials.TestUser1)
101+
);
102+
103+
await Assert.ThrowsAsync<AccessDeniedException>(
104+
() => Fixture.AppendStream("$sys-w-restricted", TestCredentials.TestUser2)
105+
);
84106

85107
await Fixture.AppendStream("$sys-w-restricted", TestCredentials.TestAdmin);
86108

@@ -89,15 +111,20 @@ public async Task acl_inheritance_is_working_properly_on_system_streams() {
89111
await Fixture.AppendStream("$sys-w-all", TestCredentials.TestAdmin);
90112

91113
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("$sys-no-acl"));
92-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("$sys-no-acl", TestCredentials.TestUser1));
114+
await Assert.ThrowsAsync<AccessDeniedException>(
115+
() => Fixture.ReadEvent("$sys-no-acl", TestCredentials.TestUser1)
116+
);
93117

94-
await Assert.ThrowsAsync<AccessDeniedException>(() => Fixture.ReadEvent("$sys-no-acl", TestCredentials.TestUser2));
118+
await Assert.ThrowsAsync<AccessDeniedException>(
119+
() => Fixture.ReadEvent("$sys-no-acl", TestCredentials.TestUser2)
120+
);
95121

96122
await Fixture.ReadEvent("$sys-no-acl", TestCredentials.TestAdmin);
97123
}
98124

99125
[AnonymousAccess.Fact]
100-
public async Task acl_inheritance_is_working_properly_on_system_streams_when_not_authenticated() => await Fixture.AppendStream("$sys-w-all");
126+
public async Task acl_inheritance_is_working_properly_on_system_streams_when_not_authenticated() =>
127+
await Fixture.AppendStream("$sys-w-all");
101128

102129
public class CustomFixture : SecurityFixture {
103130
protected override async Task When() {
@@ -106,7 +133,10 @@ protected override async Task When() {
106133
new(writeRole: "user1")
107134
);
108135

109-
await Streams.SetSystemSettingsAsync(settings, userCredentials: TestCredentials.TestAdmin);
136+
await Streams.SetSystemSettingsAsync(
137+
settings,
138+
new SetSystemSettingsOptions { UserCredentials = TestCredentials.TestAdmin }
139+
);
110140

111141
await Streams.SetStreamMetadataAsync(
112142
"user-no-acl",
@@ -125,14 +155,14 @@ await Streams.SetStreamMetadataAsync(
125155
await Streams.SetStreamMetadataAsync(
126156
"user-w-multiple",
127157
StreamState.NoStream,
128-
new(acl: new(writeRoles: new[] { "user1", "user2" })),
158+
new(acl: new(writeRoles: ["user1", "user2"])),
129159
new SetStreamMetadataOptions { UserCredentials = TestCredentials.Root }
130160
);
131161

132162
await Streams.SetStreamMetadataAsync(
133163
"user-w-restricted",
134164
StreamState.NoStream,
135-
new(acl: new(writeRoles: Array.Empty<string>())),
165+
new(acl: new(writeRoles: [])),
136166
new SetStreamMetadataOptions { UserCredentials = TestCredentials.Root }
137167
);
138168

@@ -167,14 +197,14 @@ await Streams.SetStreamMetadataAsync(
167197
await Streams.SetStreamMetadataAsync(
168198
"$sys-w-multiple",
169199
StreamState.NoStream,
170-
new(acl: new(writeRoles: new[] { "user1", "user2" })),
200+
new(acl: new(writeRoles: ["user1", "user2"])),
171201
new SetStreamMetadataOptions { UserCredentials = TestCredentials.Root }
172202
);
173203

174204
await Streams.SetStreamMetadataAsync(
175205
"$sys-w-restricted",
176206
StreamState.NoStream,
177-
new(acl: new(writeRoles: Array.Empty<string>())),
207+
new(acl: new(writeRoles: [])),
178208
new SetStreamMetadataOptions { UserCredentials = TestCredentials.Root }
179209
);
180210

0 commit comments

Comments
 (0)