@@ -3,16 +3,77 @@ package splithttp_test
33import (
44 "testing"
55
6+ "github.com/stretchr/testify/assert"
67 . "github.com/xtls/xray-core/transport/internet/splithttp"
78)
89
910func Test_GetNormalizedPath (t * testing.T ) {
10- c := Config {
11- Path : "/?world" ,
11+ tests := []struct {
12+ TestName string
13+ Path string
14+ SessionIDPlacement string
15+ SeqPlacement string
16+ Expected string
17+ }{
18+ {
19+ TestName : "default placement keeps trailing slash" ,
20+ Path : "/sh" ,
21+ Expected : "/sh/" ,
22+ },
23+ {
24+ TestName : "query string is stripped" ,
25+ Path : "/?world" ,
26+ Expected : "/" ,
27+ },
28+ {
29+ TestName : "both off path drops trailing slash" ,
30+ Path : "/stream" ,
31+ SessionIDPlacement : "query" ,
32+ SeqPlacement : "query" ,
33+ Expected : "/stream" ,
34+ },
35+ {
36+ TestName : "both off path keeps file-like path" ,
37+ Path : "/stream/filename.extension" ,
38+ SessionIDPlacement : "query" ,
39+ SeqPlacement : "header" ,
40+ Expected : "/stream/filename.extension" ,
41+ },
42+ {
43+ TestName : "seq in path keeps trailing slash" ,
44+ Path : "/stream" ,
45+ SessionIDPlacement : "query" ,
46+ Expected : "/stream/" ,
47+ },
48+ {
49+ TestName : "session in path keeps trailing slash" ,
50+ Path : "/stream" ,
51+ SeqPlacement : "cookie" ,
52+ Expected : "/stream/" ,
53+ },
54+ {
55+ TestName : "existing trailing slash preserved" ,
56+ Path : "/stream/" ,
57+ SessionIDPlacement : "query" ,
58+ SeqPlacement : "query" ,
59+ Expected : "/stream/" ,
60+ },
61+ {
62+ TestName : "root unchanged" ,
63+ Path : "/" ,
64+ SessionIDPlacement : "query" ,
65+ SeqPlacement : "query" ,
66+ Expected : "/" ,
67+ },
1268 }
13-
14- path := c .GetNormalizedPath ()
15- if path != "/" {
16- t .Error ("Unexpected: " , path )
69+ for _ , test := range tests {
70+ t .Run (test .TestName , func (t * testing.T ) {
71+ c := Config {
72+ Path : test .Path ,
73+ SessionIDPlacement : test .SessionIDPlacement ,
74+ SeqPlacement : test .SeqPlacement ,
75+ }
76+ assert .Equal (t , test .Expected , c .GetNormalizedPath ())
77+ })
1778 }
1879}
0 commit comments