__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

www-data@216.73.216.10: ~ $
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
# vi: set ft=python sts=4 ts=4 sw=4 noet :

# This file is part of Fail2Ban.
#
# Fail2Ban is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Fail2Ban is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Fail2Ban; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


__author__ = "Serg G. Brester (sebres)"
__copyright__ = "Copyright (c) 2015 Serg G. Brester, 2015- Fail2Ban Contributors"
__license__ = "GPL"

from ..server.mytime import MyTime
import unittest

from ..server.ticket import Ticket, FailTicket, BanTicket


class TicketTests(unittest.TestCase):

  def testTicket(self):

    tm = MyTime.time()
    matches = ['first', 'second']
    matches2 = ['first', 'second']
    matches3 = ['first', 'second', 'third']

    # Ticket
    t = Ticket('193.168.0.128', tm, matches)
    self.assertEqual(t.getID(), '193.168.0.128')
    self.assertEqual(t.getIP(), '193.168.0.128')
    self.assertEqual(t.getTime(), tm)
    self.assertEqual(t.getMatches(), matches2)
    t.setAttempt(2)
    self.assertEqual(t.getAttempt(), 2)
    t.setBanCount(10)
    self.assertEqual(t.getBanCount(), 10)
    # default ban time (from manager):
    self.assertEqual(t.getBanTime(60*60), 60*60)
    self.assertFalse(t.isTimedOut(tm + 60 + 1, 60*60))
    self.assertTrue(t.isTimedOut(tm + 60*60 + 1, 60*60))
    t.setBanTime(60)
    self.assertEqual(t.getBanTime(60*60), 60)
    self.assertEqual(t.getBanTime(), 60)
    self.assertFalse(t.isTimedOut(tm))
    self.assertTrue(t.isTimedOut(tm + 60 + 1))
    # permanent :
    t.setBanTime(-1)
    self.assertFalse(t.isTimedOut(tm + 60 + 1))
    t.setBanTime(60)

    # BanTicket
    tm = MyTime.time()
    matches = ['first', 'second']
    ft = FailTicket('193.168.0.128', tm, matches)
    ft.setBanTime(60*60)
    self.assertEqual(ft.getID(), '193.168.0.128')
    self.assertEqual(ft.getIP(), '193.168.0.128')
    self.assertEqual(ft.getTime(), tm)
    self.assertEqual(ft.getMatches(), matches2)
    ft.setAttempt(2)
    ft.setRetry(1)
    self.assertEqual(ft.getAttempt(), 2)
    self.assertEqual(ft.getRetry(), 1)
    ft.setRetry(2)
    self.assertEqual(ft.getRetry(), 2)
    ft.setRetry(3)
    self.assertEqual(ft.getRetry(), 3)
    ft.inc()
    self.assertEqual(ft.getAttempt(), 3)
    self.assertEqual(ft.getRetry(), 4)
    self.assertEqual(ft.getMatches(), matches2)
    # with 1 match, 1 failure and factor 10 (retry count) :
    ft.inc(['third'], 1, 10)
    self.assertEqual(ft.getAttempt(), 4)
    self.assertEqual(ft.getRetry(), 14)
    self.assertEqual(ft.getMatches(), matches3)
    # last time (ignore if smaller as time):
    self.assertEqual(ft.getTime(), tm)
    ft.adjustTime(tm-60, 3600)
    self.assertEqual(ft.getTime(), tm)
    self.assertEqual(ft.getRetry(), 14)
    ft.adjustTime(tm+60, 3600)
    self.assertEqual(ft.getTime(), tm+60)
    self.assertEqual(ft.getRetry(), 14)
    ft.adjustTime(tm+3600, 3600)
    self.assertEqual(ft.getTime(), tm+3600)
    self.assertEqual(ft.getRetry(), 14)
    # adjust time so interval is larger than find time (3600), so reset retry count:
    ft.adjustTime(tm+7200, 3600)
    self.assertEqual(ft.getTime(), tm+7200)
    self.assertEqual(ft.getRetry(), 7); # estimated attempts count
    self.assertEqual(ft.getAttempt(), 4); # real known failure count
    ft.setData('country', 'DE')
    self.assertEqual(ft.getData(),  
      {'matches': ['first', 'second', 'third'], 'failures': 4, 'country': 'DE'})

    # copy all from another ticket:
    ft2 = FailTicket(ticket=ft)
    self.assertEqual(ft, ft2)
    self.assertEqual(ft.getData(), ft2.getData())
    self.assertEqual(ft2.getAttempt(), 4)
    self.assertEqual(ft2.getRetry(), 7)
    self.assertEqual(ft2.getMatches(), matches3)
    self.assertEqual(ft2.getTime(), ft.getTime())
    self.assertEqual(ft2.getTime(), ft.getTime())
    self.assertEqual(ft2.getBanTime(), ft.getBanTime())

  def testDiffIDAndIPTicket(self):
    tm = MyTime.time()
    # different ID (string) and IP:
    t = Ticket('123-456-678', tm, data={'ip':'192.0.2.1'})
    self.assertEqual(t.getID(), '123-456-678')
    self.assertEqual(t.getIP(), '192.0.2.1')
    # different ID (tuple) and IP:
    t = Ticket(('192.0.2.1', '5000'), tm, data={'ip':'192.0.2.1'})
    self.assertEqual(t.getID(), ('192.0.2.1', '5000'))
    self.assertEqual(t.getIP(), '192.0.2.1')

  def testTicketFlags(self):
    flags = ('restored', 'banned')
    ticket = Ticket('test', 0)
    trueflags = []
    for v in (True, False, True):
      for f in flags:
        setattr(ticket, f, v)
        if v:
          trueflags.append(f)
        else:
          trueflags.remove(f)
        for f2 in flags:
          self.assertEqual(bool(getattr(ticket, f2)), f2 in trueflags)
    ## inherite props from another tockets:
    ticket = FailTicket(ticket=ticket)
    for f2 in flags:
      self.assertTrue(bool(getattr(ticket, f2)))

  def testTicketData(self):
    t = BanTicket('193.168.0.128', None, ['first', 'second'])
    # expand data (no overwrites, matches are available) :
    t.setData('region', 'Hamburg', 'country', 'DE', 'city', 'Hamburg')
    self.assertEqual(
      t.getData(), 
      {'matches': ['first', 'second'], 'failures':0, 'region': 'Hamburg', 'country': 'DE', 'city': 'Hamburg'})
    # at once as dict (single argument, overwrites it completelly, no more matches/failures) :
    t.setData({'region': None, 'country': 'FR', 'city': 'Paris'},)
    self.assertEqual(
      t.getData(), 
      {'city': 'Paris', 'country': 'FR'})
    # at once as dict (overwrites it completelly, no more matches/failures) :
    t.setData({'region': 'Hamburg', 'country': 'DE', 'city': None})
    self.assertEqual(
      t.getData(), 
      {'region': 'Hamburg', 'country': 'DE'})
    self.assertEqual(
      t.getData('region'), 
      'Hamburg')
    self.assertEqual(
      t.getData('country'), 
      'DE')
    # again, named arguments:
    t.setData(region='Bremen', city='Bremen')
    self.assertEqual(t.getData(), 
      {'region': 'Bremen', 'country': 'DE', 'city': 'Bremen'})
    # again, but as args (key value pair):
    t.setData('region', 'Brandenburg', 'city', 'Berlin')
    self.assertEqual(
      t.getData('region'), 
      'Brandenburg')
    self.assertEqual(
      t.getData('city'), 
      'Berlin')
    self.assertEqual(
      t.getData(), 
      {'city':'Berlin', 'region': 'Brandenburg', 'country': 'DE'})
    # interator filter :
    self.assertEqual(
      t.getData(('city', 'country')), 
      {'city':'Berlin', 'country': 'DE'})
    # callable filter :
    self.assertEqual(
      t.getData(lambda k: k.upper() == 'COUNTRY'),
      {'country': 'DE'})
    # remove one data entry:
    t.setData('city', None)
    self.assertEqual(
      t.getData(), 
      {'region': 'Brandenburg', 'country': 'DE'})
    # default if not available:
    self.assertEqual(
      t.getData('city', 'Unknown'),
      'Unknown')
    # add continent :
    t.setData('continent', 'Europe')
    # again, but as argument list (overwrite new only, leave continent unchanged) :
    t.setData(*['country', 'RU', 'region', 'Moscow'])
    self.assertEqual(
      t.getData(), 
      {'continent': 'Europe', 'country': 'RU', 'region': 'Moscow'})
    # clear:
    t.setData({})
    self.assertEqual(t.getData(), {})
    self.assertEqual(t.getData('anything', 'default'), 'default')

Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
action_d Folder 0755
config Folder 0755
files Folder 0755
__init__.py File 974 B 0644
actionstestcase.py File 18.69 KB 0644
actiontestcase.py File 25.13 KB 0644
banmanagertestcase.py File 9.63 KB 0644
clientbeautifiertestcase.py File 9.05 KB 0644
clientreadertestcase.py File 41.68 KB 0644
databasetestcase.py File 22.72 KB 0644
datedetectortestcase.py File 26.83 KB 0644
dummyjail.py File 2.02 KB 0644
fail2banclienttestcase.py File 60.38 KB 0644
fail2banregextestcase.py File 26.97 KB 0644
failmanagertestcase.py File 8.76 KB 0644
filtertestcase.py File 87.06 KB 0644
misctestcase.py File 18.15 KB 0644
observertestcase.py File 22.5 KB 0644
samplestestcase.py File 12.14 KB 0644
servertestcase.py File 92.44 KB 0644
sockettestcase.py File 7.63 KB 0644
tickettestcase.py File 7.66 KB 0644
utils.py File 29.38 KB 0644
Filemanager