summaryrefslogtreecommitdiff
path: root/tests/accel-pppd/pppoe/test_pppoe_session_wo_auth.py
blob: 960b7c945e9beb9eb60177d7c37a1806f8c919d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import pytest
from common import process
import time


@pytest.fixture()
def accel_pppd_config(veth_pair_netns):
    print("accel_pppd_config veth_pair_netns: " + str(veth_pair_netns))
    return (
        """
    [modules]
    radius
    pppoe
    auth_pap
    ippool

    [core]
    log-error=/dev/stderr

    [log]
    log-debug=/dev/stdout
    log-file=/dev/stdout
    log-emerg=/dev/stderr
    level=5

    [auth]
    any-login=1

    [ip-pool]
    gw-ip-address=192.0.2.1
    192.0.2.2-255

    [cli]
    tcp=127.0.0.1:2001

    [radius]

    [pppoe]
    interface="""
        + veth_pair_netns["veth_a"]
    )


@pytest.fixture()
def pppd_config(veth_pair_netns):
    print("pppd_config veth_pair_netns: " + str(veth_pair_netns))
    return (
        """
    nodetach
    noipdefault
    defaultroute
    connect /bin/true
    noauth
    persist
    mtu 1492
    noaccomp
    default-asyncmap
    user loginAB
    password pass123
    nic-"""
        + veth_pair_netns["veth_b"]
    )


# test pppoe session without auth check
def test_pppoe_session_wo_auth(pppd_instance, accel_cmd):

    # test that pppd (with accel-pppd) started successfully
    assert pppd_instance["is_started"]

    # wait until session is started
    max_wait_time = 10.0
    sleep_time = 0.0
    is_started = False  # is session started
    while sleep_time < max_wait_time:
        (exit, out, err) = process.run(
            [
                accel_cmd,
                "show sessions match username log.nAB username,ip,state",
            ]
        )
        assert exit == 0  # accel-cmd fails
        # print(out)
        if "loginAB" in out and "192.0.2." in out and "active" in out:
            # session is found
            print(
                "test_pppoe_session_wo_auth: session found in (sec): " + str(sleep_time)
            )
            is_started = True
            break
        time.sleep(0.1)
        sleep_time += 0.1

    print("test_pppoe_session_wo_auth: last accel-cmd out: " + out)

    # test that session is started
    assert is_started == True