Fix random_ipv6_cidr network generation, with test (#4438)

This commit is contained in:
Daniel Fangl 2021-10-19 15:04:30 +02:00 committed by GitHub
parent cc5a5c3d72
commit 0b647fdb8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -252,7 +252,7 @@ def randor_ipv4_cidr():
def random_ipv6_cidr():
return "2400:6500:{}:{}::/56".format(random_resource_id(4), random_resource_id(4))
return "2400:6500:{}:{}00::/56".format(random_resource_id(4), random_resource_id(2))
def generate_route_id(

View File

@ -1,3 +1,6 @@
import ipaddress
from unittest.mock import patch
from moto.ec2 import utils
from .helpers import rsa_check_private_key
@ -10,3 +13,13 @@ def test_random_key_pair():
# AWS uses MD5 fingerprints, which are 47 characters long, *not* SHA1
# fingerprints with 59 characters.
assert len(key_pair["fingerprint"]) == 47
def test_random_ipv6_cidr():
def mocked_random_resource_id(chars: int):
return "a" * chars
with patch("moto.ec2.utils.random_resource_id", mocked_random_resource_id):
cidr_address = utils.random_ipv6_cidr()
# this will throw value error if host bits are set
ipaddress.ip_network(cidr_address)