Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: setup benchmark project for Antiforgery #2033

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions build/job-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ variables:
value: --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/database.benchmarks.yml
- name: jsonJobs
value: --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/json.benchmarks.yml
- name: antiforgeryJobs
value: --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/antiforgery.benchmarks.yml
- name: goldilocksJobs
value: --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/goldilocks.benchmarks.yml
- name: monoJobs
Expand Down
5 changes: 5 additions & 0 deletions build/trend-scenarios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ parameters:
- displayName: Json 10k
arguments: --scenario json_middleware --variable singleStringJsonSize=10000 --config https://raw.githubusercontent.com/aspnet/Benchmarks/main/scenarios/json.benchmarks.yml --property scenario=Json10k

# Antiforgery

- displayName: Antiforgery
arguments: --scenario antiforgery $(antiforgeryJobs) --property scenario=Antiforgery

steps:
- ${{ each s in parameters.scenarios }}:
- task: PublishToAzureServiceBus@2
Expand Down
31 changes: 31 additions & 0 deletions scenarios/antiforgery.benchmarks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# usage: crank --config https://raw.githubusercontent.com/DeagleGross/Benchmarks/refs/heads/dmkorolev/antiforgery-sample/scenarios/antiforgery.benchmarks.yml --scenario antiforgery --profile aspnet-perf-win --application.source.branchOrCommit dmkorolev/antiforgery-sample --application.source.repository https://github.com/DeagleGross/Benchmarks.git

imports:
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.Wrk/wrk.yml
- https://raw.githubusercontent.com/dotnet/crank/main/src/Microsoft.Crank.Jobs.HttpClient/httpclient.yml
- https://github.com/aspnet/Benchmarks/blob/main/scenarios/aspnet.profiles.yml?raw=true

variables:
serverPort: 5000
serverScheme: http

jobs:
antiforgerybenchmarks:
source:
repository: https://github.com/aspnet/benchmarks.git
branchOrCommit: main
project: src/BenchmarksApps/Antiforgery/Antiforgery.csproj
readyStateText: Application started.
# arguments: "--urls {{serverScheme}}://{{serverAddress}}:{{serverPort}}"

scenarios:

antiforgery:
application:
job: antiforgerybenchmarks
variables:
scenario: antiforgery
load:
job: wrk
variables:
path: /getAndValidateToken
20 changes: 15 additions & 5 deletions src/BenchmarksApps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RunTemplate", "BenchmarksAp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Json", "BenchmarksApps\Json\Json.csproj", "{CEBEA47D-8154-4DC1-B071-6FAEAC448C88}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Antiforgery", "BenchmarksApps\Antiforgery\Antiforgery.csproj", "{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug_Database|Any CPU = Debug_Database|Any CPU
Expand Down Expand Up @@ -248,20 +250,28 @@ Global
{CEBEA47D-8154-4DC1-B071-6FAEAC448C88}.Release_Database|Any CPU.Build.0 = Release_Database|Any CPU
{CEBEA47D-8154-4DC1-B071-6FAEAC448C88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEBEA47D-8154-4DC1-B071-6FAEAC448C88}.Release|Any CPU.Build.0 = Release|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Debug_Database|Any CPU.ActiveCfg = Debug_Database|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Debug_Database|Any CPU.Build.0 = Debug_Database|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Debug|Any CPU.Build.0 = Debug|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Release_Database|Any CPU.ActiveCfg = Release_Database|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Release_Database|Any CPU.Build.0 = Release_Database|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Release|Any CPU.ActiveCfg = Release|Any CPU
{38AEFB02-3AE4-4E01-8FF9-FF09797C5853}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{8DF3A6BB-E8C5-4FAA-839A-D185C9F93CD5} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{9E4AF835-2A78-4012-B0B5-9DA41ACDC716} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{20757830-EA66-4962-BDBB-A101A2062A2C} = {9E4AF835-2A78-4012-B0B5-9DA41ACDC716}
{07C0B18B-9738-4349-A8DF-3E88D3DF90AE} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{20757830-EA66-4962-BDBB-A101A2062A2C} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{07C0B18B-9738-4349-A8DF-3E88D3DF90AE} = {9E4AF835-2A78-4012-B0B5-9DA41ACDC716}
{E68B58F8-40EA-49EA-A126-0B67F2BE7343} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{ACA43671-AD28-4F72-AAAB-6C32B388C2F0} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{D8F11F87-823F-4864-926D-5F66448A5C13} = {398A40DA-FE1D-4B4D-A580-A33E29885553}
{3D2573DE-CE7A-4CB8-A980-8C8636EE059E} = {6A69DE6C-07A6-4ABE-A4D2-0F983A33BBF8}
{31B61CD7-4CF6-464F-B418-04C700A17CB9} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{D8F11F87-823F-4864-926D-5F66448A5C13} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{3D2573DE-CE7A-4CB8-A980-8C8636EE059E} = {398A40DA-FE1D-4B4D-A580-A33E29885553}
{31B61CD7-4CF6-464F-B418-04C700A17CB9} = {6A69DE6C-07A6-4ABE-A4D2-0F983A33BBF8}
{D6616E03-A2DA-4929-AD28-595ECC4C004D} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
9 changes: 9 additions & 0 deletions src/BenchmarksApps/Antiforgery/Antiforgery.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
26 changes: 26 additions & 0 deletions src/BenchmarksApps/Antiforgery/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Microsoft.AspNetCore.Antiforgery;

var builder = WebApplication.CreateBuilder();

builder.Services.AddAntiforgery(options => options.HeaderName = "X-XSRF-TOKEN");
DeagleGross marked this conversation as resolved.
Show resolved Hide resolved

var app = builder.Build();

app.UseAntiforgery();

app.MapGet("/", () => Results.Ok("hello world!"));

app.MapPost("/getAndValidateToken", async (HttpContext ctx, IAntiforgery antiforgery) =>
{
if (!ctx.Request.Cookies.ContainsKey("XSRF-TOKEN"))
{
var token = antiforgery.GetAndStoreTokens(ctx);
ctx.Response.Cookies.Append("XSRF-TOKEN", token.RequestToken!, new CookieOptions { HttpOnly = false });
return Results.Ok();
}

await antiforgery.ValidateRequestAsync(ctx);
return Results.Ok();
});

app.Run();
12 changes: 12 additions & 0 deletions src/BenchmarksApps/Antiforgery/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"Antiforgery": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:55471;http://localhost:55472"
}
}
}
8 changes: 8 additions & 0 deletions src/BenchmarksApps/Antiforgery/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/BenchmarksApps/Antiforgery/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}