-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test and fix for malformed/truncated header
- Loading branch information
1 parent
18c1c89
commit 5c4a101
Showing
3 changed files
with
50 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package proxyprotocol | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestParse_Malformed(t *testing.T) { | ||
data := []byte{ | ||
// PROXY protocol v2 magic header | ||
0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A, | ||
// v2 version, PROXY cmd | ||
0x21, | ||
// TCP, IPv4 (also works with 0x13,0x21,0x22,0x31,0x32) | ||
0x12, | ||
// Length | ||
0x00, 0x00, | ||
// src/dest address data _should_ be here but is omitted. | ||
} | ||
|
||
_, err := Parse( | ||
bufio.NewReader( | ||
bytes.NewReader(data))) | ||
assert.Error(t, err) | ||
} |