-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added event log endpoint and starter test.
- Loading branch information
1 parent
3acdf33
commit 3b284d6
Showing
7 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Passwordless.Models; | ||
|
||
/// <summary> | ||
/// Request for getting the event logs for an application. | ||
/// </summary> | ||
public class GetEventLogRequest | ||
{ | ||
/// <summary> | ||
/// Page number for retrieving event log records. | ||
/// </summary> | ||
public int PageNumber { get; set; } | ||
|
||
/// <summary> | ||
/// This is the max number of results that will be returned. Must be between 1-1000. | ||
/// </summary> | ||
[Range(1, 1000)] | ||
public int? NumberOfResults { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Passwordless.Models; | ||
|
||
/// <summary> | ||
/// Response from GetEventLog. Contains list of events for the application. | ||
/// </summary> | ||
public class GetEventLogResponse | ||
{ | ||
/// <summary> | ||
/// Name of application the events correspond to. | ||
/// </summary> | ||
public string TenantId { get; set; } = string.Empty; | ||
/// <summary> | ||
/// List of events for the application based on the request pagination parameters. This will always be sorted by PerformedAt in descending order. | ||
/// </summary> | ||
public IEnumerable<ApplicationEvent> Events { get; set; } = new List<ApplicationEvent>(); | ||
/// <summary> | ||
/// Total number of events for the application. | ||
/// </summary> | ||
public int TotalEventCount { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// An event that occured using Passwordless library. | ||
/// </summary> | ||
public class ApplicationEvent | ||
{ | ||
public Guid Id { get; set; } | ||
/// <summary> | ||
/// When the record was performed. This will be in UTC. | ||
/// </summary> | ||
public DateTime PerformedAt { get; set; } | ||
|
||
/// <summary> | ||
/// The type of event <see href="https://github.com/passwordless/passwordless-server/blob/main/src/Common/EventLog/Enums/EventType.cs" /> | ||
/// </summary> | ||
public string EventType { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Description of the event | ||
/// </summary> | ||
public string Message { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Severity of the event <see href="https://github.com/passwordless/passwordless-server/blob/main/src/Common/EventLog/Enums/Severity.cs"/> | ||
/// </summary> | ||
public string Severity { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// The target of the event. Can be in reference to a user or the application. | ||
/// </summary> | ||
public string Subject { get; set; } = string.Empty; | ||
|
||
/// <summary> | ||
/// Last 4 characters of the api key (public/secret) used to perform the event. | ||
/// </summary> | ||
public string ApiKeyId { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Passwordless.Models; | ||
using Passwordless.Tests.Infra; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Passwordless.Tests; | ||
|
||
public class ApplicationEventLogsTests(TestApiFixture api, ITestOutputHelper testOutput) : ApiTestBase(api, testOutput) | ||
{ | ||
[Fact] | ||
public async Task I_can_view_application_event_logs_when_event_logs_are_enabled() | ||
{ | ||
// Arrange | ||
var applicationName = TestApi.GetAppName(); | ||
var passwordless = await Api.CreateClientAsync(applicationName); | ||
await Api.EnableEventLogsAsync(applicationName); | ||
|
||
// Act | ||
var response = await passwordless.GetEventLogAsync(new GetEventLogRequest { PageNumber = 1, NumberOfResults = 100 }); | ||
|
||
// Assert | ||
response.Should().NotBeNull(); | ||
response.TenantId.Should().Be(applicationName); | ||
} | ||
} |