test: verify native WireGuard config and key replacement end to end
This commit is contained in:
1 parent
b7e7fb05b6
commit
8130fa3383
3 files changed
+86
-1
No files matched your search
@@ -42,6 +42,8 @@ with Server(os.environ['TEST_SOCKET'],RPC) as server:
|
||||
'''
|
||||
def main():
|
||||
if os.geteuid()!=0:raise SystemExit('Explicit root test on Linux required.')
|
||||
existing={line.split()[0] for line in run('ip','netns','list').splitlines() if line.strip()}
|
||||
if existing.intersection((A,B)):raise SystemExit('Test namespace already exists; not modified.')
|
||||
process=None
|
||||
before=run('ip','-4','route','show')
|
||||
with tempfile.TemporaryDirectory(prefix='deck-native-test-') as t:
|
||||
@@ -82,8 +84,29 @@ def main():
|
||||
s=rpc('mode',mode='tunnel');assert http('10.241.88.1')==403;assert http('10.242.88.1')==200
|
||||
rpc('cancel');assert http('10.241.88.1')==200
|
||||
rpc('disconnect');assert rpc('status')['enabled'] is False
|
||||
# Replace both keys and PSK using only disposable test peers/configuration.
|
||||
trial=rpc('mode',mode='lan')['pending']['id']
|
||||
rpc('confirm',trial_id=trial,ingress='lan',proxy_token=token)
|
||||
try:rpc('import',config='invalid synthetic configuration')
|
||||
except ValueError:pass
|
||||
else:raise AssertionError('Invalid replacement accepted')
|
||||
new_ka=ns(A,'wg','genkey');new_kb=ns(B,'wg','genkey');psk=ns(A,'wg','genpsk')
|
||||
new_pa=ns(A,'wg','pubkey',data=new_ka+'\n');new_pb=ns(B,'wg','pubkey',data=new_kb+'\n')
|
||||
result=rpc('import',config=f'[Interface]\nPrivateKey = {new_ka}\nAddress = 10.242.88.1/24, fd42:88::1/64\n[Peer]\nPublicKey = {new_pb}\nPresharedKey = {psk}\nAllowedIPs = 10.242.88.2/32, fd42:88::2/128\nEndpoint = 10.241.88.2:51835\nPersistentKeepalive = 1\n')
|
||||
assert new_ka not in json.dumps(result) and psk not in json.dumps(result)
|
||||
peer.write_text(f'[Interface]\nPrivateKey = {new_kb}\nListenPort = 51835\n[Peer]\nPublicKey = {new_pa}\nPresharedKey = {psk}\nAllowedIPs = 10.242.88.1/32, fd42:88::1/128\nEndpoint = 10.241.88.1:51836\nPersistentKeepalive = 1\n');peer.chmod(0o600)
|
||||
ns(B,'wg','setconf','peerwg0',str(peer));peer.unlink()
|
||||
rpc('connect');ns(A,'wg','set','wgdeck0','listen-port','51836')
|
||||
for _ in range(40):
|
||||
if rpc('status')['state']=='connected':break
|
||||
time.sleep(.25)
|
||||
else:raise RuntimeError('Handshake after synthetic key replacement missing')
|
||||
trial=rpc('mode',mode='both')['pending']['id']
|
||||
rpc('confirm',trial_id=trial,ingress='tunnel',proxy_token=token)
|
||||
assert http('10.242.88.1')==200;assert http('fd42:88::1')==200
|
||||
rpc('disconnect');assert rpc('status')['enabled'] is False
|
||||
assert run('ip','-4','route','show')==before
|
||||
print('PASS native dual-stack handshake/access, LAN/tunnel/both, forged confirmation rejection, streamed API bytes, cancellation, cleanup; host routes unchanged')
|
||||
print('PASS native dual-stack handshake/access, config/key/PSK replacement and reconnect, invalid config rejection, secret-free responses, LAN/tunnel/both, streamed API bytes, cleanup; host routes unchanged')
|
||||
finally:
|
||||
if process:process.terminate();process.wait(timeout=15)
|
||||
for n in (A,B):subprocess.run(['ip','netns','del',n],capture_output=True)
|
||||
|
||||
Reference in new issue
Block a user