-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Support scanning instances/snapshots by a fully qualified azure res…
…ource id. (#2950) Signed-off-by: Preslav <[email protected]>
- Loading branch information
1 parent
1a6763d
commit c0607f5
Showing
3 changed files
with
154 additions
and
29 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
98 changes: 98 additions & 0 deletions
98
providers/azure/connection/azureinstancesnapshot/provider_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,98 @@ | ||
// Copyright (c) Mondoo, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package azureinstancesnapshot | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"go.mondoo.com/cnquery/v9/providers-sdk/v1/inventory" | ||
) | ||
|
||
func TestParseTarget(t *testing.T) { | ||
t.Run("parse snapshot target with just a resource name", func(t *testing.T) { | ||
scanner := &azureScannerInstance{ | ||
instanceInfo: instanceInfo{ | ||
ResourceGroup: "my-rg", | ||
InstanceName: "my-instance", | ||
}, | ||
} | ||
target := "my-other-snapshot" | ||
|
||
conf := &inventory.Config{ | ||
Options: map[string]string{ | ||
"target": target, | ||
"type": "snapshot", | ||
}, | ||
} | ||
scanTarget, err := ParseTarget(conf, scanner) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "my-rg", scanTarget.ResourceGroup) | ||
assert.Equal(t, target, scanTarget.Target) | ||
assert.Equal(t, "snapshot", scanTarget.TargetType) | ||
}) | ||
t.Run("parse instance target with just a resource name", func(t *testing.T) { | ||
scanner := &azureScannerInstance{ | ||
instanceInfo: instanceInfo{ | ||
ResourceGroup: "my-rg", | ||
InstanceName: "my-instance", | ||
}, | ||
} | ||
target := "my-other-instance" | ||
|
||
conf := &inventory.Config{ | ||
Options: map[string]string{ | ||
"target": target, | ||
"type": "instance", | ||
}, | ||
} | ||
scanTarget, err := ParseTarget(conf, scanner) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "my-rg", scanTarget.ResourceGroup) | ||
assert.Equal(t, target, scanTarget.Target) | ||
assert.Equal(t, "instance", scanTarget.TargetType) | ||
}) | ||
t.Run("parse snapshot target with a fully qualifed Azure resource id", func(t *testing.T) { | ||
scanner := &azureScannerInstance{ | ||
instanceInfo: instanceInfo{ | ||
ResourceGroup: "my-rg", | ||
InstanceName: "my-instance", | ||
}, | ||
} | ||
target := "/subscriptions/f1a2873a-6c27-4097-aa7c-3df51f103e91/resourceGroups/my-other-rg/providers/Microsoft.Compute/snapshots/test-snp" | ||
|
||
conf := &inventory.Config{ | ||
Options: map[string]string{ | ||
"target": target, | ||
"type": "snapshot", | ||
}, | ||
} | ||
scanTarget, err := ParseTarget(conf, scanner) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "my-other-rg", scanTarget.ResourceGroup) | ||
assert.Equal(t, "test-snp", scanTarget.Target) | ||
assert.Equal(t, "snapshot", scanTarget.TargetType) | ||
}) | ||
t.Run("parse instance target with a fully qualifed Azure resource id", func(t *testing.T) { | ||
scanner := &azureScannerInstance{ | ||
instanceInfo: instanceInfo{ | ||
ResourceGroup: "my-rg", | ||
InstanceName: "my-instance", | ||
}, | ||
} | ||
target := "/subscriptions/f1a2873a-6b27-4097-aa7c-3df51f103e96/resourceGroups/debian_group/providers/Microsoft.Compute/virtualMachines/debian" | ||
|
||
conf := &inventory.Config{ | ||
Options: map[string]string{ | ||
"target": target, | ||
"type": "instance", | ||
}, | ||
} | ||
scanTarget, err := ParseTarget(conf, scanner) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "debian_group", scanTarget.ResourceGroup) | ||
assert.Equal(t, "debian", scanTarget.Target) | ||
assert.Equal(t, "instance", scanTarget.TargetType) | ||
}) | ||
} |
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