"""Scenario 3 for unit-testing of stop-idle-sessions

In Scenario 3, there are a large number of different sessions:

  * Session 65 is a strange one. For this scenario, the root user started an
    X.org server on behalf of an individual end-user. Although the session is
    owned by root and therefore exempt, the X environment is owned by the
    user (via su - auser) and must have its idleness calculated. This idleness
    is then shared by the "downstream" sessions running x11vnc (session 4096)
    and the tunneled VNC port via sshd (session 4100). The X.org environment
    is considered to be active, having been recently used.

  * Session 72 has no session leader but just a lingering ssh-agent process.
    It should be left alone.

  * Session 82 is an idle SSH session which contains an equally-idle VNC
    session. Its session leader (but no additional processes) should be
    terminated.

  * Session 4089 is an SSH session owned by the root user and making
    observations of the system. It should be left alone.

  * Session 4096 is an idle SSH session but which contains an x11vnc process.
    This, in turn, is re-rendering the X.org session (in session 65) which is
    then being tunneled into (in session 4100). Because the X.org session is
    active, all of the "downstream" sessions including 4096 should be
    preserved.

  * Session 4098 has a long-running Ansible connection under a dedicated
    service account name. Because of the username, it should be left alone.

  * Session 4100 is an idle SSH session but which hosts an SSH tunnel. This,
    in turn, reaches x11vnc (in session 4096) and thru again to the underlying
    X.org session (in session 65). Because the X.org session is active, all of
    the "downstream" sessions including 4100 should be preserved.
"""
# Don't worry about how many lines are in this file. It's basically just a
# dataset (albeit with actual Python objects).
# pylint: disable=too-many-lines


import datetime
from ipaddress import ip_address, IPv4Address, IPv6Address
from textwrap import dedent
from typing import Any, List, Mapping, Optional, Set, Tuple, Union
from unittest.mock import Mock

import stop_idle_sessions.logind
import stop_idle_sessions.main
import stop_idle_sessions.ps
import stop_idle_sessions.ss
import stop_idle_sessions.tty

from . import test_logind, test_main, test_ps, test_ss


class Scenario3LogindTestCase(test_logind.LogindTestCase):
    """Scenario3 unit testing for the logind module

    See the docstring for the test_scenario2 module for an overall description
    of Scenario 3 (unusual ss and x11vnc session arrangements).

    This was generated by the following shell pipeline:
        loginctl | tail -n +2 | head -n -2 | awk '{print $1}' |
        xargs -L1 loginctl show-session
    """

    def _mock_gio_results_spec(self) -> Mapping[str, Mapping[str, str]]:
        """Input data to populate the mock Gio object (logind API)"""
        return {
            "4089": {
                    "Id": "4089",
                    "User": "0",
                    "TTY": "pts/5",
                    "Scope": "session-4089.scope",
                    "Leader": "1602192",
                    "Type": "tty"
            },
            "4096": {
                    "Id": "4096",
                    "User": "1000",
                    "TTY": "pts/0",
                    "Scope": "session-4096.scope",
                    "Leader": "1607896",
                    "Type": "tty"
            },
            "4098": {
                    "Id": "4098",
                    "User": "21106",
                    "TTY": "pts/8",
                    "Scope": "session-4098.scope",
                    "Leader": "1612636",
                    "Type": "tty"
            },
            "65": {
                    "Id": "65",
                    "User": "0",
                    "TTY": "pts/1",
                    "Scope": "session-65.scope",
                    "Leader": "0",
                    "Type": "tty"
            },
            "72": {
                    "Id": "72",
                    "User": "1000",
                    "TTY": "pts/2",
                    "Scope": "session-72.scope",
                    "Leader": "0",
                    "Type": "tty"
            },
            "82": {
                    "Id": "82",
                    "User": "1000",
                    "TTY": "pts/0",
                    "Scope": "session-82.scope",
                    "Leader": "67880",
                    "Type": "tty"
            },
            "4100": {
                    "Id": "4100",
                    "User": "1000",
                    "TTY": "pts/9",
                    "Scope": "session-4100.scope",
                    "Leader": "1617896",
                    "Type": "tty"
            }
        }


    def _expected_logind_sessions(self) -> List[Mapping[str, Any]]:
        """Expected set of logind session attributes to be returned"""
        return [
            {
                "session_id": "4089",
                "uid": 0,
                "tty": "pts/5",
                "leader": 1602192,
                "session_type": "tty",
                "scope": "session-4089.scope",
                "scope_path": "/user.slice/user-0.slice/session-4089.scope"
            },
            {
                "session_id": "4096",
                "uid": 1000,
                "tty": "pts/0",
                "leader": 1607896,
                "session_type": "tty",
                "scope": "session-4096.scope",
                "scope_path": "/user.slice/user-1000.slice/session-4096.scope"
            },
            {
                "session_id": "4098",
                "uid": 21106,
                "tty": "pts/8",
                "leader": 1612636,
                "session_type": "tty",
                "scope": "session-4098.scope",
                "scope_path": "/user.slice/user-21106.slice/session-4098.scope"
            },
            {
                "session_id": "65",
                "uid": 0,
                "tty": "pts/1",
                "leader": 0,
                "session_type": "tty",
                "scope": "session-65.scope",
                "scope_path": "/user.slice/user-0.slice/session-65.scope"
            },
            {
                "session_id": "72",
                "uid": 1000,
                "tty": "pts/2",
                "leader": 0,
                "session_type": "tty",
                "scope": "session-72.scope",
                "scope_path": "/user.slice/user-1000.slice/session-72.scope"
            },
            {
                "session_id": "82",
                "uid": 1000,
                "tty": "pts/0",
                "leader": 67880,
                "session_type": "tty",
                "scope": "session-82.scope",
                "scope_path": "/user.slice/user-1000.slice/session-82.scope"
            },
            {
                "session_id": "4100",
                "uid": 1000,
                "tty": "pts/9",
                "leader": 1617896,
                "session_type": "tty",
                "scope": "session-4100.scope",
                "scope_path": "/user.slice/user-1000.slice/session-4100.scope"
            }
        ]

class Scenario3CgroupPidsTestCase(test_ps.CgroupPidsTestCase):
    """Scenario3 unit testing for the ps module

    See the docstring for the test_scenario2 module for an overall description
    of Scenario 3 (unusual ss and x11vnc session arrangements).

    This was generated by the following shell pipeline:
        cat /sys/fs/cgroup/systemd/user.slice/user-1002.slice/session-1267.scope/cgroup.procs |
        xargs -L1 ps -o 'pid,args' --no-headers -p

    In Scenario 3, we deliberately choose the X.org session. In this case, it
    is owned by root, which is quite unusual (unique to basically one single
    workstation in our environment).
    """

    def _mock_process_specs(self) -> Mapping[int, str]:
        """Input data to populate the filesystem mock for the cgroup sysfs"""
        # Yes, there are some very long lines here!
        # pylint: disable=line-too-long
        return {
            60750: "/bin/sh /usr/bin/startx -- :1",
            60770: "xinit /etc/X11/xinit/xinitrc -- /usr/bin/X :1 -auth /home/auser/.serverauth.60750",
            60771: "/usr/libexec/Xorg :1 -auth /home/auser/.serverauth.60750",
            60776: "/usr/libexec/gnome-session-binary",
            60792: "dbus-launch --sh-syntax --exit-with-session",
            60793: "/usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session",
            60808: "/usr/bin/ssh-agent /etc/X11/xinit/Xclients",
            60823: "/usr/libexec/at-spi-bus-launcher",
            60828: "/usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --pri",
            60831: "/usr/libexec/at-spi2-registryd --use-gnome-session",
            60835: "/usr/libexec/gvfsd",
            60842: "/usr/libexec/gvfsd-fuse /home/auser/.gvfs -f -o big_writes",
            60870: "/usr/bin/gnome-keyring-daemon --start --components=pkcs11",
            60884: "/usr/bin/gnome-shell",
            60900: "ibus-daemon --xim --panel disable",
            60902: "/usr/libexec/xdg-permission-store",
            60904: "/usr/libexec/gnome-shell-calendar-server",
            60908: "/usr/libexec/ibus-dconf",
            60909: "/usr/libexec/ibus-extension-gtk3",
            60911: "/usr/libexec/ibus-x11 --kill-daemon",
            60913: "/usr/libexec/ibus-portal",
            60921: "/usr/libexec/dconf-service",
            60933: "/usr/libexec/evolution-source-registry",
            60955: "/usr/libexec/goa-daemon",
            60960: "/usr/libexec/gvfs-udisks2-volume-monitor",
            60967: "/usr/libexec/goa-identity-service",
            60973: "/usr/libexec/gvfs-goa-volume-monitor",
            60981: "/usr/libexec/gvfs-mtp-volume-monitor",
            60986: "/usr/libexec/gvfs-gphoto2-volume-monitor",
            60991: "/usr/libexec/gvfs-afc-volume-monitor",
            61000: "/usr/libexec/gsd-power",
            61002: "/usr/libexec/gsd-print-notifications",
            61003: "/usr/libexec/gsd-rfkill",
            61004: "/usr/libexec/gsd-screensaver-proxy",
            61005: "/usr/libexec/gsd-sharing",
            61006: "/usr/libexec/gsd-smartcard",
            61007: "/usr/libexec/gsd-sound",
            61008: "/usr/libexec/gsd-xsettings",
            61009: "/usr/libexec/gsd-wacom",
            61012: "/usr/libexec/gsd-account",
            61013: "/usr/libexec/gsd-a11y-settings",
            61014: "/usr/libexec/gsd-clipboard",
            61015: "/usr/libexec/gsd-color",
            61016: "/usr/libexec/gsd-datetime",
            61017: "/usr/libexec/gsd-housekeeping",
            61018: "/usr/libexec/gsd-keyboard",
            61019: "/usr/libexec/gsd-media-keys",
            61020: "/usr/libexec/gsd-mouse",
            61021: "/usr/libexec/gsd-subman",
            61025: "/usr/libexec/evolution-calendar-factory",
            61028: "/usr/bin/pulseaudio --start",
            61069: "/usr/libexec/gsd-printer",
            61071: "/usr/libexec/ibus-engine-simple",
            61129: "/usr/libexec/evolution-calendar-factory-subprocess --factory all --bus-name org.gnome.evolution.",
            61149: "/usr/libexec/evolution-addressbook-factory",
            61164: "/usr/libexec/evolution-addressbook-factory-subprocess --factory all --bus-name org.gnome.evoluti",
            61719: "/usr/libexec/gsd-disk-utility-notify",
            61723: "/usr/libexec/evolution/evolution-alarm-notify",
            67645: "/usr/libexec/gvfsd-trash --spawner :1.8 /org/gtk/gvfs/exec_spaw/0",
            172491: "bash",
            172639: "ssh hpc21",
            172640: "ssh jump-slot ssh-proxy hpc21",
            549838: "more run.yaml",
            575856: "bash",
            576030: "ssh hpc23",
            576031: "ssh jump-slot ssh-proxy hpc23",
            630339: "/usr/libexec/gvfsd-http --spawner :1.8 /org/gtk/gvfs/exec_spaw/4",
            769669: "bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 file.dat",
            769681: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360-bin file.dat",
            769997: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
            769998: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
            770009: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
            770014: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
            809224: "bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 untitled.lay",
            809236: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360-bin untitled.lay",
            809550: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
            809551: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
            809564: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
            809571: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
            837903: "bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 velo.lay",
            838229: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
            838230: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
            838243: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
            838249: "/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
            881543: "/usr/bin/ssh-agent -D -a /home/auser/.cache/keyring-0X1RX2/.ssh",
            881602: "ssh -fNqx jump-main",
            881730: "ssh -fNqx jump-main",
            938821: "/usr/libexec/gvfsd-metadata",
            989792: "ssh -fNqx jump-main",
            1029041: "/usr/libexec/gvfsd-network --spawner :1.8 /org/gtk/gvfs/exec_spaw/1",
            1029158: "/usr/libexec/gvfsd-dnssd --spawner :1.8 /org/gtk/gvfs/exec_spaw/3",
            1536330: "/usr/bin/nautilus --gapplication-service",
            1539823: "eog /storage/auser/Project/Subproject/File",
            1602583: "paraview",
            1602590: "/opt/software/paraview/5.13.0/bin/paraview-real",
            1740637: "/usr/libexec/gnome-terminal-server",
            1740647: "bash",
            1742445: "ssh hpc25",
            1742446: "ssh jump-slot ssh-proxy hpc25",
            1765602: "bash",
            2012476: "scp auser@hpc25:/storagep18/auser/Project/Subproject/002.* .",
            2012477: "/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
            2012478: "ssh jump-slot ssh-proxy hpc25",
            2012558: "bash",
            2013114: "bash",
            2467293: "bash",
            2675914: "./a.out",
            2686802: "/usr/bin/python3 test.py",
            2686803: "less",
            2711041: "/usr/libexec/xdg-desktop-portal",
            2711048: "/usr/libexec/xdg-document-portal",
            2711058: "fusermount -o rw,nosuid,nodev,fsname=portal,auto_unmount,subtype=portal -- /home/auser/.cache",
            2711063: "/usr/libexec/xdg-desktop-portal-gtk",
            2733953: "bash",
            2744827: "bash",
            3453399: "scp auser@hpc25:/storagep18/auser/Project/Subproject/000.* .",
            3453400: "/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
            3453401: "ssh jump-slot ssh-proxy hpc25",
            3806099: "more MakeTunnel.tcl",
            4038438: "bash",
            4046677: "scp auser@hpc25:/storagep18/auser/directory/ .",
            4046678: "/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
            4046679: "ssh jump-slot ssh-proxy hpc25",
            4120895: "ssh hpc27",
            4120896: "ssh jump-slot ssh-proxy hpc27 ",
        }

    def _expected_process_objects(self) -> List[stop_idle_sessions.ps.Process]:
        """Expected set of processes to be parsed out of the cgroup sysfs"""
        # Yes, there are some very long lines here!
        # pylint: disable=line-too-long
        return [
            stop_idle_sessions.ps.Process(
                    pid=60750,
                    cmdline="/bin/sh /usr/bin/startx -- :1",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60770,
                    cmdline="xinit /etc/X11/xinit/xinitrc -- /usr/bin/X :1 -auth /home/auser/.serverauth.60750",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60771,
                    cmdline="/usr/libexec/Xorg :1 -auth /home/auser/.serverauth.60750",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60776,
                    cmdline="/usr/libexec/gnome-session-binary",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60792,
                    cmdline="dbus-launch --sh-syntax --exit-with-session",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60793,
                    cmdline="/usr/bin/dbus-daemon --syslog --fork --print-pid 5 --print-address 7 --session",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60808,
                    cmdline="/usr/bin/ssh-agent /etc/X11/xinit/Xclients",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60823,
                    cmdline="/usr/libexec/at-spi-bus-launcher",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60828,
                    cmdline="/usr/bin/dbus-daemon --config-file=/usr/share/defaults/at-spi2/accessibility.conf --nofork --pri",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60831,
                    cmdline="/usr/libexec/at-spi2-registryd --use-gnome-session",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60835,
                    cmdline="/usr/libexec/gvfsd",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60842,
                    cmdline="/usr/libexec/gvfsd-fuse /home/auser/.gvfs -f -o big_writes",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60870,
                    cmdline="/usr/bin/gnome-keyring-daemon --start --components=pkcs11",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60884,
                    cmdline="/usr/bin/gnome-shell",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60900,
                    cmdline="ibus-daemon --xim --panel disable",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60902,
                    cmdline="/usr/libexec/xdg-permission-store",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60904,
                    cmdline="/usr/libexec/gnome-shell-calendar-server",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60908,
                    cmdline="/usr/libexec/ibus-dconf",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60909,
                    cmdline="/usr/libexec/ibus-extension-gtk3",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60911,
                    cmdline="/usr/libexec/ibus-x11 --kill-daemon",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60913,
                    cmdline="/usr/libexec/ibus-portal",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60921,
                    cmdline="/usr/libexec/dconf-service",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60933,
                    cmdline="/usr/libexec/evolution-source-registry",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60955,
                    cmdline="/usr/libexec/goa-daemon",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60960,
                    cmdline="/usr/libexec/gvfs-udisks2-volume-monitor",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60967,
                    cmdline="/usr/libexec/goa-identity-service",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60973,
                    cmdline="/usr/libexec/gvfs-goa-volume-monitor",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60981,
                    cmdline="/usr/libexec/gvfs-mtp-volume-monitor",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60986,
                    cmdline="/usr/libexec/gvfs-gphoto2-volume-monitor",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=60991,
                    cmdline="/usr/libexec/gvfs-afc-volume-monitor",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61000,
                    cmdline="/usr/libexec/gsd-power",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61002,
                    cmdline="/usr/libexec/gsd-print-notifications",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61003,
                    cmdline="/usr/libexec/gsd-rfkill",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61004,
                    cmdline="/usr/libexec/gsd-screensaver-proxy",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61005,
                    cmdline="/usr/libexec/gsd-sharing",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61006,
                    cmdline="/usr/libexec/gsd-smartcard",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61007,
                    cmdline="/usr/libexec/gsd-sound",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61008,
                    cmdline="/usr/libexec/gsd-xsettings",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61009,
                    cmdline="/usr/libexec/gsd-wacom",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61012,
                    cmdline="/usr/libexec/gsd-account",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61013,
                    cmdline="/usr/libexec/gsd-a11y-settings",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61014,
                    cmdline="/usr/libexec/gsd-clipboard",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61015,
                    cmdline="/usr/libexec/gsd-color",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61016,
                    cmdline="/usr/libexec/gsd-datetime",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61017,
                    cmdline="/usr/libexec/gsd-housekeeping",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61018,
                    cmdline="/usr/libexec/gsd-keyboard",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61019,
                    cmdline="/usr/libexec/gsd-media-keys",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61020,
                    cmdline="/usr/libexec/gsd-mouse",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61021,
                    cmdline="/usr/libexec/gsd-subman",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61025,
                    cmdline="/usr/libexec/evolution-calendar-factory",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61028,
                    cmdline="/usr/bin/pulseaudio --start",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61069,
                    cmdline="/usr/libexec/gsd-printer",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61071,
                    cmdline="/usr/libexec/ibus-engine-simple",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61129,
                    cmdline="/usr/libexec/evolution-calendar-factory-subprocess --factory all --bus-name org.gnome.evolution.",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61149,
                    cmdline="/usr/libexec/evolution-addressbook-factory",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61164,
                    cmdline="/usr/libexec/evolution-addressbook-factory-subprocess --factory all --bus-name org.gnome.evoluti",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61719,
                    cmdline="/usr/libexec/gsd-disk-utility-notify",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=61723,
                    cmdline="/usr/libexec/evolution/evolution-alarm-notify",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=67645,
                    cmdline="/usr/libexec/gvfsd-trash --spawner :1.8 /org/gtk/gvfs/exec_spaw/0",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=172491,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=172639,
                    cmdline="ssh hpc21",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=172640,
                    cmdline="ssh jump-slot ssh-proxy hpc21",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=549838,
                    cmdline="more run.yaml",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=575856,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=576030,
                    cmdline="ssh hpc23",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=576031,
                    cmdline="ssh jump-slot ssh-proxy hpc23",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=630339,
                    cmdline="/usr/libexec/gvfsd-http --spawner :1.8 /org/gtk/gvfs/exec_spaw/4",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=769669,
                    cmdline="bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 file.dat",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=769681,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360-bin file.dat",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=769997,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=769998,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=770009,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=770014,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809224,
                    cmdline="bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 untitled.lay",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809236,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360-bin untitled.lay",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809550,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809551,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809564,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=809571,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=837903,
                    cmdline="bash /opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/tec360 velo.lay",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=838229,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-z",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=838230,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=zygote --no-s",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=838243,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=utility --ena",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=838249,
                    cmdline="/opt/software/tecplot/tecplot360-2024R1/360ex_2024r1/bin/QtWebEngineProcess --type=renderer --no",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=881543,
                    cmdline="/usr/bin/ssh-agent -D -a /home/auser/.cache/keyring-0X1RX2/.ssh",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=881602,
                    cmdline="ssh -fNqx jump-main",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=881730,
                    cmdline="ssh -fNqx jump-main",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=938821,
                    cmdline="/usr/libexec/gvfsd-metadata",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=989792,
                    cmdline="ssh -fNqx jump-main",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1029041,
                    cmdline="/usr/libexec/gvfsd-network --spawner :1.8 /org/gtk/gvfs/exec_spaw/1",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1029158,
                    cmdline="/usr/libexec/gvfsd-dnssd --spawner :1.8 /org/gtk/gvfs/exec_spaw/3",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1536330,
                    cmdline="/usr/bin/nautilus --gapplication-service",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1539823,
                    cmdline="eog /storage/auser/Project/Subproject/File",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1602583,
                    cmdline="paraview",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1602590,
                    cmdline="/opt/software/paraview/5.13.0/bin/paraview-real",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1740637,
                    cmdline="/usr/libexec/gnome-terminal-server",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1740647,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1742445,
                    cmdline="ssh hpc25",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1742446,
                    cmdline="ssh jump-slot ssh-proxy hpc25",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=1765602,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2012476,
                    cmdline="scp auser@hpc25:/storagep18/auser/Project/Subproject/002.* .",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2012477,
                    cmdline="/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2012478,
                    cmdline="ssh jump-slot ssh-proxy hpc25",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2012558,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2013114,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2467293,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2675914,
                    cmdline="./a.out",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2686802,
                    cmdline="/usr/bin/python3 test.py",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2686803,
                    cmdline="less",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2711041,
                    cmdline="/usr/libexec/xdg-desktop-portal",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2711048,
                    cmdline="/usr/libexec/xdg-document-portal",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2711058,
                    cmdline="fusermount -o rw,nosuid,nodev,fsname=portal,auto_unmount,subtype=portal -- /home/auser/.cache",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2711063,
                    cmdline="/usr/libexec/xdg-desktop-portal-gtk",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2733953,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=2744827,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=3453399,
                    cmdline="scp auser@hpc25:/storagep18/auser/Project/Subproject/000.* .",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=3453400,
                    cmdline="/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=3453401,
                    cmdline="ssh jump-slot ssh-proxy hpc25",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=3806099,
                    cmdline="more MakeTunnel.tcl",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4038438,
                    cmdline="bash",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4046677,
                    cmdline="scp auser@hpc25:/storagep18/auser/directory/ .",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4046678,
                    cmdline="/usr/bin/ssh -x -oForwardAgent=no -oPermitLocalCommand=no -oClearAllForwardings=yes -oRemoteComm",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4046679,
                    cmdline="ssh jump-slot ssh-proxy hpc25",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4120895,
                    cmdline="ssh hpc27",
                    environ={}
            ),
            stop_idle_sessions.ps.Process(
                    pid=4120896,
                    cmdline="ssh jump-slot ssh-proxy hpc27 ",
                    environ={}
            )
        ]


class Scenario3LoopbackConnectionTestCase(test_ss.LoopbackConnectionTestCase):
    """Scenario3 unit testing for the ss module

    See the docstring for the test_scenario1 module for an overall description
    of Scenario 3 (unusual ss and x11vnc session arrangements).

    This was generated by the following shell pipeline:
        /usr/sbin/ss --all --no-header --numeric --oneline --processes --tcp

    Scenario 3 specifically includes some collected "oddball" socket entries
    from real-world workstations to try and throw off the ss processing.
    """

    def _mock_raw_ss_output(self) -> str:
        """Input data to populate the mocked network connections table"""
        return dedent("""\
            LISTEN              0                128                               0.0.0.0:111                                0.0.0.0:*                users:(("rpcbind",pid=6505,fd=4),("systemd",pid=1,fd=407))
            LISTEN              0                128                               0.0.0.0:22                                 0.0.0.0:*                users:(("sshd",pid=673008,fd=3))
            LISTEN              0                128                             127.0.0.1:631                                0.0.0.0:*                users:(("cupsd",pid=6860,fd=8))
            LISTEN              0                100                             127.0.0.1:25                                 0.0.0.0:*                users:(("master",pid=7650,fd=14))
            LISTEN              0                128                               0.0.0.0:57027                              0.0.0.0:*                users:(("paraview-real",pid=1602590,fd=7))
            LISTEN              0                32                                0.0.0.0:5901                               0.0.0.0:*                users:(("x11vnc",pid=1611110,fd=8))
            LISTEN              0                5                               127.0.0.1:5902                               0.0.0.0:*                users:(("Xvnc",pid=69575,fd=6))
            ESTAB               0                0                           192.168.34.80:45774                        192.168.99.40:22               users:(("ssh",pid=881602,fd=3))
            TIME-WAIT           0                0                           192.168.34.80:33092                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33124                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37624                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36360                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36354                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37740                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36236                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36226                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37664                        192.168.2.100:3128
            ESTAB               0                0                               127.0.0.1:45502                            127.0.0.1:5901             users:(("sshd",pid=1618023,fd=7))
            TIME-WAIT           0                0                           192.168.34.80:37644                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37630                        192.168.2.100:3128
            ESTAB               24               0                           192.168.34.80:44784                        192.168.0.124:1780             users:(("tec360-bin",pid=809236,fd=28))
            TIME-WAIT           0                0                           192.168.34.80:36278                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:959                          192.168.0.202:2049
            TIME-WAIT           0                0                           192.168.34.80:33166                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33180                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36294                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36382                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33150                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37620                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36284                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33140                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37710                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37756                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37758                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33068                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37702                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37738                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33128                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37654                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:34782                       192.168.121.30:9997             users:(("splunkd",pid=7751,fd=183))
            TIME-WAIT           0                0                           192.168.34.80:33086                        192.168.2.100:3128
            ESTAB               15               0                           192.168.34.80:48916                        192.168.0.124:1780             users:(("tec360-bin",pid=769681,fd=28))
            TIME-WAIT           0                0                           192.168.34.80:36326                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37674                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37328                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36366                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33080                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37726                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36308                        192.168.2.100:3128
            ESTAB               0                0                               127.0.0.1:5901                             127.0.0.1:45502            users:(("x11vnc",pid=1611110,fd=11))
            TIME-WAIT           0                0                           192.168.34.80:33108                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36270                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:35498                        192.168.99.40:22               users:(("ssh",pid=989792,fd=3))
            TIME-WAIT           0                0                           192.168.34.80:36338                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36248                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37326                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36262                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36322                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36218                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:22                            192.168.0.53:52338            users:(("sshd",pid=1602211,fd=4),("sshd",pid=1602192,fd=4))
            ESTAB               0                0                           192.168.34.80:59196                        192.168.99.40:22               users:(("ssh",pid=881730,fd=3))
            TIME-WAIT           0                0                           192.168.34.80:37780                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37690                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:36346                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37762                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:903                          192.168.0.203:2049
            TIME-WAIT           0                0                           192.168.34.80:36286                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:37770                        192.168.2.100:3128
            TIME-WAIT           0                0                           192.168.34.80:33192                        192.168.2.100:3128
            ESTAB               0                2716                        192.168.34.80:22                            192.168.7.14:49764            users:(("sshd",pid=1618023,fd=4),("sshd",pid=1617896,fd=4))
            TIME-WAIT           0                0                           192.168.34.80:37746                        192.168.2.100:3128
            ESTAB               0                0                           192.168.34.80:33206                        192.168.2.100:3128             users:(("platform-python",pid=1621488,fd=40))
            ESTAB               0                0                           192.168.34.80:22                            192.168.0.53:35578            users:(("sshd",pid=1612676,fd=4),("sshd",pid=1612636,fd=4))
            TIME-WAIT           0                0                           192.168.34.80:33054                        192.168.2.100:3128
            LISTEN              0                128                                  [::]:111                                   [::]:*                users:(("rpcbind",pid=6505,fd=6),("systemd",pid=1,fd=409))
            LISTEN              0                128                                 [::1]:631                                   [::]:*                users:(("cupsd",pid=6860,fd=7))
            LISTEN              0                100                                 [::1]:25                                    [::]:*                users:(("master",pid=7650,fd=15))
            LISTEN              0                32                                   [::]:5900                                  [::]:*                users:(("x11vnc",pid=1611110,fd=9))
            LISTEN              0                32                                   [::]:5901                                  [::]:*                users:(("x11vnc",pid=1611110,fd=10))
            LISTEN              0                5                                   [::1]:5902                                  [::]:*                users:(("Xvnc",pid=69575,fd=7))
            ESTAB               0                0                 [::ffff:192.168.35.153]:34152               [::ffff:192.168.99.10]:52311            users:(("BESClient",pid=6206,fd=25))
            LISTEN              0                80                                      *:3306                                     *:*                users:(("mysqld",pid=11827,fd=22))
            LISTEN              0                10                                      *:47827                                    *:*                users:(("star-ccm+",pid=1616815,fd=7))
            LISTEN              0                2048                                    *:9000                                     *:*                users:(("java",pid=4137270,fd=395))
            LISTEN              0                50                     [::ffff:127.0.0.1]:34695                                    *:*                users:(("java",pid=3276197,fd=391))
            LISTEN              0                2                      [::ffff:127.0.0.1]:45481                                    *:*                users:(("java",pid=503653,fd=25))
        """)

    def _expected_listening_ports(self) -> Set[int]:
        """Expected set of listening ports parsed out of the mock ss data"""
        return set([22, 25, 111, 631, 3306, 5900, 5901, 5902, 9000, 34695,
                    45481, 47827, 57027])

    def _expected_peer_pairs(self) -> Set[Tuple[Union[IPv4Address,
                                                      IPv6Address], int]]:
        """Expected set of remote peers parsed from the established conns"""
        return set([
                (ip_address("192.168.99.40"), 22),
                (ip_address("127.0.0.1"), 5901),
                (ip_address("192.168.0.124"), 1780),
                (ip_address("192.168.121.30"), 9997),
                (ip_address("192.168.0.124"), 1780),
                (ip_address("127.0.0.1"), 45502),
                (ip_address("192.168.99.40"), 22),
                (ip_address("192.168.0.53"), 52338),
                (ip_address("192.168.99.40"), 22),
                (ip_address("192.168.7.14"), 49764),
                (ip_address("192.168.2.100"), 3128),
                (ip_address("192.168.0.53"), 35578),
                (ip_address("192.168.0.203"), 2049),
                (ip_address("192.168.0.202"), 2049),
                (ip_address("::ffff:c0a8:630a"), 52311)
        ])

    def _expected_connections(self) -> List[stop_idle_sessions.ss.LoopbackConnection]:
        """Expected set of loopback connections identified from these conns

        For Scenario 3, this is just a single VNC loopback connection.
        Notably, this terminates at a different process than usual -- x11vnc
        instead of Xvnc.
        """

        return [
            stop_idle_sessions.ss.LoopbackConnection(
                    client=stop_idle_sessions.ss.Socket(
                        addr=ip_address('127.0.0.1'),
                        port=45502,
                        processes=[stop_idle_sessions.ps.Process(
                            pid=1618023,
                            cmdline="sshd: auser@pts/0",
                            environ={}
                        )]
                    ),
                    server=stop_idle_sessions.ss.Socket(
                        addr=ip_address('127.0.0.1'),
                        port=5901,
                        processes=[stop_idle_sessions.ps.Process(
                            pid=1611110,
                            cmdline="x11vnc -display :1 -autoport 5901",
                            environ={}
                        )]
                    )
            )
        ]


class Scenario3MainLoopTestCase(test_main.MainLoopTestCase):
    """Scenario3 unit testing for the main module

    See the docstring for the test_scenario2 module for an overall description
    of Scenario 3 (unusual ss and x11vnc session arrangements).

    See also the other Scenario3* TestCases for hints about how to generate
    the input data which was used to specify this test fixture.
    """

    def _mock_get_all_sessions(self) -> List[stop_idle_sessions.logind.Session]:
        """Input data to mock out the logind module and D-Bus"""
        return [
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="4089",
                session_type="tty",
                uid=0,
                tty="pts/5",
                leader=1602192,
                scope="session-4089.scope",
                scope_path="/user.slice/user-0.slice/session-4089.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="4096",
                session_type="tty",
                uid=1000,
                tty="pts/0",
                leader=1607896,
                scope="session-4096.scope",
                scope_path="/user.slice/user-1000.slice/session-4096.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="4098",
                session_type="tty",
                uid=21106,
                tty="pts/8",
                leader=1612636,
                scope="session-4098.scope",
                scope_path="/user.slice/user-21106.slice/session-4098.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="65",
                session_type="tty",
                uid=0,
                tty="pts/1",
                leader=0,
                scope="session-65.scope",
                scope_path="/user.slice/user-0.slice/session-65.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="72",
                session_type="tty",
                uid=1000,
                tty="pts/2",
                leader=0,
                scope="session-72.scope",
                scope_path="/user.slice/user-1000.slice/session-72.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="82",
                session_type="tty",
                uid=1000,
                tty="pts/0",
                leader=67880,
                scope="session-82.scope",
                scope_path="/user.slice/user-1000.slice/session-82.scope"),
            Mock(spec_set=stop_idle_sessions.logind.Session,
                session_id="4100",
                session_type="tty",
                uid=1000,
                tty="pts/0",
                leader=1617896,
                scope="session-4100.scope",
                scope_path="/user.slice/user-1000.slice/session-4100.scope")
        ]

    def _mock_find_loopback_connections(self) -> List[stop_idle_sessions.ss.LoopbackConnection]:
        """Input data to mock out the ss utility and module"""
        return [
            stop_idle_sessions.ss.LoopbackConnection(
                client=stop_idle_sessions.ss.Socket(
                    addr=ip_address('127.0.0.1'),
                    port=45502,
                    processes=[stop_idle_sessions.ps.Process(
                        pid=1618023,
                        cmdline="sshd: auser@pts/0",
                        environ={}
                    )]
                ),
                server=stop_idle_sessions.ss.Socket(
                    addr=ip_address('127.0.0.1'),
                    port=5901,
                    processes=[stop_idle_sessions.ps.Process(
                        pid=1611110,
                        cmdline="x11vnc -display :1 -autoport 5901",
                        environ={}
                    )]
                )
            )
        ]

    # Yeah well, we have seven scopes to return :-D
    # pylint: disable-next=too-many-return-statements
    def _mock_processes_in_scope_path(self,
                                  scope_path: str) -> List[stop_idle_sessions.ps.Process]:
        """Input data to mock out the ps and cgroup interface module"""

        if scope_path == "/user.slice/user-0.slice/session-4089.scope":
            return list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [1602192, 1602211, 1602212]))

        if scope_path == "/user.slice/user-1000.slice/session-4096.scope":
            pids = list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                             [1607896, 1608023, 1608025]))

            pids.append(stop_idle_sessions.ps.Process(
                    pid=1611110,
                    cmdline="x11vnc -display :1 -autoport 5901",
                    environ={}
            ))

            return pids

        if scope_path == "/user.slice/user-21106.slice/session-4098.scope":
            return list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [1612636, 1612676]))

        if scope_path == "/user.slice/user-0.slice/session-65.scope":
            pids = list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [60792, 60793, 60808, 60823, 60828, 60831, 60835,
                             60842, 60870, 60884, 60900, 60902, 60904, 60908,
                             60909, 60911, 60913, 60921, 60933, 60955, 60960,
                             60967, 60973, 60981, 60986, 60991, 61000, 61002,
                             61003, 61004, 61005, 61006, 61007, 61008, 61009,
                             61012, 61013, 61014, 61015, 61016, 61017, 61018,
                             61019, 61020, 61021, 61025, 61028, 61069, 61071,
                             61129, 61149, 61164, 61719, 61723, 67645, 172491,
                             172639, 172640, 549838, 575856, 576030, 576031,
                             630339, 769669, 769681, 769997, 769998, 770009,
                             770014, 809224, 809236, 809550, 809551, 809564,
                             809571, 837903, 838229, 838230, 838243, 838249,
                             881543, 881602, 881730, 938821, 989792, 1029041,
                             1029158, 1536330, 1539823, 1602583, 1602590,
                             1740637, 1740647, 1742445, 1742446, 1765602,
                             2012476, 2012477, 2012478, 2012558, 2013114,
                             2467293, 2675914, 2686802, 2686803, 2711041,
                             2711048, 2711058, 2711063, 2733953, 2744827,
                             3453399, 3453400, 3453401, 3806099, 4038438,
                             4046677, 4046678, 4046679, 4120895, 4120896]))

            pids.append(stop_idle_sessions.ps.Process(
                    pid=60750,
                    cmdline="/bin/sh /usr/bin/startx -- :1",
                    environ={}
            ))
            pids.append(stop_idle_sessions.ps.Process(
                    pid=60770,
                    cmdline=("xinit /etc/X11/xinit/xinitrc -- /usr/bin/X :1 "
                             "-auth /home/auser/.serverauth.60750"),
                    environ={'XAUTHORITY': "/home/auser/.Xauthority"}
            ))
            pids.append(stop_idle_sessions.ps.Process(
                    pid=60771,
                    cmdline=("/usr/libexec/Xorg :1 -auth "
                             "/home/auser/.serverauth.60750"),
                    environ={}
            ))
            pids.append(stop_idle_sessions.ps.Process(
                    pid=60776,
                    cmdline="/usr/libexec/gnome-session-binary",
                    environ={'DISPLAY': ":1",
                             'XAUTHORITY': "/home/auser/.Xauthority"}
            ))

            return pids

        if scope_path == "/user.slice/user-1000.slice/session-72.scope":
            return list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [59989, 60053]))

        if scope_path == "/user.slice/user-1000.slice/session-82.scope":
            pids = list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [68243, 68310, 69607, 69608, 69698, 69703, 69708,
                             69710, 69718, 69728, 69729, 69733, 69738, 69739,
                             69750, 69755, 69760, 69761, 69762, 69763, 69764,
                             69785, 69791, 69794, 69803, 69813, 69819, 69852,
                             69863, 69871, 69880, 69892, 69895, 69905, 69919,
                             69922, 69935, 69944, 69947, 69972, 69985,
                             92366]))

            pids.append(stop_idle_sessions.ps.Process(
                    pid=69575,
                    cmdline=("/usr/bin/Xvnc :2 -auth "
                             "/home/auser/.Xauthority -desktop "
                             "workstation.example.com:2 (auser) -f"),
                    environ={}
            ))
            pids.append(stop_idle_sessions.ps.Process(
                    pid=69590,
                    cmdline="/bin/sh /home/auser/.vnc/xstartup",
                    environ={'DISPLAY': ":2"}
            ))
            pids.append(stop_idle_sessions.ps.Process(
                    pid=69591,
                    cmdline="xfce4-session",
                    environ={'DISPLAY': ":2"}
            ))

            return pids

        if scope_path == "/user.slice/user-1000.slice/session-4100.scope":
            return list(map(lambda pid: stop_idle_sessions.ps.Process(pid=pid,
                                                                      cmdline="",
                                                                      environ={}),
                            [1617896, 1618023, 1618025]))

        raise KeyError(f'Unexpected scope argument: {scope_path}')

    def _mock_uid_to_username(self, uid: int) -> str:
        """Convert numeric UIDs to symbolic usernames"""
        return {0: 'root', 1000: 'auser', 21106: 'ansible'}[uid]

    def _mock_retrieve_idle_time(self,
                                 display: str,
                                 xauthority: Optional[str]) -> Optional[datetime.timedelta]:
        """Mock information about an X11 DISPLAY's idle timeout"""
        assert xauthority is None or isinstance(xauthority, str)

        if display == ':1':
            # Not idle
            return datetime.timedelta(seconds=3 * 60)
        if display == ':2':
            # Idle
            return datetime.timedelta(seconds=17 * 60)

        raise KeyError(f'Unexpected DISPLAY argument: {display}')

    def _mock_tty(self, name: str) -> stop_idle_sessions.tty.TTY:
        """Mock information about a tty/pty's timestamps"""

        if name == 'pts/5':
            # Session 4089
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        full_name='/dev/pts/5',
                        atime=datetime.datetime(2024, 12, 6,
                                                12, 51, 8, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 12, 6,
                                                12, 51, 8, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        if name == 'pts/0':
            # Session 4096 (also 82, but not really)
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        name=name,
                        full_name='/dev/pts/0',
                        atime=datetime.datetime(2024, 12, 6,
                                                13, 5, 35, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 12, 6,
                                                13, 5, 35, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        if name == 'pts/8':
            # Session 4098
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        name=name,
                        full_name='/dev/pts/8',
                        atime=datetime.datetime(2024, 12, 6,
                                                13, 11, 50, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 12, 6,
                                                13, 11, 50, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        if name == 'pts/1':
            # Session 65
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        name=name,
                        full_name='/dev/pts/1',
                        atime=datetime.datetime(2024, 12, 6,
                                                8, 40, 13, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 12, 6,
                                                8, 40, 13, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        if name == 'pts/2':
            # Session 72
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        name=name,
                        full_name='/dev/pts/2',
                        atime=datetime.datetime(2024, 11, 29,
                                                8, 53, 32, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 11, 29,
                                                8, 53, 32, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        if name == 'pts/9':
            # Session 4100
            atty = Mock(spec=stop_idle_sessions.tty.TTY,
                        name=name,
                        full_name='/dev/pts/9',
                        atime=datetime.datetime(2024, 12, 6,
                                                13, 5, 35, 0,
                                                tzinfo=datetime.timezone.utc),
                        mtime=datetime.datetime(2024, 12, 6,
                                                13, 5, 35, 0,
                                                tzinfo=datetime.timezone.utc))
            atty.configure_mock(name=name)
            return atty

        raise KeyError(f'Unexpected tty/pty name: {name}')

    def _now(self) -> datetime.datetime:
        """Return a fixed point in time to compare timedeltas against"""
        return datetime.datetime(2024, 12, 6,
                                 13, 26, 51, 0,
                                 tzinfo=datetime.timezone.utc)

    def _excluded_users(self) -> List[str]:
        """Supplement session assertion testing with a set of excluded users"""
        return ["root", "ansible"]

    def _expected_sessions(self) -> List[stop_idle_sessions.main.Session]:
        """Register the expected set of fully-fleshed-out session objects"""

        logind_sessions = self._mock_get_all_sessions()

        session_4089 = stop_idle_sessions.main.Session(
                session=logind_sessions[0],
                tty=self._mock_tty("pts/5"),
                display=None,
                display_idle=None,
                username='root',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1602192,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1602211,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1602212,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_4096 = stop_idle_sessions.main.Session(
                session=logind_sessions[1],
                tty=self._mock_tty("pts/0"),
                display=':1',
                display_idle=datetime.timedelta(seconds=3 * 60),
                username='auser',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1607896,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1608023,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1608025,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=1611110,
                                    cmdline="x11vnc -display :1 -autoport 5901",
                                    environ={}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_4098 = stop_idle_sessions.main.Session(
                session=logind_sessions[2],
                tty=self._mock_tty("pts/8"),
                display=None,
                display_idle=None,
                username='ansible',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1612636,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1612676,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_65 = stop_idle_sessions.main.Session(
                session=logind_sessions[3],
                tty=self._mock_tty("pts/1"),
                display=':1',
                display_idle=datetime.timedelta(seconds=3 * 60),
                username='root',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=60750,
                                    cmdline="/bin/sh /usr/bin/startx -- :1",
                                    environ={}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=60770,
                                    cmdline=("xinit /etc/X11/xinit/xinitrc "
                                             "-- /usr/bin/X :1 -auth "
                                             "/home/auser/.serverauth.60750"),
                                    environ={'XAUTHORITY':
                                             "/home/auser/.Xauthority"}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=60771,
                                    cmdline=("/usr/libexec/Xorg :1 -auth "
                                             "/home/auser/.serverauth.60750"),
                                    environ={}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=60776,
                                    cmdline="/usr/libexec/gnome-session-binary",
                                    environ={'DISPLAY': ":1",
                                             'XAUTHORITY': "/home/auser/.Xauthority"
                                    }
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60792,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60793,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60808,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60823,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60828,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60831,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60835,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60842,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60870,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60884,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60900,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60902,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60904,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60908,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60909,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60911,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60913,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60921,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60933,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60955,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60960,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60967,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60973,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60981,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60986,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60991,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61000,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61002,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61003,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61004,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61005,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61006,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61007,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61008,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61009,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61012,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61013,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61014,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61015,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61016,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61017,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61018,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61019,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61020,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61021,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61025,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61028,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61069,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61071,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61129,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61149,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61164,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61719,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=61723,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=67645,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=172491,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=172639,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=172640,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=549838,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=575856,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=576030,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=576031,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=630339,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=769669,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=769681,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=769997,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=769998,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=770009,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=770014,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809224,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809236,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809550,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809551,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809564,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=809571,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=837903,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=838229,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=838230,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=838243,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=838249,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=881543,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=881602,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=881730,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=938821,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=989792,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1029041,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1029158,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1536330,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1539823,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1602583,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1602590,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1740637,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1740647,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1742445,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1742446,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1765602,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2012476,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2012477,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2012478,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2012558,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2013114,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2467293,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2675914,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2686802,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2686803,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2711041,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2711048,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2711058,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2711063,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2733953,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=2744827,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=3453399,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=3453400,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=3453401,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=3806099,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4038438,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4046677,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4046678,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4046679,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4120895,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=4120896,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_72 = stop_idle_sessions.main.Session(
                session=logind_sessions[4],
                tty=self._mock_tty("pts/2"),
                display=None,
                display_idle=None,
                username='auser',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=59989,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=60053,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_82 = stop_idle_sessions.main.Session(
                session=logind_sessions[5],
                tty=self._mock_tty("pts/0"),
                display=':1',
                display_idle=datetime.timedelta(seconds=3 * 60),
                username='auser',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=69575,
                                    cmdline=("/usr/bin/Xvnc :2 -auth "
                                             "/home/auser/.Xauthority "
                                             "-desktop "
                                             "workstation.example.com:2 "
                                             "(auser) -f"),
                                    environ={}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=69590,
                                    cmdline="/bin/sh /home/auser/.vnc/xstartup",
                                    environ={'DISPLAY': ":2"}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(
                                    pid=69591,
                                    cmdline="xfce4-session",
                                    environ={'DISPLAY': ":2"}
                                ),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=68243,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=68310,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69607,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69608,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69698,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69703,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69708,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69710,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69718,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69728,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69729,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69733,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69738,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69739,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69750,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69755,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69760,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69761,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69762,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69763,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69764,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69785,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69791,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69794,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69803,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69813,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69819,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69852,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69863,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69871,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69880,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69892,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69895,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69905,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69919,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69922,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69935,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69944,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69947,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69972,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=69985,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=92366,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        session_4100 = stop_idle_sessions.main.Session(
                session=logind_sessions[6],
                tty=self._mock_tty("pts/9"),
                display=None,
                display_idle=None,
                username='auser',
                processes=[stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1617896,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1618023,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[
                                    stop_idle_sessions.ps.Process(
                                        pid=1611110,
                                        cmdline="x11vnc -display :1 -autoport 5901",
                                        environ={}
                                    )
                                ],
                                tunneled_sessions=[session_4096]),
                           stop_idle_sessions.main.SessionProcess(
                                process=stop_idle_sessions.ps.Process(pid=1618025,
                                                                      cmdline="",
                                                                      environ={}),
                                tunneled_processes=[],
                                tunneled_sessions=[])]
        )

        return [session_4089, session_4096, session_4098, session_65,
                session_72, session_82, session_4100]

    def _expected_results(self) -> List[Tuple[bool, bool,
                                              Optional[datetime.timedelta]]]:
        """Specify the expected handling for each of the _expected_sessions

        The returned tuple for _expected_results is as follows:
          (skipped_exempt: bool, terminated: bool, idle_metric: timedelta)
        """

        return [
                # session ID = 4089
                # As a session owned by root, it will be ignored.
                # Idletime is determined by the timestamp on pts/5.
                (True, False, datetime.timedelta(seconds=2143)),

                # session ID = 4096
                # Idletime is determined by DISPLAY=:1.
                (False, False, datetime.timedelta(seconds=3 * 60)),

                # session ID = 4098
                # As a session owned by ansible, it will be ignored.
                # Idletime is determined by the timestamp on pts/8.
                (True, False, datetime.timedelta(seconds=901)),

                # session ID = 65
                # Idletime is determined by DISPLAY=:1.
                (True, False, datetime.timedelta(seconds=3 * 60)),

                # session ID = 72
                # As a session without a leader, it will be ignored.
                # Idletime is determined by the timestamp on pts/2.
                (True, False, None),

                # session ID = 82
                # Idletime is determined by DISPLAY=:2.
                (False, True, datetime.timedelta(seconds=17 * 60)),

                # session ID = 4100
                # Idletime is determined by DISPLAY=:1.
                (False, False, datetime.timedelta(seconds=3 * 60))
        ]
