-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright © by Jeff Foley 2017-2024. All rights reserved. | ||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package registration | ||
|
||
import ( | ||
"encoding/json" | ||
"net/netip" | ||
|
||
model "github.com/owasp-amass/open-asset-model" | ||
) | ||
|
||
// IPNetRecord represents the RDAP record for an IP network. | ||
type IPNetRecord struct { | ||
Raw string `json:"raw,omitempty"` | ||
CIDR netip.Prefix `json:"cidr,omitempty"` | ||
Handle string `json:"handle"` | ||
StartAddress netip.Addr `json:"start_address"` | ||
EndAddress netip.Addr `json:"end_address"` | ||
Type string `json:"type"` | ||
Name string `json:"name"` | ||
Method string `json:"method,omitempty"` | ||
Country string `json:"country,omitempty"` | ||
ParentHandle string `json:"parent_handle,omitempty"` | ||
WhoisServer string `json:"whois_server,omitempty"` | ||
CreatedDate string `json:"created_date,omitempty"` | ||
UpdatedDate string `json:"updated_date,omitempty"` | ||
Status []string `json:"status,omitempty"` | ||
} | ||
|
||
// Key implements the Asset interface. | ||
func (ip IPNetRecord) Key() string { | ||
return ip.Handle | ||
} | ||
|
||
// AssetType implements the Asset interface. | ||
func (ip IPNetRecord) AssetType() model.AssetType { | ||
return model.IPNetRecord | ||
} | ||
|
||
// JSON implements the Asset interface. | ||
func (ip IPNetRecord) JSON() ([]byte, error) { | ||
return json.Marshal(ip) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright © by Jeff Foley 2017-2024. All rights reserved. | ||
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package registration | ||
|
||
import ( | ||
"net/netip" | ||
"testing" | ||
|
||
model "github.com/owasp-amass/open-asset-model" | ||
) | ||
|
||
func TestIPNetRecordKey(t *testing.T) { | ||
want := "NET-150-154-0-0-1" | ||
as := IPNetRecord{Handle: want} | ||
|
||
if got := as.Key(); got != want { | ||
t.Errorf("IPNetRecord.Key() = %v, want %v", got, want) | ||
} | ||
} | ||
|
||
func TestIPNetRecordAssetType(t *testing.T) { | ||
var _ model.Asset = IPNetRecord{} // Verify proper implementation of the Asset interface | ||
var _ model.Asset = (*IPNetRecord)(nil) // Verify the pointer properly implements the Asset interface. | ||
|
||
w := IPNetRecord{} | ||
want := model.IPNetRecord | ||
|
||
if got := w.AssetType(); got != want { | ||
t.Errorf("IPNetRecord.AssetType() = %v, want %v", got, want) | ||
} | ||
} | ||
func TestIPNetRecord(t *testing.T) { | ||
record := IPNetRecord{ | ||
CIDR: netip.MustParsePrefix("150.154.0.0/16"), | ||
Handle: "NET-150-154-0-0-1", | ||
StartAddress: netip.MustParseAddr("150.154.0.0"), | ||
EndAddress: netip.MustParseAddr("150.154.255.255"), | ||
Type: "IPv4", | ||
Name: "REV-MVCC", | ||
Method: "DIRECT ALLOCATION", | ||
ParentHandle: "NET-150-0-0-0-0", | ||
WhoisServer: "whois.arin.net", | ||
CreatedDate: "1991-05-20 04:00:00", | ||
UpdatedDate: "2024-03-28 18:47:50", | ||
Status: []string{"active"}, | ||
} | ||
|
||
// Test AssetType method | ||
if record.AssetType() != model.IPNetRecord { | ||
t.Errorf("Expected asset type %s, but got %s", model.IPNetRecord, record.AssetType()) | ||
} | ||
|
||
// Test JSON method | ||
expectedJSON := `{"cidr":"150.154.0.0/16","handle":"NET-150-154-0-0-1","start_address":"150.154.0.0","end_address":"150.154.255.255","type":"IPv4","name":"REV-MVCC","method":"DIRECT ALLOCATION","parent_handle":"NET-150-0-0-0-0","whois_server":"whois.arin.net","created_date":"1991-05-20 04:00:00","updated_date":"2024-03-28 18:47:50","status":["active"]}` | ||
json, err := record.JSON() | ||
if err != nil { | ||
t.Errorf("Unexpected error: %v", err) | ||
} | ||
if string(json) != expectedJSON { | ||
t.Errorf("Expected JSON %s, but got %s", expectedJSON, string(json)) | ||
} | ||
} |