From ffd1d0a3a3f8cd94bf7ffaa9d00972f35bd36f6c Mon Sep 17 00:00:00 2001 From: teowa <104055472+teowa@users.noreply.github.com> Date: Wed, 11 Sep 2024 05:37:44 +0000 Subject: [PATCH] suppress error message for base discriminator prop match --- coverage/coverage.go | 13 ++++++++----- coverage/coverage_test.go | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/coverage/coverage.go b/coverage/coverage.go index 577f223..d57918f 100644 --- a/coverage/coverage.go +++ b/coverage/coverage.go @@ -93,13 +93,14 @@ func (m *Model) CredScan(root interface{}, secrets map[string]string) { if isMatchProperty { for k, v := range value { if m.Properties == nil { - if !m.HasAdditionalProperties { - logrus.Errorf("unexpected key %s in %s", k, m.Identifier) - } + // some objects has no properties defined + // https://github.com/Azure/azure-rest-api-specs/blob/3519c80fe510a268f6e59a29ccac8a53fdec15b6/specification/monitor/resource-manager/Microsoft.Insights/stable/2023-03-11/dataCollectionRules_API.json#L724 + + logrus.Warnf("unexpected key %s in %s", k, m.Identifier) continue } if _, ok := (*m.Properties)[k]; !ok { - if !m.HasAdditionalProperties { + if !m.HasAdditionalProperties && m.Discriminator == nil { logrus.Errorf("unexpected key %s in %s", k, m.Identifier) continue } @@ -194,10 +195,12 @@ func (m *Model) MarkCovered(root interface{}) { if m.Properties == nil { // some objects has no properties defined // https://github.com/Azure/azure-rest-api-specs/blob/3519c80fe510a268f6e59a29ccac8a53fdec15b6/specification/monitor/resource-manager/Microsoft.Insights/stable/2023-03-11/dataCollectionRules_API.json#L724 + logrus.Warnf("unexpected key %s in %s", k, m.Identifier) + continue } if _, ok := (*m.Properties)[k]; !ok { - if !m.HasAdditionalProperties { + if !m.HasAdditionalProperties && m.Discriminator == nil { logrus.Errorf("unexpected key %s in %s", k, m.Identifier) continue } diff --git a/coverage/coverage_test.go b/coverage/coverage_test.go index 748626c..b2c2ae6 100644 --- a/coverage/coverage_test.go +++ b/coverage/coverage_test.go @@ -61,6 +61,28 @@ func TestCoverage_ResourceGroup(t *testing.T) { } } +func TestCoverage_AzureTerraform(t *testing.T) { + tc := testCase{ + name: "AzureTerraform", + resourceType: "Microsoft.AzureTerraform@2023-07-01-preview", + method: "POST", + apiPath: "/subscriptions/12345678-1234-9876-4563-123456789012/providers/Microsoft.AzureTerraform/exportTerraform", + expectedCoveredCount: 3, + expectedTotalCount: 25, + rawRequest: []string{ + `{ + "resourceGroupName" : "rg1", + "type" : "ExportResourceGroup" + }`, + }, + } + + _, err := testCoverage(t, tc) + if err != nil { + t.Fatalf("process coverage: %+v", err) + } +} + func TestCoverage_HealthcareDicom(t *testing.T) { tc := testCase{ name: "HealthcareApisDicom",