Deploy managed portal with Docker
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package webdevice
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
@@ -71,3 +72,73 @@ func TestScanBuildsDirectURLAndAllowList(t *testing.T) {
|
||||
t.Fatalf("DirectURL = %q", result.Devices[0].DirectURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestScanIncludesPrivateRequestHostSubnet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
svc := NewService()
|
||||
svc.interfaceGetter = func() ([]InterfaceInfo, error) {
|
||||
return []InterfaceInfo{{
|
||||
Name: "eth0",
|
||||
IP: "172.18.0.2",
|
||||
Netmask: "255.255.0.0",
|
||||
}}, nil
|
||||
}
|
||||
svc.tcpScanner = func(ip, netmask string, port int, excludeIPs map[string]bool) ([]TCPDevice, error) {
|
||||
if ip == "192.168.5.189" {
|
||||
if netmask != "255.255.255.0" {
|
||||
t.Fatalf("request host netmask = %q, want 255.255.255.0", netmask)
|
||||
}
|
||||
if !excludeIPs["192.168.5.189"] {
|
||||
t.Fatal("expected request host IP to be excluded")
|
||||
}
|
||||
return []TCPDevice{{IP: "192.168.5.124", Port: 80}}, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
svc.newForwarder = func(ip string, port int, listenAddress, targetAddress string) (*webDeviceForwarder, error) {
|
||||
return &webDeviceForwarder{ip: ip, port: port, targetAddress: targetAddress}, nil
|
||||
}
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "http://192.168.5.189:13000/api/web-devices/scan", nil)
|
||||
result, err := svc.Scan(req)
|
||||
if err != nil {
|
||||
t.Fatalf("Scan() error = %v", err)
|
||||
}
|
||||
if result.Count != 1 {
|
||||
t.Fatalf("result.Count = %d, want 1", result.Count)
|
||||
}
|
||||
if result.Devices[0].Interface != "request-host" {
|
||||
t.Fatalf("Interface = %q, want request-host", result.Devices[0].Interface)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateIPRangeCapsLargeSubnetToLocal24(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ipRange, err := calculateIPRange("192.168.5.189", "255.255.0.0")
|
||||
if err != nil {
|
||||
t.Fatalf("calculateIPRange() error = %v", err)
|
||||
}
|
||||
if got := ipRange.Start.String(); got != "192.168.5.0" {
|
||||
t.Fatalf("Start = %q, want 192.168.5.0", got)
|
||||
}
|
||||
if got := ipRange.End.String(); got != "192.168.5.255" {
|
||||
t.Fatalf("End = %q, want 192.168.5.255", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateIPRangeKeepsSmallSubnet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ipRange, err := calculateIPRange("192.168.5.189", "255.255.255.240")
|
||||
if err != nil {
|
||||
t.Fatalf("calculateIPRange() error = %v", err)
|
||||
}
|
||||
if got := ipRange.Start.String(); got != "192.168.5.176" {
|
||||
t.Fatalf("Start = %q, want 192.168.5.176", got)
|
||||
}
|
||||
if got := ipRange.End.String(); got != "192.168.5.191" {
|
||||
t.Fatalf("End = %q, want 192.168.5.191", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user