def test_build_ip_rules(self): data = { 'ip-rules': ['1.1.1.1', '6.0.0.0/16'] } action = StorageSetFirewallAction(data) action.append = False rules = action._build_ip_rules(['1.1.1.1', '8.0.0.0/12'], data['ip-rules']) self.assertEqual(sorted(['1.1.1.1', '6.0.0.0/16']), sorted(rules)) action.append = True rules = action._build_ip_rules(['1.1.1.1', '8.0.0.0/12'], data['ip-rules']) self.assertEqual(sorted(['1.1.1.1', '6.0.0.0/16', '8.0.0.0/12']), sorted(rules))
def test_build_ip_rules_alias(self): data = {'ip-rules': ['ServiceTags.ApiManagement.WestUS', '6.0.0.0/16']} action = StorageSetFirewallAction(data) action.append = False rules = action._build_ip_rules(['1.1.1.1', '8.0.0.0/12'], data['ip-rules']) self.assertIn('6.0.0.0/16', rules) self.assertEqual(4, len(rules)) # With append we expect all our specified values + others from the service tag. action.append = True rules = action._build_ip_rules(['1.1.1.1', '8.0.0.0/12'], data['ip-rules']) self.assertTrue({'6.0.0.0/16', '1.1.1.1', '8.0.0.0/12'} <= set(rules)) self.assertEqual(6, len(rules))