Skip to content

Commit

Permalink
updated for the OAM v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Aug 22, 2024
1 parent 6bb4bca commit 9d65c0d
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 14 deletions.
5 changes: 4 additions & 1 deletion assetdb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Package assetdb provides a service to interacting with an asset database.
// 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 assetdb

import (
Expand Down
6 changes: 5 additions & 1 deletion assetdb_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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 assetdb

import (
Expand Down Expand Up @@ -547,7 +551,7 @@ func createAssets(db *AssetDB) []*types.Asset {
&whois.Registrar{Name: "Registrar Inc."},
&contact.EmailAddress{Address: "[email protected]"},
&contact.Phone{Raw: "+1-555-555-5555"},
&contact.Location{FormattedAddress: "123 Example St., Example, EX 12345"},
&contact.Location{Address: "123 Example St., Example, EX 12345"},
&oamtls.TLSCertificate{SerialNumber: "1234567890"},
&fingerprint.Fingerprint{Value: "fingerprint"},
&contact.ContactRecord{DiscoveredAt: "https://owasp.org"},
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/caffix/stringset v0.1.2
github.com/glebarez/sqlite v1.11.0
github.com/owasp-amass/open-asset-model v0.4.2
github.com/owasp-amass/open-asset-model v0.5.0
github.com/rubenv/sql-migrate v1.6.0
github.com/stretchr/testify v1.8.4
gorm.io/datatypes v1.2.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/owasp-amass/open-asset-model v0.4.2 h1:qeaCrrnlw3HmT8FILWyCigl1qKgy8vKv2kRurBZHQ4E=
github.com/owasp-amass/open-asset-model v0.4.2/go.mod h1:DOX+SiD6PZBroSMnsILAmpf0SHi6TVpqjV4uNfBeg7g=
github.com/owasp-amass/open-asset-model v0.5.0 h1:+sAqtKZNTwmKq7dkKLC2935v5nr0v+NkTBLcsyZ1HZQ=
github.com/owasp-amass/open-asset-model v0.5.0/go.mod h1:DOX+SiD6PZBroSMnsILAmpf0SHi6TVpqjV4uNfBeg7g=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
15 changes: 13 additions & 2 deletions repository/models.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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 repository

import (
Expand All @@ -12,10 +16,10 @@ import (
"github.com/owasp-amass/open-asset-model/network"
"github.com/owasp-amass/open-asset-model/org"
"github.com/owasp-amass/open-asset-model/people"
"github.com/owasp-amass/open-asset-model/source"
oamtls "github.com/owasp-amass/open-asset-model/tls_certificate"
"github.com/owasp-amass/open-asset-model/url"
"github.com/owasp-amass/open-asset-model/whois"

"gorm.io/datatypes"
)

Expand Down Expand Up @@ -132,6 +136,11 @@ func (a *Asset) Parse() (oam.Asset, error) {

err = json.Unmarshal(a.Content, &url)
asset = &url
case string(oam.Source):
var src source.Source

err = json.Unmarshal(a.Content, &src)
asset = &src
default:
return nil, fmt.Errorf("unknown asset type: %s", a.Type)
}
Expand Down Expand Up @@ -176,13 +185,15 @@ func (a *Asset) JSONQuery() (*datatypes.JSONQueryExpression, error) {
case *contact.EmailAddress:
return jsonQuery.Equals(v.Address, "address"), nil
case *contact.Location:
return jsonQuery.Equals(v.FormattedAddress, "formatted_address"), nil
return jsonQuery.Equals(v.Address, "address"), nil
case *contact.ContactRecord:
return jsonQuery.Equals(v.DiscoveredAt, "discovered_at"), nil
case *oamtls.TLSCertificate:
return jsonQuery.Equals(v.SerialNumber, "serial_number"), nil
case *url.URL:
return jsonQuery.Equals(v.Raw, "url"), nil
case *source.Source:
return jsonQuery.Equals(v.Name, "name"), nil
}

return nil, fmt.Errorf("unknown asset type: %s", a.Type)
Expand Down
18 changes: 16 additions & 2 deletions repository/models_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// 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 repository

import (
Expand All @@ -13,6 +17,7 @@ import (
"github.com/owasp-amass/open-asset-model/network"
"github.com/owasp-amass/open-asset-model/org"
"github.com/owasp-amass/open-asset-model/people"
"github.com/owasp-amass/open-asset-model/source"
oamtls "github.com/owasp-amass/open-asset-model/tls_certificate"
"github.com/owasp-amass/open-asset-model/url"
"github.com/owasp-amass/open-asset-model/whois"
Expand Down Expand Up @@ -79,7 +84,7 @@ func TestModels(t *testing.T) {
},
{
description: "parse location",
asset: &contact.Location{FormattedAddress: "1600 Pennsylvania Ave NW, Washington, DC 20500"},
asset: &contact.Location{Address: "1600 Pennsylvania Ave NW, Washington, DC 20500"},
},
{
description: "parse fingerprint",
Expand All @@ -97,6 +102,10 @@ func TestModels(t *testing.T) {
description: "parse contact record",
asset: &contact.ContactRecord{DiscoveredAt: "https://owasp.org"},
},
{
description: "parse source",
asset: &source.Source{Name: "https://www.owasp.org"},
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -174,7 +183,7 @@ func TestModels(t *testing.T) {
},
{
description: "json query for location",
asset: &contact.Location{FormattedAddress: "1600 Pennsylvania Ave NW, Washington, DC 20500"},
asset: &contact.Location{Address: "1600 Pennsylvania Ave NW, Washington, DC 20500"},
expectedQuery: datatypes.JSONQuery("content").Equals("1600 Pennsylvania Ave NW, Washington, DC 20500", "formatted_address"),
},
{
Expand Down Expand Up @@ -212,6 +221,11 @@ func TestModels(t *testing.T) {
asset: &contact.ContactRecord{DiscoveredAt: "https://owasp.org"},
expectedQuery: datatypes.JSONQuery("content").Equals("https://owasp.org", "discovered_at"),
},
{
description: "json query for source",
asset: &source.Source{Name: "https://www.owasp.org"},
expectedQuery: datatypes.JSONQuery("content").Equals("https://www.owasp.org", "name"),
},
}

for _, tc := range testCases {
Expand Down
6 changes: 4 additions & 2 deletions repository/repository.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Package repository provides a database repository implementation for managing assets and relations.
// It allows creating, retrieving, and linking assets in the database.
// 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 repository

import (
Expand Down
2 changes: 1 addition & 1 deletion repository/sql.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// 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

Expand Down
2 changes: 1 addition & 1 deletion repository/sql_scope.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// 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

Expand Down
2 changes: 1 addition & 1 deletion repository/sql_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © by Jeff Foley 2022-2024. All rights reserved.
// 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

Expand Down

0 comments on commit 9d65c0d

Please sign in to comment.