Example #1
0
def test_log_bind_attempts_for_each_server():
    t1 = TIME + timedelta(seconds=1)
    t2 = TIME + timedelta(seconds=2)
    session = _create_session()
    stats.update_stats(session, [
        {'uid': 'uzer',
         'time': t1,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
        {'uid': 'uzer',
         'time': t1,
         'success': True,
         'hostname': 'ldap3',
         'remote_addr': '10.0.0.3'},
        {'uid': 'uzer',
         'time': t2,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.4'},
    ])
    logins = session.query(stats.Login).all()
    assert_equal([(b.time, b.hostname, b.remote) for b in logins], [
        (t1, 'ldap2', '10.0.0.2'),
        (t1, 'ldap3', '10.0.0.3'),
        (t2, 'ldap2', '10.0.0.4'),
    ])
Example #2
0
def test_failed_bind_does_not_update_last_login():
    session = _create_session()
    stats.update_stats(session, [
        {'uid': 'uzer',
         'time': TIME,
         'success': False,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
    ])
    persons = session.query(stats.Person).all()
    assert_equal([(p.uid, p.last_login) for p in persons], [])
Example #3
0
 def test_export_excel_prepare_data_latin(self):
     user = u'uzerâ'.encode('latin1')
     stats.update_stats(self.session, [
         {'uid': user,
         'time': TIME,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
     ])
     persons = self.session.query(stats.Person).all()
     expected = [[user.decode('latin1').encode('utf8'), str(TIME)]]
     results = []
     for person in persons:
         results.append(person.prepare_export_row(self.fields))
     self.assertEqual(results, expected)
Example #4
0
def test_after_multiple_logins_only_last_is_saved():
    session = _create_session()
    stats.update_stats(session, [
        {'uid': 'uzer',
         'time': TIME - timedelta(seconds=2),
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
        {'uid': 'uzer',
         'time': TIME,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
    ])
    persons = session.query(stats.Person).all()
    assert_equal([(p.uid, p.last_login) for p in persons], [('uzer', TIME)])
Example #5
0
def test_log_bind_success_status():
    session = _create_session()
    stats.update_stats(session, [
        {'uid': 'uzer',
         'time': TIME,
         'success': True,
         'hostname': 'ldap1',
         'remote_addr': '10.0.0.2'},
        {'uid': 'uzer',
         'time': TIME,
         'success': False,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
    ])
    logins = session.query(stats.Login).all()
    assert_equal([(b.hostname, b.success) for b in logins], [
        ('ldap1', True),
        ('ldap2', False),
    ])
Example #6
0
 def test_export_excel_prepare_data(self):
     stats.update_stats(self.session, [
         {'uid': 'uzer',
         'time': TIME,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
         {'uid': 'uzer2',
         'time': TIME,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
         {'uid': 'uzer2',
         'time': TIME2,
         'success': True,
         'hostname': 'ldap2',
         'remote_addr': '10.0.0.2'},
     ])
     persons = self.session.query(stats.Person).all()
     expected = [['uzer', str(TIME)], ['uzer2', str(TIME2)]]
     results = []
     for person in persons:
         results.append(person.prepare_export_row(self.fields))
     self.assertEqual(results, expected)