Exemplo n.º 1
0
def test_line_terminators():
    add_filter(Stuff.smpl_file, "def test")
    hn = HostContext()
    broker = dr.Broker()
    broker[HostContext] = hn
    broker = dr.run(dr.get_dependency_graph(dostuff), broker)

    content = broker[Stuff.smpl_file].content
    assert all("def test" in l for l in content), content
    assert not any(l.endswith("\n") for l in content)
Exemplo n.º 2
0
def test_spec_factory():
    add_filter(Stuff.smpl_cmd_list_of_lists, " hello ")
    hn = HostContext()
    broker = dr.Broker()
    broker[HostContext] = hn
    broker = dr.run(dr.get_dependency_graph(dostuff), broker)
    assert dostuff in broker, broker.tracebacks
    assert broker[Stuff.smpl_file].content == file_content
    assert not any(l.endswith("\n") for l in broker[Stuff.smpl_file].content)
    assert "hello" in broker[Stuff.smpl_cmd_list_of_lists].content[0]
    assert len(broker[Stuff.smpl_cmd_list_of_lists].content) == 1
Exemplo n.º 3
0
    else:
        errors['PermitRootLogin'] = '******'
    return errors


def check_protocol(sshd_config, errors):
    # Default Protocol is 2 if not specified
    protocol = sshd_config.last('Protocol')
    if protocol:
        if protocol.lower() != '2':
            errors['Protocol'] = protocol
    return errors


add_filter(
    Specs.sshd_config,
    ["AuthenticationMethods", "LogLevel", "PermitRootLogin", "Protocol"])


@rule(InstalledRpms, SSHDConfig)
def report(installed_rpms, sshd_config):
    errors = {}
    errors = check_auth_method(sshd_config, errors)
    errors = check_log_level(sshd_config, errors)
    errors = check_permit_root(sshd_config, errors)
    errors = check_protocol(sshd_config, errors)

    if errors:
        openssh_version = installed_rpms.get_max('openssh')
        return make_fail(ERROR_KEY,
                         errors=errors,
Exemplo n.º 4
0
MSGINFO = """
Aug 24 09:31:39 localhost polkitd[822]: Loading rules from directory /etc/polkit-1/rules.d
Aug 24 09:31:39 localhost polkitd[822]: Loading rules from directory /usr/share/polkit-1/rules.d
Aug 24 09:31:39 localhost polkitd[822]: Finished loading, compiling and executing 6 rules
Aug 24 09:31:39 localhost polkitd[822]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
Aug 25 13:52:54 localhost sshd[23085]: pam_unix(sshd:session): session opened for user zjj by (uid=0)
Aug 25 13:52:54 localhost sshd[23085]: error: openpty: No such file or directory
Aug 25 13:52:54 localhost sshd[23089]: error: session_pty_req: session 0 alloc failed
Aug 25 14:04:04 localhost sshd[23089]: Received disconnect from 10.66.192.100: 11: disconnected by user
Aug 25 14:04:04 localhost sshd[23085]: pam_unix(sshd:session): session closed for user zjj
Strange line with : but not otherwise parseable for testing code correctness
    Test continuation line
""".strip()

add_filter("secure", ["polkitd", "sshd"])


def test_secure():
    msg_info = Secure(context_wrap(MSGINFO))
    ssh_list = msg_info.get('sshd')
    assert 5 == len(ssh_list)
    assert ssh_list[0].get('timestamp') == "Aug 25 13:52:54"
    assert ssh_list[4].get('timestamp') == "Aug 25 14:04:04"
    polkitd = msg_info.get('Loading rules from directory')
    assert 2 == len(polkitd)
    assert polkitd[0].get('procname') == "polkitd[822]"
    assert polkitd[1].get(
        'raw_message'
    ) == "Aug 24 09:31:39 localhost polkitd[822]: Loading rules from directory /usr/share/polkit-1/rules.d"
    assert polkitd[1].get(
Exemplo n.º 5
0
LOG2 = """
2011-12-27 08:41:12,460 [DEBUG]  @connection.py:209 - Making request: GET /subscription/users/isavia_sysdep/owners
2011-12-27 08:41:13,104 [ERROR]  @managercli.py:65 - Error during registration: certificate verify failed
2011-12-27 08:41:13,104 [ERROR]  @managercli.py:66 - certificate verify failed
    Traceback (most recent call last):
    File "/usr/share/rhsm/subscription_manager/managercli.py", line 600, in _do_command
""".strip()

# For Coverage
LOG3 = """
[ERROR]
2011-12-27-08:41:13,104 [ERROR]  @managercli.py:66 - certificate verify failed
"""

add_filter(Specs.rhsm_log, [
    "[ERROR]",
    "[Errno"
])


def test_rhsm_log():
    rlog = RhsmLog(context_wrap(LOG1))
    ern_list = rlog.get('[Errno -2]')
    assert 1 == len(ern_list)
    assert ern_list[0]['raw_message'] == "2016-07-31 04:07:21,245 [ERROR] rhsmcertd-worker:24440 @entcertlib.py:121 - [Errno -2] Name or service not known"
    assert ern_list[0]['timestamp'] == datetime(2016, 7, 31, 4, 7, 21, 245000)
    assert ern_list[0]['message'] == "[ERROR] rhsmcertd-worker:24440 @entcertlib.py:121 - [Errno -2] Name or service not known"

    rlog = RhsmLog(context_wrap(LOG2))
    ern_list = rlog.get('[Errno -2]')
    assert 0 == len(ern_list)
    err_list = rlog.get('ERROR')
Exemplo n.º 6
0
DUMMY_AUDIT_LOG_1 = """
type=AVC
""".strip()

DUMMY_AUDIT_LOG_2 = """
type=AVC msg=whatever(1506487181.009:32794): avc:  denied  { create } for  pid=27960 comm="mongod" scontext=system_u:system_r:mongod_t:s0 tcontext=system_u:system_r:mongod_t:s0 tclass=unix_dgram_socket
""".strip()

DUMMY_AUDIT_LOG_3 = """
type=AVC msg=audit(1506abc181.009:32794): avc:  denied  { create } for  pid=27960 comm="mongod" scontext=system_u:system_r:mongod_t:s0 tcontext=system_u:system_r:mongod_t:s0 tclass=unix_dgram_socket
""".strip()

LAST_LINE_OF_TEMPLATE = """type=CRED_REFR msg=audit(1508476956.471:13339): pid=30909 uid=0 auid=0 ses=1559 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:setcred grantors=pam_unix acct="root" exe="/usr/sbin/sshd" hostname=foo.example.com addr=192.0.2.2 terminal=ssh res=success'"""

add_filter("audit_log", [
    "CRYPTO_KEY_USER",
    "LOGIN"
])


def test_audit_log():

    auditlog = AuditLog(context_wrap(AUDIT_LOG_TEMPALTE % AUDIT_LOG_NORMAL))

    info = auditlog.get(['type=', 'msg='])
    assert len(info) == 4
    info = auditlog.get('type=')
    assert len(info) == 4
    line0 = info[0]
    assert line0.get('type') == 'CRYPTO_KEY_USER'
    assert line0.get('msg') == 'op=destroy kind=session fp=? direction=both spid=16865 suid=0 rport=59296 laddr=192.0.2.1 lport=22  exe="/usr/sbin/sshd" hostname=? addr=10.66.136.139 terminal=? res=success'
    assert line0.get('unparsed') is None
Exemplo n.º 7
0
from insights.specs import Specs
from insights.tests import context_wrap

MSGINFO = """
May 18 15:13:34 lxc-rhel68-sat56 jabberd/sm[11057]: session started: [email protected]/superclient
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: --> Wrapper Started as Daemon
May 18 15:13:36 lxc-rhel68-sat56 wrapper[11375]: Launching a JVM...
May 18 15:24:28 lxc-rhel68-sat56 yum[11597]: Installed: lynx-2.8.6-27.el6.x86_64
May 18 15:36:19 lxc-rhel68-sat56 yum[11954]: Updated: sos-3.2-40.el6.noarch
Apr 22 10:35:01 boy-bona CROND[27921]: (root) CMD (/usr/lib64/sa/sa1 -S DISK 1 1)
Apr 22 10:37:32 boy-bona crontab[28951]: (root) LIST (root)
Apr 22 10:40:01 boy-bona CROND[30677]: (root) CMD (/usr/lib64/sa/sa1 -S DISK 1 1)
Apr 22 10:41:13 boy-bona crontab[32515]: (root) LIST (root)
""".strip()

add_filter(Specs.messages,
           ["LIST", "CROND", "jabberd", "Wrapper", "Launching", "yum"])


def test_doc_examples():
    env = {
        'msgs': messages.Messages(context_wrap(MSGINFO)),
        'Messages': messages.Messages
    }
    failed, total = doctest.testmod(messages, globs=env)
    assert failed == 0


def test_messages():
    msg_info = messages.Messages(context_wrap(MSGINFO))
    bona_list = msg_info.get('(root) LIST (root)')
    assert 2 == len(bona_list)
"""
InsightsClientConf - file ``/etc/insights-client/insights-client.conf``
=======================================================================

"""
from insights import IniConfigFile, parser, add_filter
from insights.specs import Specs

add_filter(Specs.insights_client_conf, "[")


@parser(Specs.insights_client_conf)
class InsightsClientConf(IniConfigFile):
    """
    This class provides parsing for the file ``/etc/insights-client/insights-client.conf``.

    Sample input data is in the format::

        [insights-client]
        auto_update=False

    See the :class:`insights.core.IniConfigFile` class for examples.
    """
    pass
Exemplo n.º 9
0
"""
Doveconf - command ``doveconf``
===============================
"""
import string

from insights import parser, add_filter
from insights.combiners.nginx_conf import EmptyQuotedString
from insights.core import ConfigParser
from insights.parsr import (EOF, InSet, Lift, Many, OneLineComment, PosMarker,
                            QuotedString, skip_none, String, WS, WSChar,
                            LeftCurly, RightCurly, Forward, EOL)
from insights.parsr.query import Directive, Entry, Section
from insights.specs import Specs

add_filter(Specs.doveconf, ["{", "}"])


@parser(Specs.doveconf, continue_on_error=False)
class Doveconf(ConfigParser):
    """
    Class for parsing the ``doveconf`` command.
    Sample input::

        # 2.2.36 (1f10bfa63): /etc/dovecot/dovecot.conf
        auth_anonymous_username = anonymous
        auth_cache_negative_ttl = 1 hours
        auth_policy_request_attributes = login=%{requested_username} pwhash=%{hashed_password} remote=%{rip} device_id=%{client_id} protocol=%s
        auth_policy_server_api_header =
        log_timestamp = "%b %d %H:%M:%S "
        login_access_sockets =
Exemplo n.º 10
0
"""
NeutronL3AgentIni - file ``/etc/neutron/l3_agent.ini``
======================================================

The ``NeutronL3AgentIni`` class parses the l3_agent configuration file.
See the ``IniConfigFile`` class for more usage information.
"""

from insights import add_filter, parser, IniConfigFile
from insights.specs import Specs

add_filter(Specs.neutron_l3_agent_ini, ["["])


@parser(Specs.neutron_l3_agent_ini)
class NeutronL3AgentIni(IniConfigFile):
    """
    Parse the ``/etc/neutron/l3_agent.ini`` configuration file.

    Sample configuration::

         [DEFAULT]

         #
         # From neutron.base.agent
         #

         # Name of Open vSwitch bridge to use (string value)
         ovs_integration_bridge = br-int

         # Uses veth for an OVS interface or not. Support kernels with limited namespace
Exemplo n.º 11
0
                               '".php[45]?$"', 'httpd.conf',
                               'etc/httpd/conf/httpd.conf')]
                }
            }
        },
        'JustATest': [('on', 'JustATest on', 'IfModule', '!php5_module',
                       'httpd.conf', 'etc/httpd/conf/httpd.conf')],
    }


add_filter(Specs.httpd_conf, [
    'SSLProtocol',
    'NSSProtocol',
    'RequestHeader',
    'FcgidPassHeader'
    '<IfModule worker.c>',
    '<IfModule prefork.c>',
    '</IfModule>',
    'MaxClients',
    'UserDir',
])


def test_get_httpd_conf_1():
    context = context_wrap(HTTPD_CONF_1, path=HTTPD_CONF_PATH)
    result = HttpdConf(context)

    assert "SSLCipherSuite" not in result
    assert "SSLV3 TLSV1.0" in result["NSSProtocol"][-1]
    assert result[("IfModule", "prefork.c")]["MaxClients"][-1].value == "256"
    assert result[("IfModule", "worker.c")]["MaxClients"][-1].value == "300"