Changeset 60 in code for trunk/morty_test.go
- Timestamp:
- Dec 1, 2016, 12:45:38 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty_test.go
r55 r60 13 13 } 14 14 15 type SanitizeURITestCase struct { 16 Input []byte 17 ExpectedOutput []byte 18 ExpectedScheme string 19 } 20 15 21 type StringTestCase struct { 16 22 Input string … … 38 44 []byte("console.log(document.cookies)"), 39 45 nil, 46 }, 47 } 48 49 var sanitizeUriTestData []*SanitizeURITestCase = []*SanitizeURITestCase{ 50 &SanitizeURITestCase{ 51 []byte("http://example.com/"), 52 []byte("http://example.com/"), 53 "http:", 54 }, 55 &SanitizeURITestCase{ 56 []byte("HtTPs://example.com/ \t"), 57 []byte("https://example.com/"), 58 "https:", 59 }, 60 &SanitizeURITestCase{ 61 []byte(" Ht TPs://example.com/ \t"), 62 []byte("https://example.com/"), 63 "https:", 64 }, 65 &SanitizeURITestCase{ 66 []byte("javascript:void(0)"), 67 []byte("javascript:void(0)"), 68 "javascript:", 69 }, 70 &SanitizeURITestCase{ 71 []byte(" /path/to/a/file/without/protocol "), 72 []byte("/path/to/a/file/without/protocol"), 73 "", 74 }, 75 &SanitizeURITestCase{ 76 []byte(" #fragment "), 77 []byte("#fragment"), 78 "", 79 }, 80 &SanitizeURITestCase{ 81 []byte(" qwertyuiop "), 82 []byte("qwertyuiop"), 83 "", 84 }, 85 &SanitizeURITestCase{ 86 []byte(""), 87 []byte(""), 88 "", 89 }, 90 &SanitizeURITestCase{ 91 []byte(":"), 92 []byte(":"), 93 ":", 94 }, 95 &SanitizeURITestCase{ 96 []byte(" :"), 97 []byte(":"), 98 ":", 99 }, 100 &SanitizeURITestCase{ 101 []byte("schéma:"), 102 []byte("schéma:"), 103 "schéma:", 40 104 }, 41 105 } … … 75 139 } 76 140 141 func TestSanitizeURI(t *testing.T) { 142 for _, testCase := range sanitizeUriTestData { 143 newUrl, scheme := sanitizeURI(testCase.Input) 144 if !bytes.Equal(newUrl, testCase.ExpectedOutput) { 145 t.Errorf( 146 `URL proxifier error. Expected: "%s", Got: "%s"`, 147 testCase.ExpectedOutput, 148 newUrl, 149 ) 150 } 151 if scheme != testCase.ExpectedScheme { 152 t.Errorf( 153 `URL proxifier error. Expected: "%s", Got: "%s"`, 154 testCase.ExpectedScheme, 155 scheme, 156 ) 157 } 158 } 159 } 160 77 161 func TestURLProxifier(t *testing.T) { 78 162 u, _ := url.Parse("http://127.0.0.1/") 79 163 rc := &RequestConfig{BaseURL: u} 80 164 for _, testCase := range urlTestData { 81 newUrl, err := rc.ProxifyURI( testCase.Input)165 newUrl, err := rc.ProxifyURI([]byte(testCase.Input)) 82 166 if err != nil { 83 167 t.Errorf("Failed to parse URL: %s", testCase.Input)
Note:
See TracChangeset
for help on using the changeset viewer.