Skip to content

Commit

Permalink
RavenDB-21651 CSRF protection in Studio - fixing flacky test
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Nov 7, 2023
1 parent 59c46b4 commit b01f473
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions test/SlowTests/Issues/RavenDB-21651.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public RavenDB_21651(ITestOutputHelper output) : base(output)

public const string ExternalTrustedOriginHostname = "external-trusted-origin";
public const string ExternalTrustedOriginUrl = "http://external-trusted-origin:8080";
public const string ExternalTrustedOriginInHeader = "external-trusted-origin-passed-via-header:8084";
public const string OriginHeader = "X-Forwarded-Host";

public const string ProxyServerHost = "proxy:5656";
Expand Down Expand Up @@ -83,12 +82,9 @@ public async Task CsrfProtectionForSecuredCluster()
var databaseName = GetDatabaseName();
var (_, leader, certificates) = await CreateRaftClusterWithSsl(clusterSize, false);

X509Certificate2 adminCertificate = Certificates.RegisterClientCertificate(certificates, new Dictionary<string, DatabaseAccess>(), SecurityClearance.ClusterAdmin, server: leader);
X509Certificate2 adminCertificate =
Certificates.RegisterClientCertificate(certificates, new Dictionary<string, DatabaseAccess>(), SecurityClearance.ClusterAdmin, server: leader);

var members = leader.ServerStore.GetClusterTopology().Members.Values.ToList();
var nonLeaderUrl = members.First(x => x != leader.WebUrl);
var leaderUrl = leader.WebUrl;

var studioUrl = leader.WebUrl + "/studio/index.html";
var leaderHost = new Uri(leader.WebUrl).Authority;
var sameHostAsLeaderButDifferentPort = "http://" + new Uri(leader.WebUrl).Host + ":21";
Expand Down Expand Up @@ -159,7 +155,9 @@ private async Task ExecuteRequest(HttpMethod method, string uri, Dictionary<stri
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, certificate2, arg3, arg4) => true, SslProtocols = TcpUtils.SupportedSslProtocols
ServerCertificateCustomValidationCallback = (_, _, _, _) => true,
SslProtocols = TcpUtils.SupportedSslProtocols,
AllowAutoRedirect = true
};

if (certificate != null)
Expand All @@ -169,7 +167,7 @@ private async Task ExecuteRequest(HttpMethod method, string uri, Dictionary<stri

using (var httpClient = new HttpClient(handler))
{
HttpRequestMessage request = new HttpRequestMessage {Method = method, RequestUri = new Uri(uri)};
HttpRequestMessage request = new() {Method = method, RequestUri = new Uri(uri)};

if (headers != null)
{
Expand Down

0 comments on commit b01f473

Please sign in to comment.