Skip to content
quarry Artifact [5441bd6419]
Login

Artifact [5441bd6419]

Artifact 5441bd6419e91ccfe1be8bf7699fc0981d7c8131b0b79b97dab815a57dcf2bc1:


package outbound

import "testing"

// Whatever quarry sends on its own initiative goes over https, or over
// http only to this machine (#225).
func TestOnlyHTTPSLeavesTheMachine(t *testing.T) {
	for _, tc := range []struct {
		raw string
		ok  bool
	}{
		{"https://hooks.example/x", true},
		{"http://127.0.0.1:8950/r/quarry", true},
		{"http://localhost:9000", true},
		{"http://[::1]:9000", true},
		{"http://hooks.example/x", false},
		{"http://127.evil.example/x", false},
		{"http://10.0.0.5/x", false},
		{"ftp://files.example/x", false},
		{"https:///nohost", false},
		{"not a url", false},
	} {
		_, err := Check(tc.raw)
		if (err == nil) != tc.ok {
			t.Errorf("FAIL: %q accepted=%v, want %v (%v)", tc.raw, err == nil, tc.ok, err)
		} else {
			t.Logf("ok: %q accepted=%v", tc.raw, tc.ok)
		}
	}
}