Skip to content

Commit

Permalink
added the SourceProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Nov 13, 2024
1 parent 0329528 commit e314bdc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 1 deletion.
3 changes: 2 additions & 1 deletion property.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ type PropertyType string

const (
SimpleProperty PropertyType = "SimpleProperty"
SourceProperty PropertyType = "SourceProperty"
VulnProperty PropertyType = "VulnProperty"
)

var PropertyList = []PropertyType{
SimpleProperty, VulnProperty,
SimpleProperty, SourceProperty, VulnProperty,
}
38 changes: 38 additions & 0 deletions property/source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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 property

import (
"encoding/json"
"strconv"

model "github.com/owasp-amass/open-asset-model"
)

// SourceProperty represents a source of data in the graph.
type SourceProperty struct {
Source string `json:"name"`
Confidence int `json:"confidence"`
}

// Name implements the Property interface.
func (p SourceProperty) Name() string {
return p.Source
}

// Value implements the Property interface.
func (p SourceProperty) Value() string {
return strconv.Itoa(p.Confidence)
}

// PropertyType implements the Property interface.
func (p SourceProperty) PropertyType() model.PropertyType {
return model.SourceProperty
}

// JSON implements the Property interface.
func (p SourceProperty) JSON() ([]byte, error) {
return json.Marshal(p)
}
66 changes: 66 additions & 0 deletions property/source_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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 property

import (
"testing"

model "github.com/owasp-amass/open-asset-model"
"github.com/stretchr/testify/require"
)

func TestSourcePropertyName(t *testing.T) {
want := "anything"
sp := SourceProperty{
Source: "anything",
Confidence: 80,
}

if got := sp.Name(); got != want {
t.Errorf("SourceProperty.Name() = %v, want %v", got, want)
}
}

func TestSourcePropertyValue(t *testing.T) {
want := "80"
sp := SourceProperty{
Source: "anything",
Confidence: 80,
}

if got := sp.Value(); got != want {
t.Errorf("SourceProperty.Value() = %v, want %v", got, want)
}
}

func TestSourcePropertyImplementsProperty(t *testing.T) {
var _ model.Property = SourceProperty{} // Verify proper implementation of the Property interface
var _ model.Property = (*SourceProperty)(nil) // Verify *SourceProperty properly implements the Property interface.
}

func TestSourceProperty(t *testing.T) {
t.Run("Test successful creation of SourceProperty", func(t *testing.T) {
sp := SourceProperty{
Source: "anything",
Confidence: 80,
}

require.Equal(t, "anything", sp.Source)
require.Equal(t, 80, sp.Confidence)
require.Equal(t, sp.PropertyType(), model.SourceProperty)
})

t.Run("Test successful JSON serialization of SourceProperty", func(t *testing.T) {
sp := SourceProperty{
Source: "anything",
Confidence: 80,
}

jsonData, err := sp.JSON()

require.NoError(t, err)
require.JSONEq(t, `{"name":"anything", "confidence":80}`, string(jsonData))
})
}

0 comments on commit e314bdc

Please sign in to comment.