wjdp / htmltest

:white_check_mark: Test generated HTML for problems
MIT License
323 stars 54 forks source link

HTTPHeaders results in a reflect.Value.MapIndex panic #145

Closed indygriffiths closed 4 years ago

indygriffiths commented 4 years ago

When using HTTPHeaders in an attempt to modify the user agent, htmltest panics when reading the options I've specified even through I believe it's the correct YAML structure

Steps to reproduce the behaviour:

  1. Run htmltest -l 0 with the configuration file below
  2. Observe the panic

.htmltest.yml

HTTPHeaders: 
  User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"

Expected behaviour

htmltest to run with the custom header I've set in the configuration file.

Actual behaviour

It immediately panics when reading the configuration file, and the debug output isn't shown either

$ ./bin/htmltest -l 0
htmltest started at 02:55:14 on <nil>
========================================================================
panic: reflect.Value.MapIndex: value of type interface {} is not assignable to type string

goroutine 1 [running]:
reflect.Value.assignTo(0x729360, 0xc00005fc50, 0x94, 0x79ad65, 0x16, 0x719200, 0x0, 0x729360, 0xc00005fc50, 0x94)
        /home/travis/.gimme/versions/go1.13.6.linux.amd64/src/reflect/value.go:2403 +0x432
reflect.Value.MapIndex(0x72ac20, 0xc000013a70, 0x15, 0x729360, 0xc00005fc50, 0x94, 0x729360, 0xc00005fc60, 0x94)
        /home/travis/.gimme/versions/go1.13.6.linux.amd64/src/reflect/value.go:1168 +0xea
github.com/imdario/mergo.deepMerge(0x72ac20, 0xc000013a70, 0x15, 0x729a20, 0xc000013a10, 0x15, 0xc0001037e0, 0x1, 0xc00000f5c0, 0x0, ...)
        /home/travis/gopath/pkg/mod/github.com/imdario/mergo@v0.3.8/merge.go:97 +0x48b
github.com/imdario/mergo.deepMerge(0x72aa40, 0xc0000103d0, 0x195, 0x72aa40, 0xc0000139e0, 0x15, 0xc0001037e0, 0x0, 0xc00000f5c0, 0x15, ...)
        /home/travis/gopath/pkg/mod/github.com/imdario/mergo@v0.3.8/merge.go:122 +0xa7d
github.com/imdario/mergo.merge(0x70d180, 0xc0000103d0, 0x72aa40, 0xc0000139e0, 0xc0000103d8, 0x1, 0x1, 0x1, 0x7b0bf8)
        /home/travis/gopath/pkg/mod/github.com/imdario/mergo@v0.3.8/merge.go:282 +0x299
github.com/imdario/mergo.MergeWithOverwrite(...)
        /home/travis/gopath/pkg/mod/github.com/imdario/mergo@v0.3.8/merge.go:234
github.com/wjdp/htmltest/htmltest.(*HTMLTest).setOptions(0xc0000da480, 0xc0000139e0)
        /home/travis/gopath/src/github.com/wjdp/htmltest/htmltest/options.go:148 +0x109
github.com/wjdp/htmltest/htmltest.Test(0xc0000139e0, 0xc000010018, 0xc000103d48, 0x1)
        /home/travis/gopath/src/github.com/wjdp/htmltest/htmltest/htmltest.go:47 +0xae
main.run(0xc0000139e0, 0xc0000139e0)
        /home/travis/gopath/src/github.com/wjdp/htmltest/main.go:159 +0x207
main.main()
        /home/travis/gopath/src/github.com/wjdp/htmltest/main.go:66 +0x268

Versions