コード例 #1
0
def test_match():
    with patch("salt.utils.files.fopen", mock_open(read_data=raw)):
        with patch("struct.unpack", MagicMock(return_value=pack)):
            config = [{"users": {"gareth": {}}}]

            ret = wtmp.validate(config)

            assert ret == (True, "Valid beacon configuration")

            _expected = [
                {
                    "PID": 6216,
                    "action": "login",
                    "line": "pts/14",
                    "session": 0,
                    "time": 0,
                    "exit_status": 0,
                    "inittab": "s/14",
                    "type": 7,
                    "addr": 1506101523,
                    "hostname": "::1",
                    "user": "******",
                }
            ]

            ret = wtmp.beacon(config)
            log.debug("wtmp beacon: %s", ret)
            assert ret == _expected
コード例 #2
0
    def test_match_time(self):
        with patch('salt.utils.files.fopen',
                   mock_open(read_data=raw)):
            with patch('time.time',
                       MagicMock(return_value=1506121200)):
                with patch('struct.unpack',
                           MagicMock(return_value=pack)):
                    config = [{'users': {'gareth': {'time': {'end': '5pm',
                                                             'start': '3pm'}}}}
                              ]

                    ret = wtmp.validate(config)

                    self.assertEqual(ret, (True, 'Valid beacon configuration'))

                    _expected = [{'PID': 6216,
                                  'line': 'pts/14',
                                  'session': 0,
                                  'time': 0,
                                  'exit_status': 0,
                                  'inittab': 's/14',
                                  'type': 7,
                                  'addr': 1506101523,
                                  'hostname': '::1',
                                  'user': '******'}]

                    ret = wtmp.beacon(config)
                    self.assertEqual(ret, _expected)
コード例 #3
0
ファイル: test_wtmp.py プロジェクト: a-a-abramov/saltstack
def test_invalid_users():
    config = [{"users": ["gareth"]}]

    ret = wtmp.validate(config)

    assert ret == (False,
                   "User configuration for wtmp beacon must be a dictionary.")
コード例 #4
0
ファイル: test_wtmp.py プロジェクト: a-a-abramov/saltstack
def test_invalid_groups():
    config = [{"groups": ["docker"]}]

    ret = wtmp.validate(config)

    assert ret == (False,
                   "Group configuration for wtmp beacon must be a dictionary.")
コード例 #5
0
    def test_invalid_groups(self):
        config = [{'groups': ['docker']}]

        ret = wtmp.validate(config)

        self.assertEqual(
            ret, (False,
                  'Group configuration for wtmp beacon must be a dictionary.'))
コード例 #6
0
    def test_invalid_users(self):
        config = [{'users': ['gareth']}]

        ret = wtmp.validate(config)

        self.assertEqual(
            ret, (False,
                  'User configuration for wtmp beacon must be a dictionary.'))
コード例 #7
0
    def test_invalid_groups(self):
        config = [{"groups": ["docker"]}]

        ret = wtmp.validate(config)

        self.assertEqual(
            ret, (False,
                  "Group configuration for wtmp beacon must be a dictionary."))
コード例 #8
0
    def test_invalid_users(self):
        config = [{"users": ["gareth"]}]

        ret = wtmp.validate(config)

        self.assertEqual(
            ret, (False,
                  "User configuration for wtmp beacon must be a dictionary."))
コード例 #9
0
def test_match_group():

    for groupadd in (
        "salt.modules.aix_group",
        "salt.modules.mac_group",
        "salt.modules.pw_group",
        "salt.modules.solaris_group",
        "salt.modules.win_groupadd",
    ):
        mock_group_info = {
            "passwd": "x",
            "gid": 100,
            "name": "users",
            "members": ["gareth"],
        }

        with patch("salt.utils.files.fopen", mock_open(read_data=raw)):
            with patch("time.time", MagicMock(return_value=1506121200)):
                with patch("struct.unpack", MagicMock(return_value=pack)):
                    with patch(
                        "{}.info".format(groupadd),
                        new=MagicMock(return_value=mock_group_info),
                    ):
                        config = [
                            {
                                "group": {
                                    "users": {
                                        "time": {
                                            "end": "09-22-2017 5pm",
                                            "start": "09-22-2017 3pm",
                                        }
                                    }
                                }
                            }
                        ]

                        ret = wtmp.validate(config)

                        assert ret == (True, "Valid beacon configuration")

                        _expected = [
                            {
                                "PID": 6216,
                                "action": "login",
                                "line": "pts/14",
                                "session": 0,
                                "time": 0,
                                "exit_status": 0,
                                "inittab": "s/14",
                                "type": 7,
                                "addr": 1506101523,
                                "hostname": "::1",
                                "user": "******",
                            }
                        ]

                        ret = wtmp.beacon(config)
                        assert ret == _expected
コード例 #10
0
def test_groups_invalid_time_range():
    config = [{"groups": {"docker": {"time_range": {"start": "3pm"}}}}]

    ret = wtmp.validate(config)

    assert ret == (
        False,
        "The time_range parameter for wtmp beacon must contain start & end options.",
    )
コード例 #11
0
    def test_groups_invalid_time_range(self):
        config = [{'groups': {'docker': {'time_range': {'start': '3pm'}}}}]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (
            False,
            'The time_range parameter for wtmp beacon must contain start & end options.'
        ))
コード例 #12
0
    def test_no_match(self):
        config = [{'users': {'gareth': {'time': {'end': '5pm',
                                                 'start': '3pm'}}}}
                  ]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (True, 'Valid beacon configuration'))

        ret = wtmp.beacon(config)
        self.assertEqual(ret, [])
コード例 #13
0
    def test_users_invalid_time_range(self):
        config = [{"users": {"gareth": {"time_range": {"start": "3pm"}}}}]

        ret = wtmp.validate(config)

        self.assertEqual(
            ret,
            (
                False,
                "The time_range parameter for wtmp beacon must contain start & end options.",
            ),
        )
コード例 #14
0
    def test_no_match(self):
        config = [{'users': {'gareth': {'time': {'end': '5pm',
                                                 'start': '3pm'}}}}
                  ]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (True, 'Valid beacon configuration'))

        with patch('salt.utils.files.fopen', mock_open()) as m_open:
            ret = wtmp.beacon(config)
            m_open.assert_called_with(wtmp.WTMP, 'rb')
            self.assertEqual(ret, [])
コード例 #15
0
    def test_match_group(self):

        for groupadd in ('salt.modules.aix_group', 'salt.modules.mac_group',
                         'salt.modules.pw_group', 'salt.modules.solaris_group',
                         'salt.modules.win_groupadd'):
            mock_group_info = {
                'passwd': 'x',
                'gid': 100,
                'name': 'users',
                'members': ['gareth']
            }

            with patch('salt.utils.files.fopen', mock_open(read_data=raw)):
                with patch('time.time', MagicMock(return_value=1506121200)):
                    with patch('struct.unpack', MagicMock(return_value=pack)):
                        with patch(
                                '{0}.info'.format(groupadd),
                                new=MagicMock(return_value=mock_group_info)):
                            config = [{
                                'group': {
                                    'users': {
                                        'time': {
                                            'end': '09-22-2017 5pm',
                                            'start': '09-22-2017 3pm'
                                        }
                                    }
                                }
                            }]

                            ret = wtmp.validate(config)

                            self.assertEqual(
                                ret, (True, 'Valid beacon configuration'))

                            _expected = [{
                                'PID': 6216,
                                'action': 'login',
                                'line': 'pts/14',
                                'session': 0,
                                'time': 0,
                                'exit_status': 0,
                                'inittab': 's/14',
                                'type': 7,
                                'addr': 1506101523,
                                'hostname': '::1',
                                'user': '******'
                            }]

                            ret = wtmp.beacon(config)
                            self.assertEqual(ret, _expected)
コード例 #16
0
ファイル: test_wtmp.py プロジェクト: elisapa/salt-1
    def test_no_match(self):
        config = [{'users': {'gareth': {'time_range': {'end': '09-22-2017 5pm',
                                                       'start': '09-22-2017 3pm'}}}}
                  ]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (True, 'Valid beacon configuration'))

        with patch('salt.utils.files.fopen', mock_open(b'')) as m_open:
            ret = wtmp.beacon(config)
            call_args = next(six.itervalues(m_open.filehandles))[0].call.args
            assert call_args == (wtmp.WTMP, 'rb'), call_args
            assert ret == [], ret
コード例 #17
0
def test_match_time():
    with patch("salt.utils.files.fopen", mock_open(read_data=raw)):
        mock_now = datetime.datetime(2017, 9, 22, 16, 0, 0, 0)
        with patch("datetime.datetime", MagicMock()), patch(
            "datetime.datetime.now", MagicMock(return_value=mock_now)
        ):
            with patch("struct.unpack", MagicMock(return_value=pack)):
                config = [
                    {
                        "users": {
                            "gareth": {
                                "time": {
                                    "end": "09-22-2017 5pm",
                                    "start": "09-22-2017 3pm",
                                }
                            }
                        }
                    }
                ]

                ret = wtmp.validate(config)

                assert ret == (True, "Valid beacon configuration")

                _expected = [
                    {
                        "PID": 6216,
                        "action": "login",
                        "line": "pts/14",
                        "session": 0,
                        "time": 0,
                        "exit_status": 0,
                        "inittab": "s/14",
                        "type": 7,
                        "addr": 1506101523,
                        "hostname": "::1",
                        "user": "******",
                    }
                ]

                ret = wtmp.beacon(config)
                assert ret == _expected
コード例 #18
0
    def test_no_match(self):
        config = [{
            "users": {
                "gareth": {
                    "time_range": {
                        "end": "09-22-2017 5pm",
                        "start": "09-22-2017 3pm",
                    }
                }
            }
        }]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (True, "Valid beacon configuration"))

        with patch("salt.utils.files.fopen", mock_open(b"")) as m_open:
            ret = wtmp.beacon(config)
            call_args = next(six.itervalues(m_open.filehandles))[0].call.args
            assert call_args == (wtmp.WTMP, "rb"), call_args
            assert ret == [], ret
コード例 #19
0
def test_empty_config():
    config = [{}]

    ret = wtmp.validate(config)

    assert ret == (True, "Valid beacon configuration")
コード例 #20
0
def test_non_list_config():
    config = {}
    ret = wtmp.validate(config)

    assert ret == (False, "Configuration for wtmp beacon must be a list.")
コード例 #21
0
    def test_empty_config(self):
        config = [{}]

        ret = wtmp.validate(config)

        self.assertEqual(ret, (True, 'Valid beacon configuration'))
コード例 #22
0
    def test_non_list_config(self):
        config = {}
        ret = wtmp.validate(config)

        self.assertEqual(ret, (False, 'Configuration for wtmp beacon must'
                                      ' be a list.'))