-
Notifications
You must be signed in to change notification settings - Fork 129
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
Yevhen Zavhorodnii
committed
May 29, 2024
1 parent
f519297
commit 3d5fc1f
Showing
1 changed file
with
181 additions
and
0 deletions.
There are no files selected for viewing
181 changes: 181 additions & 0 deletions
181
pkg/security/risks/builtin/incomplete_model_rule_test.go
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,181 @@ | ||
package builtin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/threagile/threagile/pkg/security/types" | ||
) | ||
|
||
func TestIncompleteModelRuleGenerateRisksEmptyModelNotRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksOutOfScopeNotRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
OutOfScope: true, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksTechnicalAssetWithoutCommunicationLinksNoRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "tool", | ||
Attributes: map[string]bool{ | ||
types.UnknownTechnology: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksTechnicalAssetContainTechnologyWithoutAttributesRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "tool", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, "<b>Unknown Technology</b> specified at technical asset <b>Test Technical Asset</b>", risks[0].Title) | ||
assert.Equal(t, types.LowImpact, risks[0].ExploitationImpact) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksTechnicalAssetContainUnknownTechnologiesRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "unknown", | ||
Attributes: map[string]bool{ | ||
types.UnknownTechnology: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, "<b>Unknown Technology</b> specified at technical asset <b>Test Technical Asset</b>", risks[0].Title) | ||
assert.Equal(t, types.LowImpact, risks[0].ExploitationImpact) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksNoTechnologySpecifiedRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, "<b>Unknown Technology</b> specified at technical asset <b>Test Technical Asset</b>", risks[0].Title) | ||
assert.Equal(t, types.LowImpact, risks[0].ExploitationImpact) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksKnownProtocolCommunicationLinksNoRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "tool", | ||
Attributes: map[string]bool{ | ||
types.UnknownTechnology: false, | ||
}, | ||
}, | ||
}, | ||
CommunicationLinks: []*types.CommunicationLink{ | ||
{ | ||
Title: "Test Communication Link", | ||
Protocol: types.HTTPS, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestIncompleteModelRuleGenerateRisksUnknownProtocolCommunicationLinksRisksCreated(t *testing.T) { | ||
rule := NewIncompleteModelRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "tool", | ||
Attributes: map[string]bool{ | ||
types.UnknownTechnology: false, | ||
}, | ||
}, | ||
}, | ||
CommunicationLinks: []*types.CommunicationLink{ | ||
{ | ||
Title: "Test Communication Link", | ||
Protocol: types.UnknownProtocol, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, "<b>Unknown Protocol</b> specified for communication link <b>Test Communication Link</b> at technical asset <b>Test Technical Asset</b>", risks[0].Title) | ||
assert.Equal(t, types.LowImpact, risks[0].ExploitationImpact) | ||
} |