|
1 | | -using BenchmarkDotNet.Attributes; |
2 | | -using BenchmarkDotNet.Jobs; |
3 | | -using Microsoft.Extensions.Logging; |
4 | | -using Microsoft.Net.Http.Headers; |
5 | | -using oidc_guard_tests.Infra; |
6 | | -using System.Security.Claims; |
7 | | - |
8 | | -namespace oidc_guard_benchmarks; |
9 | | - |
10 | | -[JsonExporterAttribute.FullCompressed] |
11 | | -[MemoryDiagnoser] |
12 | | -public class BenchmarkJWT |
13 | | -{ |
14 | | - private HttpClient client = default!; |
15 | | - |
16 | | - private readonly string query = "/auth"; |
17 | | - |
18 | | - [GlobalSetup] |
19 | | - public void GlobalSetup() |
20 | | - { |
21 | | - client = AuthTestsHelpers.GetClient(settings => |
22 | | - { |
23 | | - settings.LogLevel = LogLevel.Error; |
24 | | - }); |
25 | | - |
26 | | - var claims = new List<Claim>() |
27 | | - { |
28 | | - new Claim("tid", "11111111-1111-1111-1111-111111111111"), |
29 | | - new Claim("gcip", "{\"auth_time\":1553219869,\"email\":\"[email protected]\",\"email_verified\":true,\"firebase\":{\"identities\":{\"email\":[\"[email protected]\"],\"saml.myProvider\":[\"[email protected]\"]},\"sign_in_attributes\":{\"firstname\":\"John\",\"group\":\"test group\",\"role\":\"admin\",\"lastname\":\"Doe\"},\"sign_in_provider\":\"saml.myProvider\",\"tenant\":\"my_tenant_id\"},\"sub\":\"gZG0yELPypZElTmAT9I55prjHg63\"}") |
30 | | - }; |
31 | | - |
32 | | - client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.Authorization, FakeJwtIssuer.GenerateBearerJwtToken(claims)); |
33 | | - } |
34 | | - |
35 | | - [Benchmark] |
36 | | - public async Task Auth() |
37 | | - { |
38 | | - await client.GetAsync(query); |
39 | | - } |
40 | | - |
41 | | - [Benchmark] |
42 | | - public async Task AuthCheckClaim() |
43 | | - { |
44 | | - await client.GetAsync(query + "?tid=11111111-1111-1111-1111-111111111111"); |
45 | | - } |
46 | | - |
47 | | - [Benchmark] |
48 | | - public async Task InjectClaims() |
49 | | - { |
50 | | - await client.GetAsync(query + "?inject-claim=tid"); |
51 | | - } |
52 | | - |
53 | | - [Benchmark] |
54 | | - public async Task InjectJsonClaims() |
55 | | - { |
56 | | - await client.GetAsync(query + "?inject-json-claim=role,gcip,$.firebase.sign_in_attributes.role"); |
57 | | - } |
58 | | -} |
| 1 | +using BenchmarkDotNet.Attributes; |
| 2 | +using BenchmarkDotNet.Jobs; |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using Microsoft.Net.Http.Headers; |
| 5 | +using oidc_guard_tests.Infra; |
| 6 | +using System.Security.Claims; |
| 7 | + |
| 8 | +namespace oidc_guard_benchmarks; |
| 9 | + |
| 10 | +[JsonExporterAttribute.FullCompressed] |
| 11 | +[MemoryDiagnoser] |
| 12 | +public class BenchmarkJWT |
| 13 | +{ |
| 14 | + private HttpClient client = default!; |
| 15 | + |
| 16 | + private readonly string query = "/auth"; |
| 17 | + |
| 18 | + [GlobalSetup] |
| 19 | + public void GlobalSetup() |
| 20 | + { |
| 21 | + client = AuthTestsHelpers.GetClient(settings => |
| 22 | + { |
| 23 | + settings.LogLevel = LogLevel.Error; |
| 24 | + }); |
| 25 | + |
| 26 | + var claims = new List<Claim>() |
| 27 | + { |
| 28 | + new Claim("tid", "11111111-1111-1111-1111-111111111111"), |
| 29 | + new Claim("gcip", "{\"auth_time\":1553219869,\"email\":\"[email protected]\",\"email_verified\":true,\"firebase\":{\"identities\":{\"email\":[\"[email protected]\"],\"saml.myProvider\":[\"[email protected]\"]},\"sign_in_attributes\":{\"firstname\":\"John\",\"group\":\"test group\",\"role\":\"admin\",\"lastname\":\"Doe\"},\"sign_in_provider\":\"saml.myProvider\",\"tenant\":\"my_tenant_id\"},\"sub\":\"gZG0yELPypZElTmAT9I55prjHg63\"}") |
| 30 | + }; |
| 31 | + |
| 32 | + client.DefaultRequestHeaders.TryAddWithoutValidation(HeaderNames.Authorization, FakeJwtIssuer.GenerateBearerJwtToken(claims)); |
| 33 | + } |
| 34 | + |
| 35 | + [Benchmark] |
| 36 | + public async Task Auth() |
| 37 | + { |
| 38 | + await client.GetAsync(query); |
| 39 | + } |
| 40 | + |
| 41 | + [Benchmark] |
| 42 | + public async Task AuthCheckClaim() |
| 43 | + { |
| 44 | + await client.GetAsync(query + "?tid=11111111-1111-1111-1111-111111111111"); |
| 45 | + } |
| 46 | + |
| 47 | + [Benchmark] |
| 48 | + public async Task InjectClaims() |
| 49 | + { |
| 50 | + await client.GetAsync(query + "?inject-claim=tid"); |
| 51 | + } |
| 52 | + |
| 53 | + [Benchmark] |
| 54 | + public async Task InjectJsonClaims() |
| 55 | + { |
| 56 | + await client.GetAsync(query + "?inject-json-claim=role,gcip,$.firebase.sign_in_attributes.role"); |
| 57 | + } |
| 58 | +} |
0 commit comments