def test_multiple_dns(dns, dummy): address = '192.168.0.2' peer = Peer( 'test-peer', address=address, dns=dns, ) config = Config(peer) wg_config = config.local_config config_lines = wg_config.split('\n') # Because the set of DNS entries could return in any order, check that at least one is present assert ('DNS = 1.1.1.1,2.2.2.2,3.3.3.3' in config_lines or 'DNS = 1.1.1.1,3.3.3.3,2.2.2.2' in config_lines or 'DNS = 2.2.2.2,1.1.1.1,3.3.3.3' in config_lines or 'DNS = 2.2.2.2,3.3.3.3,1.1.1.1' in config_lines or 'DNS = 3.3.3.3,1.1.1.1,2.2.2.2' in config_lines or 'DNS = 3.3.3.3,2.2.2.2,1.1.1.1' in config_lines) # Check that these don't appear anywhere at all because of how basic this config is for option in [ 'PreUp', 'PostUp', 'PreDown', 'PostDown', 'SaveConfig', 'MTU', 'Table', 'AllowedIPs', 'Endpoint', 'PersistentKeepalive', 'PresharedKey', 'PublicKey' ]: assert f'{option} =' not in wg_config peer.dns = None assert config.dns is None
def test_dns(): address = '192.168.0.2' peer = Peer( 'test-peer', address=address, dns='8.8.8.8', ) config = Config(peer) wg_config = config.local_config config_lines = wg_config.split('\n') assert 'DNS = 8.8.8.8' in config_lines # Check that these don't appear anywhere at all because of how basic this config is for option in [ 'PreUp', 'PostUp', 'PreDown', 'PostDown', 'SaveConfig', 'MTU', 'Table', 'AllowedIPs', 'Endpoint', 'PersistentKeepalive', 'PresharedKey', 'PublicKey' ]: assert f'{option} =' not in wg_config peer.dns = None assert config.dns is None