Skip to content

[Appsec]Benchmarks#2537

Merged
anna-git merged 9 commits into
appsec/parsed-body-commonfrom
appsec/anna/parsed-body-common-benchmarks
Mar 7, 2022
Merged

[Appsec]Benchmarks#2537
anna-git merged 9 commits into
appsec/parsed-body-commonfrom
appsec/anna/parsed-body-common-benchmarks

Conversation

@anna-git

@anna-git anna-git commented Mar 7, 2022

Copy link
Copy Markdown
Contributor

Summary of changes

Reason for change

Implementation details

Test coverage

Other details

@anna-git
anna-git requested a review from a team as a code owner March 7, 2022 09:40
@anna-git
anna-git requested review from robertpi and removed request for a team March 7, 2022 09:40
Comment thread tracer/build/_build/Build.Steps.cs Outdated
{
// Build the actual integration test projects for Any CPU
var integrationTestProjects = TracerDirectory.GlobFiles("test/*.IntegrationTests/*.csproj");
var integrationTestProjects = TracerDirectory.GlobFiles("test/*.Security.IntegrationTests/*.csproj");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an error.

@robertpi robertpi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's a minor fix needed, but otherwise looks good.

@andrewlock andrewlock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor suggestions/questions

@@ -0,0 +1,5 @@
{
"DD_APPSEC_ENABLED": true,
"DD_DOTNET_TRACER_HOME": "C:\Repositories\dd-trace-dotnet\tracer\bin\dd-tracer-home\win-x64",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be hard-coded? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed I forgot to change it, removed the file and setting environment variables in the constructor, thanks

Comment on lines +109 to +118
#if !NETFRAMEWORK
public class HttpContextMock : HttpContext
{
private readonly HttpResponseMock responseMock;

public HttpContextMock(HttpResponseMock responseMock)
{
this.responseMock = responseMock;
}
public override ConnectionInfo Connection => throw new NotImplementedException();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure all this is necessary? I think you can use DefaultHttpContext?

@anna-git anna-git Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I wasnt sure how to make sure the response was disposing the waf pointers, but with disposing them manually now in 8eda4fe, no need for all this anymore thanks

Comment on lines +67 to +71
[GlobalSetup]
public void Setup()
{
security = Security.Instance;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rather than using GlobalSetup we typically use a static constructor. Nothing wrong with this AFAIK, just wondered if there was a specific reason for this approach?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there was no reason , as I had problems initializing Security, I tried this and left it 😅

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 2dd5587

Comment on lines +73 to +86
[Benchmark]
public void AllCycleSimpleBody()
{
#if NETFRAMEWORK
Debugger.Break();
using var ms = new MemoryStream();
using var sw = new StreamWriter(ms);
var httpContextMock = new HttpContext(new HttpRequest(string.Empty, string.Empty, string.Empty), new HttpResponse(sw));
security.InstrumentationGateway.RaiseBodyAvailable(httpContextMock, new Span(new SpanContext(1, 1), DateTimeOffset.UtcNow), new { });
#else
var httpContextMock = new HttpContextMock(new HttpResponseMock());
security.InstrumentationGateway.RaiseBodyAvailable(httpContextMock, new Span(new SpanContext(1, 1), DateTimeOffset.UtcNow), new { });
#endif
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to be able to compare these to benchmarks where security is disabled, do we do that currently?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have that in the crank but this was more to benchmark the body, and in particular, the body reflection algorithm.

Comment on lines +92 to +94
using var ms = new MemoryStream();
using var sw = new StreamWriter(ms);
var httpContextMock = new HttpContext(new HttpRequest(string.Empty, string.Empty, string.Empty), new HttpResponse(sw));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this setup should be outside the benchmark itself? Probably not necessary though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! Fixed in 8eda4fe, resources are then disposed after the execution

@anna-git
anna-git merged commit 8eb45a5 into appsec/parsed-body-common Mar 7, 2022
@anna-git
anna-git deleted the appsec/anna/parsed-body-common-benchmarks branch March 7, 2022 19:26
anna-git added a commit that referenced this pull request Mar 7, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 8, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 10, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 16, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 23, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
robertpi added a commit that referenced this pull request Mar 29, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 31, 2022
* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>
anna-git added a commit that referenced this pull request Mar 31, 2022
* Failing test for framework

* Adding extractor for body model and event

* Subscribing to body available in security

* add content type for post request

* Read the parsed body in .NET Framework

Includes:
* Win Forms
* WebApi
* MVC

* Read the parsed body in Net Core (#2501)

Adding a more complex model

Removing tests with block enabled

Removing tests with block enabled Renaming samples wth security prefix to avoid nuke confusion Changing sln accordingly

* Adapt build steps for linux and rename integration right

* Changing snapshot files to match new ressponse content length

* Publish views dll for linux cause we use the publish folder for inte test

fix build

* Start of unit tests for parsed body

* Unit tests and handle some serialization corner cases

* Move code from IG into BodyExtractor.cs

* Better detection of primatives
Detect object graphs with cycles
Only look at instance properties

* Use fields instead of property to avoid side effects

Use fields instead of property to avoid side effects

Fix possible null ref

* [Appsec]Benchmarks (#2537)

* first appsec benchmark

* Remove required filter and add more benchmarks

* Fix benchmarks for .NET framework

* add a more complex object

* fix build steps

* Env variables

* fix benchmarks

* Init httpcontext outside of benchmark

* remove global setup

Co-authored-by: Robert Pickering <[email protected]>

* Adding enum to body extractor

* Remove unneeded code containing a TODO

Adding verified files

* First response to comments

* Fixing duck typing

Factorize peek and pop with Func

remove duck type on real type

* Repsonse to comments

Response to comments

* Fix integration tests

* Fix called several times if 2 binding sources with different id , fix derived attribute

* Adding instrumentation scenario filter to instrumentations

* Readonlydictionary and reuse the empty one

Co-authored-by: Anna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants