-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(proxy): removed the udp payload length check when encryption is d…
…isabled
- Loading branch information
Showing
3 changed files
with
106 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,37 +23,80 @@ func equalRequestHeader(x, y *protocol.RequestHeader) bool { | |
})) | ||
} | ||
|
||
func TestUDPEncoding(t *testing.T) { | ||
request := &protocol.RequestHeader{ | ||
Version: Version, | ||
Command: protocol.RequestCommandUDP, | ||
Address: net.LocalHostIP, | ||
Port: 1234, | ||
User: &protocol.MemoryUser{ | ||
Email: "[email protected]", | ||
Account: toAccount(&Account{ | ||
Password: "password", | ||
CipherType: CipherType_AES_128_GCM, | ||
}), | ||
func TestUDPEncodingDecoding(t *testing.T) { | ||
testRequests := []protocol.RequestHeader{ | ||
{ | ||
Version: Version, | ||
Command: protocol.RequestCommandUDP, | ||
Address: net.LocalHostIP, | ||
Port: 1234, | ||
User: &protocol.MemoryUser{ | ||
Email: "[email protected]", | ||
Account: toAccount(&Account{ | ||
Password: "password", | ||
CipherType: CipherType_AES_128_GCM, | ||
}), | ||
}, | ||
}, | ||
{ | ||
Version: Version, | ||
Command: protocol.RequestCommandUDP, | ||
Address: net.LocalHostIP, | ||
Port: 1234, | ||
User: &protocol.MemoryUser{ | ||
Email: "[email protected]", | ||
Account: toAccount(&Account{ | ||
Password: "123", | ||
CipherType: CipherType_NONE, | ||
}), | ||
}, | ||
}, | ||
} | ||
|
||
data := buf.New() | ||
common.Must2(data.WriteString("test string")) | ||
encodedData, err := EncodeUDPPacket(request, data.Bytes()) | ||
common.Must(err) | ||
for _, request := range testRequests { | ||
data := buf.New() | ||
common.Must2(data.WriteString("test string")) | ||
encodedData, err := EncodeUDPPacket(&request, data.Bytes()) | ||
common.Must(err) | ||
|
||
validator := new(Validator) | ||
validator.Add(request.User) | ||
decodedRequest, decodedData, err := DecodeUDPPacket(validator, encodedData) | ||
common.Must(err) | ||
validator := new(Validator) | ||
validator.Add(request.User) | ||
decodedRequest, decodedData, err := DecodeUDPPacket(validator, encodedData) | ||
common.Must(err) | ||
|
||
if r := cmp.Diff(decodedData.Bytes(), data.Bytes()); r != "" { | ||
t.Error("data: ", r) | ||
if r := cmp.Diff(decodedData.Bytes(), data.Bytes()); r != "" { | ||
t.Error("data: ", r) | ||
} | ||
|
||
if equalRequestHeader(decodedRequest, &request) == false { | ||
t.Error("different request") | ||
} | ||
} | ||
} | ||
|
||
if equalRequestHeader(decodedRequest, request) == false { | ||
t.Error("different request") | ||
func TestUDPDecodingWithPayloadTooShort(t *testing.T) { | ||
testAccounts := []protocol.Account{ | ||
toAccount(&Account{ | ||
Password: "password", | ||
CipherType: CipherType_AES_128_GCM, | ||
}), | ||
toAccount(&Account{ | ||
Password: "password", | ||
CipherType: CipherType_NONE, | ||
}), | ||
} | ||
|
||
for _, account := range testAccounts { | ||
data := buf.New() | ||
data.WriteString("short payload") | ||
validator := new(Validator) | ||
validator.Add(&protocol.MemoryUser{ | ||
Account: account, | ||
}) | ||
_, _, err := DecodeUDPPacket(validator, data) | ||
if err == nil { | ||
t.Fatal("expected error") | ||
} | ||
} | ||
} | ||
|
||
|
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