Add server subnet discovery store, API, and agent policy push.
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
This commit is contained in:
33
server/internal/db/subnet_discoveries_test.go
Normal file
33
server/internal/db/subnet_discoveries_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUpsertSubnetDiscoveryDedupesPorts(t *testing.T) {
|
||||
database, err := New(t.TempDir())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer database.Close()
|
||||
portsA, _ := json.Marshal([]int{22})
|
||||
portsB, _ := json.Marshal([]int{22, 80})
|
||||
if _, err := database.UpsertSubnetDiscovery(SubnetDiscoveryRow{IP: "10.1.1.5", OpenPorts: portsA, SubnetPrefix: "10.1.1", Status: SubnetDiscoveryUninfected}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := database.UpsertSubnetDiscovery(SubnetDiscoveryRow{IP: "10.1.1.5", OpenPorts: portsB, SubnetPrefix: "10.1.1", Status: SubnetDiscoveryUninfected}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
row, err := database.GetSubnetDiscovery("10.1.1.5")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var ports []int
|
||||
if err := json.Unmarshal(row.OpenPorts, &ports); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(ports) != 2 {
|
||||
t.Fatalf("ports=%v", ports)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user