@@ -4,6 +4,7 @@ package cmd
44
55import (
66 "context"
7+ "errors"
78 "net/url"
89 "testing"
910)
@@ -24,11 +25,6 @@ func Test_newBinaryCmd_Key_Value_Pair(t *testing.T) {
2425 urlString : "binary:///executable?-key=value" ,
2526 expected : `\executable -key value` ,
2627 },
27- {
28- name : "Path_With_Back_Slashes" ,
29- urlString : `binary:///\executable?-key=value` ,
30- expected : `\executable -key value` ,
31- },
3228 {
3329 name : "Clean_Path_With_Dots_And_Multiple_Fwd_Slashes" ,
3430 urlString : "binary:///../path/to///to/../executable" ,
@@ -70,6 +66,45 @@ func Test_newBinaryCmd_Key_Value_Pair(t *testing.T) {
7066 }
7167}
7268
69+ func Test_newBinaryCmd_Unsafe_Path (t * testing.T ) {
70+ ctx , cancel := context .WithCancel (context .Background ())
71+ defer cancel ()
72+
73+ type config struct {
74+ name string
75+ urlString string
76+ expectedError error
77+ }
78+
79+ for _ , cfg := range []* config {
80+ {
81+ name : "UNC_Path_With_Back_Slashes" ,
82+ urlString : `binary:///\server\share\executable` ,
83+ expectedError : ErrUnsafePath ,
84+ },
85+ {
86+ name : "UNC_Path_With_Forward_Slashes" ,
87+ urlString : `binary:////server/share/executable` ,
88+ expectedError : ErrUnsafePath ,
89+ },
90+ } {
91+ t .Run (cfg .name , func (t * testing.T ) {
92+ u , err := url .Parse (cfg .urlString )
93+ if err != nil {
94+ t .Fatalf ("failed to parse url: %s" , cfg .urlString )
95+ }
96+
97+ _ , err = newBinaryCmd (ctx , u , nil )
98+ if err == nil {
99+ t .Fatalf ("no error was returned" )
100+ }
101+ if ! errors .Is (err , cfg .expectedError ) {
102+ t .Fatalf ("expected error: %s, actual: %s" , cfg .expectedError , err )
103+ }
104+ })
105+ }
106+ }
107+
73108func Test_newBinaryCmd_Empty_Path (t * testing.T ) {
74109 ctx , cancel := context .WithCancel (context .Background ())
75110 defer cancel ()
0 commit comments