-
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 30, 2024
1 parent
d63117f
commit 36e6a4c
Showing
1 changed file
with
163 additions
and
0 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
pkg/security/risks/builtin/missing_file_validation_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,163 @@ | ||
package builtin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/threagile/threagile/pkg/security/types" | ||
) | ||
|
||
func TestMissingFileValidationRuleGenerateRisksEmptyModelNotRisksCreated(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
|
||
risks, err := rule.GenerateRisks(&types.Model{}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksOutOfScopeNoRisksCreated(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: true, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksNotCustomlyDevelopedTechnicalAssetNoRisksCreated(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: false, | ||
OutOfScope: false, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksNoFileAcceptedAssetNoRisksCreated(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: false, | ||
DataFormatsAccepted: []types.DataFormat{types.CSV, types.Serialization, types.XML}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Empty(t, risks) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksFileDataFormatsAcceptedRisksCreated(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: false, | ||
DataFormatsAccepted: []types.DataFormat{types.File}, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, types.LowImpact, risks[0].ExploitationImpact) | ||
assert.Equal(t, "<b>Missing File Validation</b> risk at <b>Test Technical Asset</b>", risks[0].Title) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksProcessStrictlyConfidentialDataRisksCreatedWithMediumImpact(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: false, | ||
DataFormatsAccepted: []types.DataFormat{types.File}, | ||
DataAssetsProcessed: []string{"da1"}, | ||
}, | ||
}, | ||
DataAssets: map[string]*types.DataAsset{ | ||
"da1": { | ||
Title: "Test Data Asset", | ||
Confidentiality: types.StrictlyConfidential, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, types.MediumImpact, risks[0].ExploitationImpact) | ||
assert.Equal(t, "<b>Missing File Validation</b> risk at <b>Test Technical Asset</b>", risks[0].Title) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksProcessMissionCriticalIntegrityDataRisksCreatedWithMediumImpact(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: false, | ||
DataFormatsAccepted: []types.DataFormat{types.File}, | ||
DataAssetsProcessed: []string{"da1"}, | ||
}, | ||
}, | ||
DataAssets: map[string]*types.DataAsset{ | ||
"da1": { | ||
Title: "Test Data Asset", | ||
Integrity: types.MissionCritical, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, types.MediumImpact, risks[0].ExploitationImpact) | ||
assert.Equal(t, "<b>Missing File Validation</b> risk at <b>Test Technical Asset</b>", risks[0].Title) | ||
} | ||
|
||
func TestMissingFileValidationRuleGenerateRisksProcessMissionCriticalAvailabilityDataRisksCreatedWithMediumImpact(t *testing.T) { | ||
rule := NewMissingFileValidationRule() | ||
risks, err := rule.GenerateRisks(&types.Model{ | ||
TechnicalAssets: map[string]*types.TechnicalAsset{ | ||
"ta1": { | ||
Title: "Test Technical Asset", | ||
CustomDevelopedParts: true, | ||
OutOfScope: false, | ||
DataFormatsAccepted: []types.DataFormat{types.File}, | ||
DataAssetsProcessed: []string{"da1"}, | ||
}, | ||
}, | ||
DataAssets: map[string]*types.DataAsset{ | ||
"da1": { | ||
Title: "Test Data Asset", | ||
Availability: types.MissionCritical, | ||
}, | ||
}, | ||
}) | ||
|
||
assert.Nil(t, err) | ||
assert.Len(t, risks, 1) | ||
assert.Equal(t, types.MediumImpact, risks[0].ExploitationImpact) | ||
assert.Equal(t, "<b>Missing File Validation</b> risk at <b>Test Technical Asset</b>", risks[0].Title) | ||
} |