-
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.
(WIP) start adding tests for code backdooring rule
- Loading branch information
Yevhen Zavhorodnii
committed
May 24, 2024
1 parent
020a961
commit 69128be
Showing
3 changed files
with
124 additions
and
16 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
113 changes: 113 additions & 0 deletions
113
pkg/security/risks/builtin/code_backdooring_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,113 @@ | ||
package builtin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/threagile/threagile/pkg/security/types" | ||
) | ||
|
||
func TestCodeBackdooringRuleGenerateRisksEmptyModelNotRisksCreated(t *testing.T) { | ||
rule := NewCodeBackdooringRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestCodeBackdooringRuleGenerateRisksOutOfScopeNotRisksCreated(t *testing.T) { | ||
rule := NewCodeBackdooringRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
OutOfScope: true, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestCodeBackdooringRuleGenerateRisksTechAssetNotContainSecretsNotRisksCreated(t *testing.T) { | ||
rule := NewCodeBackdooringRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "tool", | ||
Attributes: map[string]bool{ | ||
types.MayContainSecrets: false, | ||
types.IsUsuallyAbleToPropagateIdentityToOutgoingTargets: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestCodeBackdooringRuleGenerateRisksTechAssetFromInternetRisksCreated(t *testing.T) { | ||
rule := NewCodeBackdooringRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"git-lab-ci-cd": { | ||
Title: "GitLab CI/CD", | ||
Internet: true, | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "build-pipeline", | ||
Attributes: map[string]bool{ | ||
types.IsDevelopmentRelevant: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.NotEmpty(t, risks) | ||
assert.Equal(t, "<b>Code Backdooring</b> risk at <b>GitLab CI/CD</b>", risks[0].Title) | ||
assert.Equal(t, types.MediumImpact, risks[0].ExploitationImpact) | ||
} | ||
|
||
func TestCodeBackdooringRuleGenerateRisksTechAssetProcessConfidentialityRisksCreated(t *testing.T) { | ||
rule := NewCodeBackdooringRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"git-lab-ci-cd": { | ||
Title: "GitLab CI/CD", | ||
Internet: true, | ||
Technologies: types.TechnologyList{ | ||
{ | ||
Name: "build-pipeline", | ||
Attributes: map[string]bool{ | ||
types.IsDevelopmentRelevant: true, | ||
}, | ||
}, | ||
}, | ||
DataAssetsProcessed: []string{"critical-data-asset"}, | ||
}, | ||
}, | ||
DataAssets: map[string]*types.DataAsset{ | ||
"critical-data-asset": { | ||
Integrity: types.Critical, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.NotEmpty(t, risks) | ||
assert.Equal(t, "<b>Code Backdooring</b> risk at <b>GitLab CI/CD</b>", risks[0].Title) | ||
assert.Equal(t, types.HighImpact, risks[0].ExploitationImpact) | ||
} |