Manage external site-prober actions va API and Dashboard
This commit is contained in:
1 parent
f22ad569b6
commit
42f584dd3c
28 files changed
+717
-32
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package dashboard
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -207,6 +208,56 @@ func TestSettingsGetAndPut(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSettingsPageShowsInboundChecks(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
fake.inboundPorts = []int{22, 443}
|
||||
fake.inboundICMP = true
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
page := get(t, ts, "/settings")
|
||||
if !strings.Contains(page, `value="22, 443"`) {
|
||||
t.Fatalf("expected seeded ports in the form, got:\n%s", page)
|
||||
}
|
||||
if !strings.Contains(page, "checked") {
|
||||
t.Fatalf("expected icmp checkbox checked, got:\n%s", page)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInboundChecksPutUpdatesForm(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
ts := newTestServer(t, caURL)
|
||||
|
||||
body := postForm(t, ts, "PUT", "/settings/inbound-checks", map[string][]string{"ports": {"8080, 8443"}})
|
||||
if !strings.Contains(body, `value="8080, 8443"`) {
|
||||
t.Fatalf("expected updated ports in re-rendered form, got:\n%s", body)
|
||||
}
|
||||
if !reflect.DeepEqual(fake.inboundPorts, []int{8080, 8443}) || fake.inboundICMP {
|
||||
t.Fatalf("expected fake control-api updated to {[8080 8443] false}, got ports=%v icmp=%v", fake.inboundPorts, fake.inboundICMP)
|
||||
}
|
||||
|
||||
// icmp checkbox checked, empty ports field.
|
||||
body = postForm(t, ts, "PUT", "/settings/inbound-checks", map[string][]string{"ports": {""}, "icmp": {"on"}})
|
||||
if len(fake.inboundPorts) != 0 || !fake.inboundICMP {
|
||||
t.Fatalf("expected fake control-api updated to {[] true}, got ports=%v icmp=%v", fake.inboundPorts, fake.inboundICMP)
|
||||
}
|
||||
if !strings.Contains(body, "checked") {
|
||||
t.Fatalf("expected icmp checkbox checked in re-rendered form, got:\n%s", body)
|
||||
}
|
||||
|
||||
// A malformed ports field is caught by the dashboard itself.
|
||||
body = postForm(t, ts, "PUT", "/settings/inbound-checks", map[string][]string{"ports": {"22, not-a-port"}})
|
||||
if !strings.Contains(body, "alert-warning") {
|
||||
t.Fatalf("expected client error banner for malformed ports, got:\n%s", body)
|
||||
}
|
||||
|
||||
// A control-api validation error (port out of range) surfaces via the
|
||||
// banner too.
|
||||
body = postForm(t, ts, "PUT", "/settings/inbound-checks", map[string][]string{"ports": {"70000"}})
|
||||
if !strings.Contains(body, "alert-warning") {
|
||||
t.Fatalf("expected client error banner for out-of-range port, got:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPsPageShowsSettleBadge(t *testing.T) {
|
||||
fake, caURL := newFakeControlAPI(t)
|
||||
now := time.Now()
|
||||
|
||||
Reference in new issue
Block a user