initial commit [141.14.140.180,mike]

This commit is contained in:
mike committed 2026-10-26 15:52:55 +01:00
commit e34ba75b7b
33 files changed
+6267

No files matched your search

+87
View File
@@ -0,0 +1,87 @@
package oui
import (
"net"
"path/filepath"
"strings"
"testing"
)
const sampleCSV = `Registry,Assignment,Organization Name,Organization Address
MA-L,3CA62F,AVM Audiovisuelles Marketing und Computersysteme GmbH,Alt-Moabit 95 Berlin DE 10559
MA-L,F0189B,"Apple, Inc.",1 Infinite Loop Cupertino CA US 95014
MA-L,B827EB,Raspberry Pi Foundation,Mitchell Wood House Caldecote GB CB23 7NU
`
const sampleTXT = `OUI/MA-L Organization
company_id Organization
Address
50-C7-BF (hex) TP-LINK TECHNOLOGIES CO.,LTD.
50C7BF (base 16) TP-LINK TECHNOLOGIES CO.,LTD.
Building 24 (floors 1,3,4,5) and 28 (floors1-4)
`
func TestParseAndLookup(t *testing.T) {
db, err := Parse(strings.NewReader(sampleCSV))
if err != nil {
t.Fatal(err)
}
for mac, want := range map[string]string{
"3c:a6:2f:01:02:03": "AVM",
"f0:18:9b:aa:bb:cc": "Apple",
"b8:27:eb:00:00:01": "Raspberry Pi Foundation",
"00:00:00:00:00:01": "",
"da:a1:19:00:00:01": Private,
} {
hw, _ := net.ParseMAC(mac)
if got := db.Lookup(hw); got != want {
t.Errorf("Lookup(%s) = %q, want %q", mac, got, want)
}
}
db, err = Parse(strings.NewReader(sampleTXT))
if err != nil {
t.Fatal(err)
}
hw, _ := net.ParseMAC("50:c7:bf:11:22:33")
if got := db.Lookup(hw); got != "TP-LINK TECHNOLOGIES" {
t.Errorf("txt Lookup = %q", got)
}
}
func TestInstallLoad(t *testing.T) {
path := filepath.Join(t.TempDir(), "oui.tsv")
n, err := Install(strings.NewReader(sampleCSV), path)
if err != nil || n != 3 {
t.Fatalf("Install = %d, %v", n, err)
}
db, err := Load(path)
if err != nil || db.Len() != 3 {
t.Fatalf("Load = %d, %v", db.Len(), err)
}
if _, err := Parse(strings.NewReader("<html>blocked</html>")); err == nil {
t.Error("Parse accepted garbage")
}
}
func TestShortName(t *testing.T) {
for in, want := range map[string]string{
"Apple, Inc.": "Apple",
"Samsung Electronics Co.,Ltd": "Samsung Electronics",
"Sonos, Inc.": "Sonos",
"Espressif Inc.": "Espressif",
"Synology Incorporated": "Synology",
"Hewlett Packard Enterprise, LLC.": "Hewlett Packard Enterprise",
"Ubiquiti Inc": "Ubiquiti",
" Intel Corporate ": "Intel Corporate",
} {
if got := ShortName(in); got != want {
t.Errorf("ShortName(%q) = %q, want %q", in, got, want)
}
}
var nilDB *DB
if nilDB.Lookup(net.HardwareAddr{0, 1, 2, 3, 4, 5}) != "" || nilDB.Len() != 0 {
t.Error("nil DB misbehaves")
}
}