mirror of
https://github.com/aquasecurity/kube-bench.git
synced 2024-12-24 07:28:06 +00:00
c3f94dd89f
* add aasf * add AASF format * credentials provider * add finding publisher * add finding publisher * add write AASF path * add testing * read config from file * update docker file * refactor * remove sample * add comments * Add comment in EKS config.yaml * Fix comment typo * Fix spelling of ASFF * Fix typo and other small code review suggestions * Limit length of Actual result field Avoids this message seen in testing: Message:Finding does not adhere to Amazon Finding Format. data.ProductFields['Actual result'] should NOT be longer than 1024 characters. * Add comment for ASFF schema * Add Security Hub documentation * go mod tidy * remove dupe lines in docs * support integration in any region * fix README link * fix README links Co-authored-by: Liz Rice <liz@lizrice.com>
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package findings
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/aws/aws-sdk-go/service/securityhub"
|
|
"github.com/aws/aws-sdk-go/service/securityhub/securityhubiface"
|
|
)
|
|
|
|
// Define a mock struct to be used in your unit tests of myFunc.
|
|
type MockSHClient struct {
|
|
securityhubiface.SecurityHubAPI
|
|
Batches int
|
|
NumberOfFinding int
|
|
}
|
|
|
|
func NewMockSHClient() *MockSHClient {
|
|
return &MockSHClient{}
|
|
}
|
|
|
|
func (m *MockSHClient) BatchImportFindings(input *securityhub.BatchImportFindingsInput) (*securityhub.BatchImportFindingsOutput, error) {
|
|
o := securityhub.BatchImportFindingsOutput{}
|
|
m.Batches++
|
|
m.NumberOfFinding = len(input.Findings)
|
|
return &o, nil
|
|
}
|
|
|
|
func TestPublisher_publishFinding(t *testing.T) {
|
|
type fields struct {
|
|
client *MockSHClient
|
|
}
|
|
type args struct {
|
|
finding []*securityhub.AwsSecurityFinding
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields fields
|
|
args args
|
|
wantBatchCount int
|
|
wantFindingCount int
|
|
}{
|
|
{"Test single finding", fields{NewMockSHClient()}, args{makeFindings(1)}, 1, 1},
|
|
{"Test 150 finding should return 2 batches", fields{NewMockSHClient()}, args{makeFindings(150)}, 2, 150},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
p := New(tt.fields.client)
|
|
p.PublishFinding(tt.args.finding)
|
|
if tt.fields.client.NumberOfFinding != tt.wantFindingCount {
|
|
t.Errorf("Publisher.publishFinding() want = %v, got %v", tt.wantFindingCount, tt.fields.client.NumberOfFinding)
|
|
}
|
|
if tt.fields.client.Batches != tt.wantBatchCount {
|
|
t.Errorf("Publisher.publishFinding() want = %v, got %v", tt.wantBatchCount, tt.fields.client.Batches)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func makeFindings(count int) []*securityhub.AwsSecurityFinding {
|
|
var findings []*securityhub.AwsSecurityFinding
|
|
|
|
for i := 0; i < count; i++ {
|
|
t := securityhub.AwsSecurityFinding{}
|
|
findings = append(findings, &t)
|
|
|
|
}
|
|
return findings
|
|
}
|