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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
Principal: {
Identities: [
{
Claims: [
{
TheClaimType: TheClaimValue
}
],
AuthenticationType: TheAuthenticationType
}
]
},
Name: TheValue
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
Principal: {},
Name: TheValue
}
25 changes: 25 additions & 0 deletions src/Verify.Tests/Serialization/ClaimsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
public class ClaimsTests
{
[Fact]
public Task EmptyClaimsPrincipal() =>
// An empty principal still writes an object. Writing no token would leave the
// writer mid-property and corrupt every member written after it.
Verify(
new
{
Principal = new ClaimsPrincipal(),
Name = "TheValue"
});

[Fact]
public Task ClaimsPrincipalWithIdentity() =>
Verify(
new
{
Principal = new ClaimsPrincipal(
new ClaimsIdentity(
[new Claim("TheClaimType", "TheClaimValue")],
"TheAuthenticationType")),
Name = "TheValue"
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ class ClaimsPrincipalConverter :
{
public override void Write(VerifyJsonWriter writer, ClaimsPrincipal principal)
{
if (!principal.Identities.Any())
{
return;
}

// The object is always written, even with no identities. Writing no token at all
// leaves the writer in Property state after the caller has written the member
// name, which corrupts every subsequent write. WriteMember drops the empty
// Identities collection, so an empty principal renders as {}.
writer.WriteStartObject();
writer.WriteMember(principal, principal.Identities, "Identities");
writer.WriteEndObject();
Expand Down
Loading