Skip to content

Commit

Permalink
RavenDB-22990 fix NRE at WhoAmI when cert is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 committed Oct 15, 2024
1 parent 9c35268 commit 9c37e67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ public async Task WhoAmI()
};
certificate = ctx.ReadObject(wellKnownCertDef.ToJson(), "WellKnown/Certificate/Definition");
}
else
{
NoContentStatus();
return;
}
}

await using (var writer = new AsyncBlittableJsonTextWriter(ctx, ResponseBodyStream()))
Expand Down
17 changes: 17 additions & 0 deletions test/SlowTests/Issues/RavenDB-19951.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,23 @@ await store.Maintenance.Server.SendAsync(new EditClientCertificateOperation(new
}
}

[RavenFact(RavenTestCategory.Security)]
public async Task CanAccessWhoAmIWithBadCertificate()
{
var certificates = Certificates.SetupServerAuthentication();
var adminCert = Certificates.RegisterClientCertificate(certificates.ServerCertificate.Value, certificates.ClientCertificate1.Value, new Dictionary<string, DatabaseAccess>(), SecurityClearance.ClusterAdmin);
var userCert = certificates.ClientCertificate2.Value;

using (var store = GetDocumentStore(new Options
{
AdminCertificate = adminCert,
ClientCertificate = userCert
}))
{
var client = new TwoFactorClient(store, userCert);
await client.WhoAmIRequest();
}
}

class TwoFactorClient : IDisposable
{
Expand Down

0 comments on commit 9c37e67

Please sign in to comment.