Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:
10.0.x

- name: Restore
run: dotnet restore DapperIdentity.sln
run: dotnet restore DapperIdentity.slnx

- name: Build
run: dotnet build DapperIdentity.sln -c Release --no-restore
run: dotnet build DapperIdentity.slnx -c Release --no-restore

- name: Test
run: dotnet test DapperIdentity.sln -c Release --no-build --verbosity normal
run: dotnet test DapperIdentity.slnx -c Release --no-build --verbosity normal

- name: Pack
run: dotnet pack DapperIdentity.sln -c Release --no-build -o artifacts
run: dotnet pack DapperIdentity.slnx -c Release --no-build -o artifacts

# The five packages only work as a set: packing turns each ProjectReference into a dependency
# on the referenced project's PackageId at its Version. A project that lost its PackageId or
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# Autobuild guesses, and guesses badly on a multi-targeted library that needs two SDKs.
# Build it explicitly instead.
- name: Build
run: dotnet build DapperIdentity.sln -c Release
run: dotnet build DapperIdentity.slnx -c Release

- name: Analyze
uses: github/codeql-action/analyze@v4
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ jobs:
done

- name: Restore
run: dotnet restore DapperIdentity.sln
run: dotnet restore DapperIdentity.slnx

- name: Build
run: dotnet build DapperIdentity.sln -c Release --no-restore
run: dotnet build DapperIdentity.slnx -c Release --no-restore

- name: Test
run: dotnet test DapperIdentity.sln -c Release --no-build
run: dotnet test DapperIdentity.slnx -c Release --no-build

- name: Pack
run: dotnet pack DapperIdentity.sln -c Release --no-build -o artifacts
run: dotnet pack DapperIdentity.slnx -c Release --no-build -o artifacts

- name: Verify package set, contents and inter-package dependencies
shell: bash
Expand Down
25 changes: 18 additions & 7 deletions DapperIdentity.Stores/SignIn/SignInReporting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ public static string[] Values(SignInAttempt attempt, string ip, string appName,
{
ArgumentNullException.ThrowIfNull(attempt);
var user = UserNameFor(attempt, userNames);
// A success carries no name, so its sentence names none - "for ''" read like a bug.
var sentence = attempt.Succeeded
? $"Sign-in succeeded for '{user}' from {ip} on {appName} ({attempt.Path})."
? $"Sign-in succeeded from {ip} on {appName} ({attempt.Path})."
: $"Sign-in failed for '{user}' from {ip} on {appName} ({attempt.Path}): {attempt.Reason}.";
return [sentence, Version, ip, user, attempt.Succeeded ? "" : attempt.Reason.ToString(), appName, attempt.Path];
}
Expand Down Expand Up @@ -250,12 +251,22 @@ public void Report(SignInAttempt attempt)

// Information, not Warning: on Windows ASP.NET Core's default event-log logger takes Warning and
// up, so a Warning here would add a second Application-log entry per attempt during an attack.
_logger.LogInformation(
new EventId(attempt.Succeeded ? SignInEventFormat.SucceededId : SignInEventFormat.FailedId,
attempt.Succeeded ? "SignInSucceeded" : "SignInFailed"),
"Sign-in {Outcome} for {UserName} from {ClientIp} on {App} via {Path} ({Reason})",
attempt.Succeeded ? "succeeded" : "failed", SignInEventFormat.UserNameFor(attempt, _userNames), attempt.ClientIp, _appName, attempt.Path,
attempt.Succeeded ? "-" : attempt.Reason.ToString());
// Two templates, not one with blanks: a success has no name or reason to show, and an empty "for from" or a
// "(-)" in the log reads like something failed to fill in. The shared properties keep the same names.
if (attempt.Succeeded)
{
_logger.LogInformation(
new EventId(SignInEventFormat.SucceededId, "SignInSucceeded"),
"Sign-in succeeded from {ClientIp} on {App} via {Path}",
attempt.ClientIp, _appName, attempt.Path);
}
else
{
_logger.LogInformation(
new EventId(SignInEventFormat.FailedId, "SignInFailed"),
"Sign-in failed for {UserName} from {ClientIp} on {App} via {Path} ({Reason})",
SignInEventFormat.UserNameFor(attempt, _userNames), attempt.ClientIp, _appName, attempt.Path, attempt.Reason.ToString());
}

// No address, nothing to ban: PortGuardian has no use for the event.
if (_eventLogOff || attempt.ClientIp is null)
Expand Down
15 changes: 15 additions & 0 deletions DapperIdentity.Tests/SignInReportingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ public void Every_attempt_is_logged_at_information_under_its_own_category()
Assert.DoesNotContain("bob ", entry.Message, StringComparison.Ordinal);
}

[Fact]
public void A_success_is_logged_without_an_empty_name_or_reason()
{
var logs = new CapturingLogs();
var written = new List<string[]>();
var reporter = Reporter(logs, (_, _, values) => written.Add(values));

reporter.Report(SignInAttempt.Success(From("203.0.113.9"), "bob", "cookie"));

var entry = Assert.Single(logs.Entries);
Assert.Equal((LogLevel.Information, 1001), (entry.Level, entry.EventId.Id));
Assert.Equal("Sign-in succeeded from 203.0.113.9 on TestApp via cookie", entry.Message);
Assert.Equal("Sign-in succeeded from 203.0.113.9 on TestApp (cookie).", Assert.Single(written)[0]);
}

[Fact]
public void An_attempt_without_an_address_is_logged_but_not_written_as_an_event()
{
Expand Down
107 changes: 0 additions & 107 deletions DapperIdentity.sln

This file was deleted.

13 changes: 13 additions & 0 deletions DapperIdentity.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Solution>
<Configurations>
<Platform Name="Any CPU" />
<Platform Name="x64" />
<Platform Name="x86" />
</Configurations>
<Project Path="DapperIdentity.Abstractions/DapperIdentity.Abstractions.csproj" />
<Project Path="DapperIdentity.Cookies.Server/DapperIdentity.Cookies.Server.csproj" />
<Project Path="DapperIdentity.Jwt.Client/DapperIdentity.Jwt.Client.csproj" />
<Project Path="DapperIdentity.Jwt.Server/DapperIdentity.Jwt.Server.csproj" />
<Project Path="DapperIdentity.Stores/DapperIdentity.Stores.csproj" />
<Project Path="DapperIdentity.Tests/DapperIdentity.Tests.csproj" />
</Solution>
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
ProjectReference into a package dependency on the referenced project's Version, so the
five ids only ever resolve correctly against each other when they move together.
publish.yml reads this line and refuses to run if the requested version differs. -->
<Version>0.10.0</Version>
<Version>0.10.1</Version>

<Authors>CPE</Authors>
<Company>CPE</Company>
Expand Down
Loading