Changeset 53 in code for trunk


Ignore:
Timestamp:
Nov 29, 2016, 11:11:00 PM (9 years ago)
Author:
asciimoo
Message:

[enh] add url proxifier tests ++ fix proxification user url part handling

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/morty.go

    r52 r53  
    656656        // some web pages describe the whole link https://same:auth@same.host/same.path?same.query#new.fragment
    657657        if u.Scheme == rc.BaseURL.Scheme &&
    658                 ((u.User == nil && rc.BaseURL.User == nil) || (u.User.String() == rc.BaseURL.User.String())) &&
     658                (rc.BaseURL.User == nil || (u.User != nil && u.User.String() == rc.BaseURL.User.String())) &&
    659659                u.Host == rc.BaseURL.Host &&
    660660                u.Path == rc.BaseURL.Path &&
  • trunk/morty_test.go

    r22 r53  
    1111        AttrValue      []byte
    1212        ExpectedOutput []byte
     13}
     14
     15type StringTestCase struct {
     16        Input          string
     17        ExpectedOutput string
    1318}
    1419
     
    3641}
    3742
     43var urlTestData []*StringTestCase = []*StringTestCase{
     44        &StringTestCase{
     45                "http://x.com/",
     46                "./?mortyurl=http%3A%2F%2Fx.com%2F",
     47        },
     48        &StringTestCase{
     49                "http://a@x.com/",
     50                "./?mortyurl=http%3A%2F%2Fa%40x.com%2F",
     51        },
     52}
     53
    3854func TestAttrSanitizer(t *testing.T) {
    3955        u, _ := url.Parse("http://127.0.0.1/")
     
    4561                if !bytes.Equal(res, testCase.ExpectedOutput) {
    4662                        t.Errorf(
    47                                 `Attribute parse error. Name: "%s", Value: "%s", Expected: %s, Got: %s`,
     63                                `Attribute parse error. Name: "%s", Value: "%s", Expected: %s, Got: "%s"`,
    4864                                testCase.AttrName,
    4965                                testCase.AttrValue,
    5066                                testCase.ExpectedOutput,
    5167                                res,
     68                        )
     69                }
     70        }
     71}
     72
     73func TestURLProxifier(t *testing.T) {
     74        u, _ := url.Parse("http://127.0.0.1/")
     75        rc := &RequestConfig{BaseURL: u}
     76        for _, testCase := range urlTestData {
     77                newUrl, err := rc.ProxifyURI(testCase.Input)
     78                if err != nil {
     79                        t.Errorf("Failed to parse URL: %s", testCase.Input)
     80                }
     81                if newUrl != testCase.ExpectedOutput {
     82                        t.Errorf(
     83                                `URL proxifier error. Expected: "%s", Got: "%s"`,
     84                                testCase.ExpectedOutput,
     85                                newUrl,
    5286                        )
    5387                }
Note: See TracChangeset for help on using the changeset viewer.