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

[packetbeat/protos/http] fix: non-standard http host format error and add extract host tests. #36498

Closed
wants to merge 6 commits into from

Conversation

moonD4rk
Copy link

@moonD4rk moonD4rk commented Sep 4, 2023

Proposed commit message

fix: non-standard http host format when packetbeat capture http request and add extract host test cases.

  • Add test for extractHostHeader function

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Author's Checklist

  • [ ]

How to test this PR locally

check and use go test -v ./...

Related issues

Use cases

Packetbeat panic when HTTP requests that have a non-standard Host header. such as :1234

TestCase

func TestHttpParser_extractHostHeader(t *testing.T) {
	var testCases = []struct {
		host       string
		wantedHost string
		wantedPort int
	}{
		{":1234", "", 1234},
	}
	for _, tc := range testCases {
		host, port := extractHostHeader(tc.host)
		assert.Equal(t, tc.wantedHost, host)
		assert.Equal(t, tc.wantedPort, port)
	}
}

use go test -v ./...

before:

=== RUN   TestHttpParser_extractHostHeader
--- FAIL: TestHttpParser_extractHostHeader (0.00s)
panic: runtime error: index out of range [0] with length 0 [recovered]
	panic: runtime error: index out of range [0] with length 0

after:

=== RUN   TestHttpParser_extractHostHeader
--- PASS: TestHttpParser_extractHostHeader (0.00s)
PASS

Screenshots

Logs

@moonD4rk moonD4rk requested a review from a team as a code owner September 4, 2023 12:35
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Sep 4, 2023
@cla-checker-service
Copy link

cla-checker-service bot commented Sep 4, 2023

💚 CLA has been signed

@mergify
Copy link
Contributor

mergify bot commented Sep 4, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @moonD4rk? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 4, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-09-05T19:21:23.673+0000

  • Duration: 47 min 10 sec

Test stats 🧪

Test Results
Failed 0
Passed 2361
Skipped 25
Total 2386

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Sep 5, 2023
@bhapas
Copy link
Contributor

bhapas commented Sep 5, 2023

@moonD4rk

Thank you for your contribution. Can you please sign the CLA agreement for contributors for CI to proceed running your change. - Contributor Agreement

@bhapas bhapas changed the title fix: non-standard http host format error and add extract host tests. [packetbeat/protos/http] fix: non-standard http host format error and add extract host tests. Sep 5, 2023
@bhapas
Copy link
Contributor

bhapas commented Sep 5, 2023

/test

@bhapas bhapas added the backport-v8.10.0 Automated backport with mergify label Sep 5, 2023
@moonD4rk
Copy link
Author

moonD4rk commented Sep 5, 2023

@moonD4rk

Thank you for your contribution. Can you please sign the CLA agreement for contributors for CI to proceed running your change. - Contributor Agreement

Hi, I'm already signed and passed the CI test.

@bhapas
Copy link
Contributor

bhapas commented Sep 5, 2023

Thanks @moonD4rk
Can you add a changelog after

- Fixed some race conditions in tests {pull}36185[36185]

@bhapas
Copy link
Contributor

bhapas commented Sep 5, 2023

/test

@bhapas
Copy link
Contributor

bhapas commented Sep 5, 2023

/test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[packetbeat] panic when parsing HTTP host header with non-standard format
3 participants