X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=test%2Fintegration%2Finvite.py;fp=test%2Fintegration%2Finvite.py;h=743b4249c28785225ece05b8aba71497d3135627;hp=2d06252425c5d8541de7a374262ca907fcd796e8;hb=c8402791b82947c49ba1d04f855dab04191607ca;hpb=66eb66ec8f872db3dc12e1d01101772918d69a4a diff --git a/test/integration/invite.py b/test/integration/invite.py index 2d062524..743b4249 100755 --- a/test/integration/invite.py +++ b/test/integration/invite.py @@ -3,30 +3,25 @@ """Test tinc peer invitations.""" +import time +import subprocess as subp + from testlib import check, util +from testlib.proc import Tinc from testlib.log import log from testlib.test import Test def run_port0_test(ctx: Test) -> None: """Checks that tinc invite fails if called with Port 0 and tincd stopped.""" - foo = ctx.node() - stdin = f""" - init {foo} - set Port 0 - set Address localhost - set DeviceType dummy - """ - foo.cmd(stdin=stdin) + foo = ctx.node(init=True) _, err = foo.cmd("invite", "bar", code=1) check.is_in("Please start tincd", err) -def run_invite_test(ctx: Test, start_before_invite: bool) -> None: - """Run tests. If start_before_invite is True, - tincd is started *before* creating invitation, and vice versa. - """ - foo, bar = ctx.node(), ctx.node() +def init(ctx: Test) -> Tinc: + """Initialize a node.""" + foo = ctx.node() stdin = f""" init {foo} set Port 12345 @@ -36,6 +31,36 @@ def run_invite_test(ctx: Test, start_before_invite: bool) -> None: set Broadcast no """ foo.cmd(stdin=stdin) + return foo + + +def run_expiration_test(ctx: Test) -> None: + """Make sure that invites can't be used after expiration date.""" + + foo, bar = init(ctx), ctx.node() + foo.cmd("set", "InvitationExpire", "1") + foo.start() + + url, _ = foo.cmd("invite", bar.name) + url = url.strip() + time.sleep(2) + + try: + bar.cmd("join", url, code=1, timeout=1) + except subp.TimeoutExpired: + pass + + foo.cmd("stop") + foo_log = util.read_text(foo.sub("log")) + check.is_in("tried to use expired invitation", foo_log) + + +def run_invite_test(ctx: Test, start_before_invite: bool) -> None: + """Run tests. If start_before_invite is True, + tincd is started *before* creating invitation, and vice versa. + """ + foo = init(ctx) + bar = ctx.node() if start_before_invite: foo.cmd("set", "Port", "0") @@ -108,3 +133,6 @@ with Test("offline mode") as context: with Test("online mode") as context: run_invite_test(context, start_before_invite=True) + +with Test("invite expiration") as context: + run_expiration_test(context)