From 1518bdc31da09fbb644656d7944b8bb58e77d72f Mon Sep 17 00:00:00 2001 From: Yevhen Zavhorodnii Date: Tue, 4 Jun 2024 17:40:18 +0100 Subject: [PATCH] Cover unnecessary technical asset rule with tests --- .../unnecessary_technical_asset_rule_test.go | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 pkg/security/risks/builtin/unnecessary_technical_asset_rule_test.go diff --git a/pkg/security/risks/builtin/unnecessary_technical_asset_rule_test.go b/pkg/security/risks/builtin/unnecessary_technical_asset_rule_test.go new file mode 100644 index 00000000..4b882208 --- /dev/null +++ b/pkg/security/risks/builtin/unnecessary_technical_asset_rule_test.go @@ -0,0 +1,82 @@ +package builtin + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/threagile/threagile/pkg/security/types" +) + +func TestUnnecessaryTechnicalAssetRuleGenerateRisksEmptyModelNotRisksCreated(t *testing.T) { + rule := NewUnnecessaryTechnicalAssetRule() + + risks, err := rule.GenerateRisks(&types.Model{}) + + assert.Nil(t, err) + assert.Empty(t, risks) +} + +func TestUnnecessaryTechnicalAssetRuleGenerateRisksNoDataProcessedOrStoreNotRisksCreated(t *testing.T) { + rule := NewUnnecessaryTechnicalAssetRule() + + risks, err := rule.GenerateRisks(&types.Model{ + TechnicalAssets: map[string]*types.TechnicalAsset{ + "ta1": { + Title: "Technical Asset", + Id: "ta1", + DataAssetsProcessed: []string{}, + DataAssetsStored: []string{}, + CommunicationLinks: []*types.CommunicationLink{}, + }, + }, + }) + + assert.Nil(t, err) + assert.Len(t, risks, 1) + assert.Equal(t, "Unnecessary Technical Asset named Technical Asset", risks[0].Title) +} + +func TestUnnecessaryTechnicalAssetRuleSomeDataStoredAndSomeOutgoingCommunicationNotRisksCreated(t *testing.T) { + rule := NewUnnecessaryTechnicalAssetRule() + risks, err := rule.GenerateRisks(&types.Model{ + TechnicalAssets: map[string]*types.TechnicalAsset{ + "ta1": { + Title: "First Technical Asset", + Id: "ta1", + DataAssetsProcessed: []string{}, + DataAssetsStored: []string{"data"}, + CommunicationLinks: []*types.CommunicationLink{ + { + DataAssetsSent: []string{"data"}, + TargetId: "ta2", + SourceId: "ta1", + }, + }, + }, + "ta2": { + Title: "Second Technical Asset", + Id: "ta2", + DataAssetsProcessed: []string{"data"}, + DataAssetsStored: []string{}, + }, + }, + DataAssets: map[string]*types.DataAsset{ + "data": { + Id: "data", + Title: "data", + }, + }, + IncomingTechnicalCommunicationLinksMappedByTargetId: map[string][]*types.CommunicationLink{ + "ta2": { + { + DataAssetsReceived: []string{"data"}, + TargetId: "ta1", + SourceId: "ta2", + }, + }, + }, + }) + + assert.Nil(t, err) + assert.Empty(t, risks) +}