Changeset 22 in code
- Timestamp:
- Oct 30, 2016, 4:51:27 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/morty_test.go
r16 r22 38 38 func TestAttrSanitizer(t *testing.T) { 39 39 u, _ := url.Parse("http://127.0.0.1/") 40 rc := &RequestConfig{ nil,u}40 rc := &RequestConfig{BaseURL: u} 41 41 for _, testCase := range attrTestData { 42 42 out := bytes.NewBuffer(nil) 43 sanitizeAttr(rc, out, testCase.AttrName, testCase.AttrValue )43 sanitizeAttr(rc, out, testCase.AttrName, testCase.AttrValue, testCase.AttrValue) 44 44 res, _ := out.ReadBytes(byte(0)) 45 45 if !bytes.Equal(res, testCase.ExpectedOutput) { … … 54 54 } 55 55 } 56 57 var BENCH_SIMPLE_HTML []byte = []byte(`<!doctype html> 58 <html> 59 <head> 60 <title>test</title> 61 </head> 62 <body> 63 <h1>Test heading</h1> 64 </body> 65 </html>`) 66 67 func BenchmarkSanitizeSimpleHTML(b *testing.B) { 68 u, _ := url.Parse("http://127.0.0.1/") 69 rc := &RequestConfig{BaseURL: u} 70 b.ResetTimer() 71 for i := 0; i < b.N; i++ { 72 out := bytes.NewBuffer(nil) 73 sanitizeHTML(rc, out, BENCH_SIMPLE_HTML) 74 } 75 } 76 77 var BENCH_COMPLEX_HTML []byte = []byte(`<!doctype html> 78 <html> 79 <head> 80 <noscript><meta http-equiv="refresh" content="0; URL=./xy"></noscript> 81 <title>test 2</title> 82 <script> alert('xy'); </script> 83 <link rel="stylesheet" href="./core.bundle.css"> 84 <style> 85 html { background: url(./a.jpg); } 86 </style 87 </head> 88 <body> 89 <h1>Test heading</h1> 90 <img src="b.png" alt="imgtitle" /> 91 <form action="/z"> 92 <input type="submit" style="background: url(http://aa.bb/cc)" > 93 </form> 94 </body> 95 </html>`) 96 97 func BenchmarkSanitizeComplexHTML(b *testing.B) { 98 u, _ := url.Parse("http://127.0.0.1/") 99 rc := &RequestConfig{BaseURL: u} 100 b.ResetTimer() 101 for i := 0; i < b.N; i++ { 102 out := bytes.NewBuffer(nil) 103 sanitizeHTML(rc, out, BENCH_COMPLEX_HTML) 104 } 105 }
Note:
See TracChangeset
for help on using the changeset viewer.