diff options
| author | Shulhan <ms@kilabit.info> | 2025-06-14 19:21:10 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2025-06-16 22:44:37 +0700 |
| commit | f9478c87f6e8553ce42c5fca91c2fc09f9f50d0f (patch) | |
| tree | cd9e6945cf736853c623f00fdd6b9c48f42955e9 /brokenlinks/brokenlinks_test.go | |
| parent | fb9937797a07816fbc8b25fc03893f74bf7c7663 (diff) | |
| download | jarink-f9478c87f6e8553ce42c5fca91c2fc09f9f50d0f.tar.xz | |
brokenlinks: add option "insecure"
The insecure option will allow and not report as error on server with
invalid certificates.
Diffstat (limited to 'brokenlinks/brokenlinks_test.go')
| -rw-r--r-- | brokenlinks/brokenlinks_test.go | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/brokenlinks/brokenlinks_test.go b/brokenlinks/brokenlinks_test.go index b868942..9b176b7 100644 --- a/brokenlinks/brokenlinks_test.go +++ b/brokenlinks/brokenlinks_test.go @@ -16,13 +16,21 @@ import ( "git.sr.ht/~shulhan/jarink/brokenlinks" ) -// The test run two web servers that serve content on "testdata/web/". +// The test run three web servers that serve content on "testdata/web/". // The first web server is the one that we want to scan. // The second web server is external web server, where HTML pages should not // be parsed. +// The third web server is with insecure, self-signed TLS, for testing +// "insecure" option. +// +// Command to generate certificate: +// $ openssl genrsa -out 127.0.0.1.key +// $ openssl x509 -new -key=127.0.0.1.key -subj="/CN=shulhan" \ +// -days=3650 -out=127.0.0.1.pem const testAddress = `127.0.0.1:11836` const testExternalAddress = `127.0.0.1:11900` +const testInsecureAddress = `127.0.0.1:11838` func TestMain(m *testing.M) { log.SetFlags(0) @@ -31,6 +39,7 @@ func TestMain(m *testing.M) { go testServer(fshandle) go testExternalServer(fshandle) + go testInsecureServer(fshandle) var err = libnet.WaitAlive(`tcp`, testAddress, 5*time.Second) if err != nil { @@ -40,6 +49,10 @@ func TestMain(m *testing.M) { if err != nil { log.Fatal(err) } + err = libnet.WaitAlive(`tcp`, testInsecureAddress, 5*time.Second) + if err != nil { + log.Fatal(err) + } os.Exit(m.Run()) } @@ -81,6 +94,24 @@ func testExternalServer(fshandle http.Handler) { } } +func testInsecureServer(fshandle http.Handler) { + var mux = http.NewServeMux() + mux.Handle(`/`, fshandle) + var testServer = &http.Server{ + Addr: testInsecureAddress, + Handler: mux, + ReadTimeout: 10 * time.Second, + WriteTimeout: 10 * time.Second, + MaxHeaderBytes: 1 << 20, + } + var certFile = `testdata/127.0.0.1.pem` + var keyFile = `testdata/127.0.0.1.key` + var err = testServer.ListenAndServeTLS(certFile, keyFile) + if err != nil { + log.Fatal(err) + } +} + func TestBrokenlinks(t *testing.T) { var testUrl = `http://` + testAddress @@ -104,6 +135,7 @@ func TestBrokenlinks(t *testing.T) { opts: brokenlinks.Options{ Url: testUrl, IgnoreStatus: `403`, + Insecure: true, }, exp: map[string][]brokenlinks.Broken{ testUrl: []brokenlinks.Broken{ |
