5
5
namespace KurrentDB . Client . Tests ;
6
6
7
7
[ 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
+ )
9
12
: KurrentTemporaryTests < StreamSecurityInheritanceTests . CustomFixture > ( output , fixture ) {
10
13
[ RetryFact ]
11
14
public async Task acl_inheritance_is_working_properly_on_user_streams ( ) {
12
15
await Assert . ThrowsAsync < AccessDeniedException > ( ( ) => Fixture . AppendStream ( "user-no-acl" ) ) ;
13
16
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
+ ) ;
15
20
16
21
await Fixture . AppendStream ( "user-no-acl" , TestCredentials . TestAdmin ) ;
17
22
18
23
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
+ ) ;
20
27
21
28
await Fixture . AppendStream ( "user-w-diff" , TestCredentials . TestUser2 ) ;
22
29
await Fixture . AppendStream ( "user-w-diff" , TestCredentials . TestAdmin ) ;
@@ -28,9 +35,13 @@ public async Task acl_inheritance_is_working_properly_on_user_streams() {
28
35
29
36
await Assert . ThrowsAsync < AccessDeniedException > ( ( ) => Fixture . AppendStream ( "user-w-restricted" ) ) ;
30
37
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
+ ) ;
32
41
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
+ ) ;
34
45
35
46
await Fixture . AppendStream ( "user-w-restricted" , TestCredentials . TestAdmin ) ;
36
47
@@ -45,7 +56,9 @@ public async Task acl_inheritance_is_working_properly_on_user_streams() {
45
56
await Assert . ThrowsAsync < AccessDeniedException > ( ( ) => Fixture . ReadEvent ( "user-r-restricted" ) ) ;
46
57
await Fixture . AppendStream ( "user-r-restricted" , TestCredentials . TestUser1 ) ;
47
58
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
+ ) ;
49
62
50
63
await Fixture . ReadEvent ( "user-r-restricted" , TestCredentials . TestAdmin ) ;
51
64
}
@@ -63,12 +76,16 @@ public async Task acl_inheritance_is_working_properly_on_user_streams_when_not_a
63
76
public async Task acl_inheritance_is_working_properly_on_system_streams ( ) {
64
77
await Assert . ThrowsAsync < AccessDeniedException > ( ( ) => Fixture . AppendStream ( "$sys-no-acl" ) ) ;
65
78
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
+ ) ;
67
82
68
83
await Fixture . AppendStream ( "$sys-no-acl" , TestCredentials . TestAdmin ) ;
69
84
70
85
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
+ ) ;
72
89
73
90
await Fixture . AppendStream ( "$sys-w-diff" , TestCredentials . TestUser2 ) ;
74
91
await Fixture . AppendStream ( "$sys-w-diff" , TestCredentials . TestAdmin ) ;
@@ -79,8 +96,13 @@ public async Task acl_inheritance_is_working_properly_on_system_streams() {
79
96
await Fixture . AppendStream ( "$sys-w-multiple" , TestCredentials . TestAdmin ) ;
80
97
81
98
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
+ ) ;
84
106
85
107
await Fixture . AppendStream ( "$sys-w-restricted" , TestCredentials . TestAdmin ) ;
86
108
@@ -89,15 +111,20 @@ public async Task acl_inheritance_is_working_properly_on_system_streams() {
89
111
await Fixture . AppendStream ( "$sys-w-all" , TestCredentials . TestAdmin ) ;
90
112
91
113
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
+ ) ;
93
117
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
+ ) ;
95
121
96
122
await Fixture . ReadEvent ( "$sys-no-acl" , TestCredentials . TestAdmin ) ;
97
123
}
98
124
99
125
[ 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" ) ;
101
128
102
129
public class CustomFixture : SecurityFixture {
103
130
protected override async Task When ( ) {
@@ -106,7 +133,10 @@ protected override async Task When() {
106
133
new ( writeRole : "user1" )
107
134
) ;
108
135
109
- await Streams . SetSystemSettingsAsync ( settings , userCredentials : TestCredentials . TestAdmin ) ;
136
+ await Streams . SetSystemSettingsAsync (
137
+ settings ,
138
+ new SetSystemSettingsOptions { UserCredentials = TestCredentials . TestAdmin }
139
+ ) ;
110
140
111
141
await Streams . SetStreamMetadataAsync (
112
142
"user-no-acl" ,
@@ -125,14 +155,14 @@ await Streams.SetStreamMetadataAsync(
125
155
await Streams . SetStreamMetadataAsync (
126
156
"user-w-multiple" ,
127
157
StreamState . NoStream ,
128
- new ( acl : new ( writeRoles : new [ ] { "user1" , "user2" } ) ) ,
158
+ new ( acl : new ( writeRoles : [ "user1" , "user2" ] ) ) ,
129
159
new SetStreamMetadataOptions { UserCredentials = TestCredentials . Root }
130
160
) ;
131
161
132
162
await Streams . SetStreamMetadataAsync (
133
163
"user-w-restricted" ,
134
164
StreamState . NoStream ,
135
- new ( acl : new ( writeRoles : Array . Empty < string > ( ) ) ) ,
165
+ new ( acl : new ( writeRoles : [ ] ) ) ,
136
166
new SetStreamMetadataOptions { UserCredentials = TestCredentials . Root }
137
167
) ;
138
168
@@ -167,14 +197,14 @@ await Streams.SetStreamMetadataAsync(
167
197
await Streams . SetStreamMetadataAsync (
168
198
"$sys-w-multiple" ,
169
199
StreamState . NoStream ,
170
- new ( acl : new ( writeRoles : new [ ] { "user1" , "user2" } ) ) ,
200
+ new ( acl : new ( writeRoles : [ "user1" , "user2" ] ) ) ,
171
201
new SetStreamMetadataOptions { UserCredentials = TestCredentials . Root }
172
202
) ;
173
203
174
204
await Streams . SetStreamMetadataAsync (
175
205
"$sys-w-restricted" ,
176
206
StreamState . NoStream ,
177
- new ( acl : new ( writeRoles : Array . Empty < string > ( ) ) ) ,
207
+ new ( acl : new ( writeRoles : [ ] ) ) ,
178
208
new SetStreamMetadataOptions { UserCredentials = TestCredentials . Root }
179
209
) ;
180
210
0 commit comments