Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Yevhen Zavhorodnii committed May 30, 2024
1 parent bb454b4 commit 29eb214
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/security/risks/builtin/missing_hardening_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ func (r *MissingHardeningRule) GenerateRisks(input *types.Model) ([]*types.Risk,
risks := make([]*types.Risk, 0)
for _, id := range input.SortedTechnicalAssetIDs() {
technicalAsset := input.TechnicalAssets[id]
if !technicalAsset.OutOfScope {
if technicalAsset.RAA >= float64(r.raaLimit) || (technicalAsset.RAA >= float64(r.raaLimitReduced) &&
if technicalAsset.OutOfScope {
continue
}
if technicalAsset.RAA >= float64(r.raaLimit) ||
(technicalAsset.RAA >= float64(r.raaLimitReduced) &&
(technicalAsset.Type == types.Datastore || technicalAsset.Technologies.GetAttribute(types.IsHighValueTarget))) {
risks = append(risks, r.createRisk(input, technicalAsset))
}
risks = append(risks, r.createRisk(input, technicalAsset))
}
}
return risks, nil
Expand Down
16 changes: 16 additions & 0 deletions pkg/security/risks/builtin/missing_hardening_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ func TestMissingHardeningRuleGenerateRisksEmptyModelNotRisksCreated(t *testing.T
assert.Empty(t, risks)
}

func TestMissingHardeningRuleGenerateRisksOutOfScopeNoRisksCreated(t *testing.T) {
rule := NewMissingHardeningRule()
risks, err := rule.GenerateRisks(&types.Model{
TechnicalAssets: map[string]*types.TechnicalAsset{
"ta1": {
Title: "Test Technical Asset",
OutOfScope: true,
RAA: 100,
},
},
})

assert.Nil(t, err)
assert.Empty(t, risks)
}

type MissingHardeningRuleNoRisksTest struct {
raa int
technicalAssetType types.TechnicalAssetType
Expand Down

0 comments on commit 29eb214

Please sign in to comment.