6
6
using Passwordless . Api . IntegrationTests . Helpers . App ;
7
7
using Passwordless . Common . Constants ;
8
8
using Passwordless . Common . EventLog . Enums ;
9
+ using Passwordless . Common . Extensions ;
9
10
using Passwordless . Common . Models . Apps ;
11
+ using Passwordless . Service . Models ;
10
12
using Xunit ;
11
13
using Xunit . Abstractions ;
12
14
@@ -176,8 +178,8 @@ public async Task I_can_view_the_event_for_disabling_the_generate_sign_in_token_
176
178
using var appCreationResponse = await _client . CreateApplicationAsync ( applicationName ) ;
177
179
var accountKeysCreation = await appCreationResponse . Content . ReadFromJsonAsync < CreateAppResultDto > ( ) ;
178
180
_client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
179
- _ = await _client . EnableEventLogging ( applicationName ) ;
180
- using var enableResponse = await _client . PostAsJsonAsync ( $ "admin/apps/{ applicationName } /sign-in-generate-token-endpoint/disable",
181
+ await _client . EnableEventLogging ( applicationName ) ;
182
+ await _client . PostAsJsonAsync ( $ "admin/apps/{ applicationName } /sign-in-generate-token-endpoint/disable",
181
183
new AppsEndpoints . DisableGenerateSignInTokenEndpointRequest ( user ) ) ;
182
184
183
185
// Act
@@ -193,6 +195,107 @@ public async Task I_can_view_the_event_for_disabling_the_generate_sign_in_token_
193
195
enabledEvent ! . PerformedBy . Should ( ) . Be ( user ) ;
194
196
}
195
197
198
+ [ Fact ]
199
+ public async Task I_can_view_the_event_for_using_a_disabled_api_secret ( )
200
+ {
201
+ // Arrange
202
+ var applicationName = CreateAppHelpers . GetApplicationName ( ) ;
203
+ using var createApplicationMessage = await _client . CreateApplicationAsync ( applicationName ) ;
204
+ var accountKeysCreation = await createApplicationMessage . Content . ReadFromJsonAsync < CreateAppResultDto > ( ) ;
205
+ _client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
206
+ await _client . EnableEventLogging ( applicationName ) ;
207
+ using var getApiKeysResponse = await _client . GetAsync ( $ "/admin/apps/{ applicationName } /api-keys") ;
208
+ var apiKeys = await getApiKeysResponse . Content . ReadFromJsonAsync < IReadOnlyCollection < ApiKeyResponse > > ( ) ;
209
+ var keyToLock = apiKeys ! . First ( x => x . ApiKey . EndsWith ( accountKeysCreation . ApiSecret1 . GetLast ( 4 ) ) ) ;
210
+ _ = await _client . PostAsync ( $ "/admin/apps/{ applicationName } /api-keys/{ keyToLock . Id } /lock", null ) ;
211
+ _ = await _client . GetAsync ( "credentials/list" ) ;
212
+ _ = await _client . PostAsync ( $ "/admin/apps/{ applicationName } /api-keys/{ keyToLock . Id } /unlock", null ) ;
213
+
214
+ // Act
215
+ using var getApplicationEventsResponse = await _client . GetAsync ( "events?pageNumber=1" ) ;
216
+ // Assert
217
+ getApplicationEventsResponse . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
218
+ var applicationEvents = await getApplicationEventsResponse . Content . ReadFromJsonAsync < EventLog . GetEventLogEventsResponse > ( ) ;
219
+ applicationEvents . Should ( ) . NotBeNull ( ) ;
220
+ applicationEvents ! . Events . Should ( ) . NotBeEmpty ( ) ;
221
+ applicationEvents . Events . Should ( ) . Contain ( x => x . EventType == EventType . ApiAuthDisabledSecretKeyUsed . ToString ( ) ) ;
222
+ }
223
+
224
+ [ Fact ]
225
+ public async Task I_can_view_the_event_for_using_a_disabled_public_key ( )
226
+ {
227
+ // Arrange
228
+ var applicationName = CreateAppHelpers . GetApplicationName ( ) ;
229
+ using var createApplicationMessage = await _client . CreateApplicationAsync ( applicationName ) ;
230
+ var accountKeysCreation = await createApplicationMessage . Content . ReadFromJsonAsync < CreateAppResultDto > ( ) ;
231
+ _client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
232
+ _client . AddPublicKey ( accountKeysCreation . ApiKey1 ) ;
233
+ await _client . EnableEventLogging ( applicationName ) ;
234
+ using var getApiKeysResponse = await _client . GetAsync ( $ "/admin/apps/{ applicationName } /api-keys") ;
235
+ var apiKeys = await getApiKeysResponse . Content . ReadFromJsonAsync < IReadOnlyCollection < ApiKeyResponse > > ( ) ;
236
+ var keyToLock = apiKeys ! . First ( x => x . ApiKey . EndsWith ( accountKeysCreation . ApiKey1 . GetLast ( 4 ) ) ) ;
237
+ _ = await _client . PostAsync ( $ "/admin/apps/{ applicationName } /api-keys/{ keyToLock . Id } /lock", null ) ;
238
+ _ = await _client . PostAsJsonAsync ( "/signin/begin" , new SignInBeginDTO { Origin = PasswordlessApiFactory . OriginUrl , RPID = PasswordlessApiFactory . RpId } ) ;
239
+ _ = await _client . PostAsync ( $ "/admin/apps/{ applicationName } /api-keys/{ keyToLock . Id } /unlock", null ) ;
240
+
241
+ // Act
242
+ using var getApplicationEventsResponse = await _client . GetAsync ( "events?pageNumber=1" ) ;
243
+
244
+ // Assert
245
+ getApplicationEventsResponse . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
246
+ var applicationEvents = await getApplicationEventsResponse . Content . ReadFromJsonAsync < EventLog . GetEventLogEventsResponse > ( ) ;
247
+ applicationEvents . Should ( ) . NotBeNull ( ) ;
248
+ applicationEvents ! . Events . Should ( ) . NotBeEmpty ( ) ;
249
+ applicationEvents . Events . Should ( ) . Contain ( x => x . EventType == EventType . ApiAuthDisabledPublicKeyUsed . ToString ( ) ) ;
250
+ }
251
+
252
+ [ Fact ]
253
+ public async Task I_can_view_the_event_for_using_a_non_existent_api_key ( )
254
+ {
255
+ // Arrange
256
+ var applicationName = CreateAppHelpers . GetApplicationName ( ) ;
257
+ using var createApplicationMessage = await _client . CreateApplicationAsync ( applicationName ) ;
258
+ var accountKeysCreation = await createApplicationMessage . Content . ReadFromJsonAsync < CreateAppResultDto > ( ) ;
259
+ _client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
260
+ _client . AddPublicKey ( $ "{ applicationName } :public:invalid-public-key") ;
261
+ await _client . EnableEventLogging ( applicationName ) ;
262
+ _ = await _client . PostAsJsonAsync ( "/signin/begin" , new SignInBeginDTO { Origin = PasswordlessApiFactory . OriginUrl , RPID = PasswordlessApiFactory . RpId } ) ;
263
+
264
+ // Act
265
+ using var getApplicationEventsResponse = await _client . GetAsync ( "events?pageNumber=1" ) ;
266
+
267
+ // Assert
268
+ getApplicationEventsResponse . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
269
+ var applicationEvents = await getApplicationEventsResponse . Content . ReadFromJsonAsync < EventLog . GetEventLogEventsResponse > ( ) ;
270
+ applicationEvents . Should ( ) . NotBeNull ( ) ;
271
+ applicationEvents ! . Events . Should ( ) . NotBeEmpty ( ) ;
272
+ applicationEvents . Events . Should ( ) . Contain ( x => x . EventType == EventType . ApiAuthInvalidPublicKeyUsed . ToString ( ) ) ;
273
+ }
274
+
275
+ [ Fact ]
276
+ public async Task I_can_view_the_event_for_using_a_non_existent_api_secret ( )
277
+ {
278
+ // Arrange
279
+ var applicationName = CreateAppHelpers . GetApplicationName ( ) ;
280
+ using var createApplicationMessage = await _client . CreateApplicationAsync ( applicationName ) ;
281
+ var accountKeysCreation = await createApplicationMessage . Content . ReadFromJsonAsync < CreateAppResultDto > ( ) ;
282
+ _client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
283
+ _client . AddSecretKey ( $ "{ applicationName } :secret:invalid-secret-key") ;
284
+ await _client . EnableEventLogging ( applicationName ) ;
285
+ _ = await _client . GetAsync ( "credentials/list" ) ;
286
+ _client . AddSecretKey ( accountKeysCreation ! . ApiSecret1 ) ;
287
+
288
+ // Act
289
+ using var getApplicationEventsResponse = await _client . GetAsync ( "events?pageNumber=1" ) ;
290
+
291
+ // Assert
292
+ getApplicationEventsResponse . StatusCode . Should ( ) . Be ( HttpStatusCode . OK ) ;
293
+ var applicationEvents = await getApplicationEventsResponse . Content . ReadFromJsonAsync < EventLog . GetEventLogEventsResponse > ( ) ;
294
+ applicationEvents . Should ( ) . NotBeNull ( ) ;
295
+ applicationEvents ! . Events . Should ( ) . NotBeEmpty ( ) ;
296
+ applicationEvents . Events . Should ( ) . Contain ( x => x . EventType == EventType . ApiAuthInvalidSecretKeyUsed . ToString ( ) ) ;
297
+ }
298
+
196
299
public void Dispose ( )
197
300
{
198
301
_client . Dispose ( ) ;
0 commit comments