示例#1
0
    def test_extract_resource_id(self):
        rg_id = "/subscriptions/ea98974b-5d2a-4d98-a78a-382f3715d07e/resourceGroups/test_emptyrg"
        nsg_id = rg_id + '/providers/Microsoft.Network/networkSecurityGroups/test-nsg'
        sr_id = nsg_id + '/securityRules/test-rule'
        resource_type = ''
        policy = Mock()
        policy.resource_manager.resource_type.resource_type = resource_type

        event = {'subject': rg_id}
        policy.resource_manager.resource_type.resource_type =\
            'Microsoft.Resources/subscriptions/resourceGroups'
        self.assertEqual(AzureModeCommon.extract_resource_id(policy, event), rg_id)

        event = {'subject': nsg_id}
        policy.resource_manager.resource_type.resource_type =\
            'Microsoft.Resources/subscriptions/resourceGroups'
        self.assertEqual(AzureModeCommon.extract_resource_id(policy, event), rg_id)

        event = {'subject': nsg_id}
        policy.resource_manager.resource_type.resource_type =\
            'Microsoft.Network/networksecuritygroups'
        self.assertEqual(AzureModeCommon.extract_resource_id(policy, event), nsg_id)

        event = {'subject': sr_id}
        policy.resource_manager.resource_type.resource_type =\
            'Microsoft.Network/networksecuritygroups'
        self.assertEqual(AzureModeCommon.extract_resource_id(policy, event), nsg_id)
示例#2
0
 def run(self, event=None, lambda_context=None):
     return AzureModeCommon.run_for_event(self.policy, event)