Rewrite integration test suite in Python
[tinc] / test / integration / algorithms.py
1 #!/usr/bin/env python3
2
3 """Check that legacy protocol works with different cryptographic algorithms."""
4
5 import typing as T
6
7 from testlib.test import Test
8 from testlib.proc import Tinc
9 from testlib.log import log
10 from testlib import cmd, check
11
12
13 def init(ctx: Test, digest: str, cipher: str) -> T.Tuple[Tinc, Tinc]:
14     """Initialize new test nodes."""
15     foo, bar = ctx.node(), ctx.node()
16
17     stdin = f"""
18         init {foo}
19         set Port 0
20         set DeviceType dummy
21         set Address localhost
22         set ExperimentalProtocol no
23         set Digest {digest}
24         set Cipher {cipher}
25     """
26     foo.cmd(stdin=stdin)
27     foo.start()
28
29     stdin = f"""
30         init {bar}
31         set Port 0
32         set DeviceType dummy
33         set Address localhost
34         set ExperimentalProtocol no
35         set Digest {digest}
36         set Cipher {cipher}
37     """
38     bar.cmd(stdin=stdin)
39
40     foo.add_script(bar.script_up)
41     bar.add_script(foo.script_up)
42
43     cmd.exchange(foo, bar)
44     bar.cmd("add", "ConnectTo", foo.name)
45     bar.cmd("start")
46
47     return foo, bar
48
49
50 def test(foo: Tinc, bar: Tinc) -> None:
51     """Run tests on algorithm pair."""
52     log.info("waiting for bar to come up")
53     foo[bar.script_up].wait()
54
55     log.info("waiting for foo to come up")
56     bar[foo.script_up].wait()
57
58     log.info("checking node reachability")
59     stdout, _ = foo.cmd("info", bar.name)
60     check.is_in("reachable", stdout)
61
62
63 for alg_digest in "none", "sha256", "sha512":
64     for alg_cipher in "none", "aes-256-cbc":
65         with Test("compression") as context:
66             node0, node1 = init(context, alg_digest, alg_cipher)
67             test(node0, node1)