%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/fail2ban/tests/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyc

�
��&dc@sdZdZdZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZm
Z
mZddlmZddlmZmZmZdd	lmZdd
lmZddlmZmZddlmZdd
lmZddl m Z ddl!m"Z"m#Z#ej$j%ej$j&e'�d�Z(iZ)ddl!m*Z*e	j+j,Z-ej$j%ej$j&e'�d�Z.iZ/de	j0fd��YZ1de"fd��YZ2de"fd��YZ3de"fd��YZ4de"fd��YZ5dS(s!Cyril Jaquier, Yaroslav Halchenkos>Copyright (c) 2004 Cyril Jaquier, 2011-2013 Yaroslav HalchenkotGPLi����Ni(tConfigReadertConfigReaderUnsharedtDefinitionInitConfigReadertNoSectionError(tconfigparserinc(t
JailReadertextractOptionstsplitWithOptions(tFilterReader(tJailsReader(tActionReadert
CommandAction(tConfigurator(tMyTime(tversioni(tLogCaptureTestCasetwith_tmpdirtfiles(t
CONFIG_DIRtconfigtConfigReaderTestcBs}eZd�Zd�Zd
d
d�Zd�Zdd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�ZRS(cCsAtt|�j�tjdd�|_td|j�|_dS(sCall before every test case.tprefixsf2b-temptbasedirN(tsuperRtsetUpttempfiletmkdtemptdRtc(tself((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR7scCstj|j�dS(sCall after every test case.N(tshutiltrmtreeR(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttearDown=scCs�tjj|kratjj|�}tjj|j|�}tjj|�satj|�qantd|j|fd�}|dk	r�|j
d|�n|dk	r�|j
|�n|j�dS(Ns%s/%stws
[section]
option = %s
	(tostpathtseptdirnametjoinRtexiststmakedirstopentNonetwritetclose(RtfnametvaluetcontentRtd_tf((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt_writeAscCs7tjd|j|f�|j|jjd��dS(Ns%s/%sR(R#tunlinkRt
assertTrueRtread(RR.((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt_removeRsRcCs3|j|jj|��|jjddg�dS(Ntsectiontinttoption(sintsoption(R5RR6t
getOptions(RR2((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt
_getoptionVscCs+|jjd�|jjddd�|jjddd�|jjddd�|jjdddd
f�}|j|id
d6td6dd6�|jjddddf�}|j|id
d6td6dd6�|jjdidd6dd6dd6�}|j|id
d6td6dd6�dS(Nt
Definitiontat1tbRttestR9itbooli(sintR>i(sboolR@i(sintRi(sintR>(sboolR@(sintR(sinti(sbooli(sinti(Rtadd_sectiontsetR;tassertSortedEqualtTrueR+(Rtopts((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestConvertZs%%cCs�tjj|jd�}|jdd�|j|jd�d�tj|d�tj|tj	�s�|j
|jjd��n%ddl
}tjd|j
���dS(Nsd.confiRi����s0Skipping on %s -- access rights are not enforced(R#R$R'RR3tassertEqualR<tchmodtaccesstR_OKtassertFalseRR6tplatformtunittesttSkipTest(RR2RN((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestInaccessibleFileiscCs�|j|jjd��|jdd�|j|j�d�|jdd�|j|j�d�|jdd�|j|j�d	�|jd
d�|j|j�d	�|jdd
�|j|j�d�|jdd�|j|j�d�|jdd�|j|j�d�|jd�|jd�|j|j�d�|jd�|j|j�d	�|jd�|j|j�d�|jd
�|j|j�d�dS(NRsc.confR?it2isc.d/98.conft998i�sc.d/90.conft990sc.d/99.conft999i�sc.localt3isc.d/1.localt4ii�(RMRR6R3RIR<R7(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestOptionalDotDDirvs0




cCsE|jddddd�|jddddd�|jddddd�|jd	dddd
�|jddddd�d
tfd��Y}|ddi�|_|jj|j�|j|jj��|jjidt	�|jj
�}|j|jd�d�|j|jd�d�|j|jd�d�dS(Nsc.confR/R0sS
[INCLUDES]
before = ib.conf
after  = ia.conf
[Definition]
test = %(default/test)s
sib.confs,
[DEFAULT]
test = A
[Definition]
option = 1
sib.locals,
[DEFAULT]
test = B
[Definition]
option = 2
sia.confs,
[DEFAULT]
test = C
[Definition]
oafter = 3
sia.locals,
[DEFAULT]
test = D
[Definition]
oafter = 4
tTestDefConfReadercBs5eZiddgd6ddgd6ddgd6ZRS(R9R:toaftertstringRAN(t__name__t
__module__R+t_configOpts(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyRY�s

RR:talliRZiRAtD(
R3R+RRt
setBaseDirRR5R6R;RFtgetCombinedRItget(RRYto((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestLocalInIncludes�s&cCs	|j|jjd��|jddddd�|j|jjd��|j|jj�ddg�|j|jjdd�d	�|j|jjdd
�d�|j|jjdd�d�|j|jjdd
�d�|j|jjdd�d�dS(Ntisi.confR/R0su
[DEFAULT]
b = a
zz = the%(__name__)s

[section]
y = 4%(b)s
e = 5${b}
z = %(__name__)s

[section2]
z = 3%(__name__)s
R8tsection2tyt4ates5${b}tztzzt
thesectiont	3section2(	RMRR6R3R+R5RItsectionsRc(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestInterpolations�scCs�|j|jjd��|jddddd�|j|jjd��|j|jjdd�d�|j|jjdd	�d
�dS(Ntgsg.confR/R0s4
[DEFAULT]
# A comment
b = a
c = d ;in line comment
tDEFAULTR@R>RR(RMRR6R3R+R5RIRc(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestComments�scCs�|j|jjd��|jddddd�|j|jjd��|j|jjdd�d�|j|jjdd	�d
�|j|jjdd�d�|j|jjdd	�d
�|j|jjdd�d�|j|jjdd�d�|j|jjdd�d�|j|jjdd�d�|j|jjdd�d�|j|jjdd�d�|jt	|jjdd�|jt	|jjdd�dS(NRqsg.confR/R0s�
[DEFAULT]
a = def-a
b = def-b,a:`%(a)s`
c = def-c,b:"%(b)s"
d = def-d-b:"%(known/b)s"

[jail]
a = jail-a-%(test/a)s
b = jail-b-%(test/b)s
y = %(test/y)s

[test]
a = test-a-%(default/a)s
b = test-b-%(known/b)s
x = %(test/x)s
y = %(jail/y)s
RAR>stest-a-def-aR@stest-b-def-b,a:`test-a-def-a`tjailsjail-a-test-a-def-as+jail-b-test-b-def-b,a:`jail-a-test-a-def-a`Rs5def-c,b:"jail-b-test-b-def-b,a:`jail-a-test-a-def-a`"Rs'def-d-b:"def-b,a:`jail-a-test-a-def-a`"s'def-c,b:"test-b-def-b,a:`test-a-def-a`"s def-d-b:"def-b,a:`test-a-def-a`"Rrsdef-c,b:"def-b,a:`def-a`"sdef-d-b:"def-b,a:`def-a`"txRh(
RMRR6R3R+R5RIRctassertRaisest	Exception(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestTargetedSectionOptions�s N(R\R]RR!R+R3R7R<RHRQRXReRpRsRx(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR5s					
		0		tJailReaderTestcBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zed��Zd�ZRS(cOstt|�j||�dS(N(RRyt__init__(Rtargstkwargs((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyRzscCs
xdD]�}|jtd|f�ddg�|jtd|f�ddg�|jtd	|f�d
dg�|jtd|f�ddg�|jtd
|f�ddg�|jtd|f�ddg�|jtd|f�ddg�qWdS(Ns
s	t sa%sbR>R@s	a[x=y]%sbsa[x=y]sa[x=y][z=z]%sbsa[x=y][z=z]sa[x="y][z"]%sbsa[x="y][z"]s
a[x="y z"]%sbs
a[x="y z"]s
a[x="y	z"]%sbs
a[x="y	z"]s
a[x="y
z"]%sbs
a[x="y
z"](s
s	R}(RIR(RR%((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestSplitWithOptionss
######cCs/tddtdt�}|jt|j�dS(NtXXXABSENTXXXRtshare_config(RRtCONFIG_DIR_SHARE_CFGRvt
ValueErrorR6(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestIncorrectJailscCsotddtdt�}|j|j��|j|j��|j|j��|jd�|jd�dS(NtemptyactionRR�s"No filter set for jail emptyactions'No actions were defined for emptyaction(RtIMPERFECT_CONFIGtIMPERFECT_CONFIG_SHARE_CFGR5R6R;t	isEnabledtassertLogged(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestJailActionEmptys
cCsstddtdt�}|j|j��|j|j��|j|j��|jdt�|jd�dS(NtmissingbitsjailRR�sJFound no accessible config files for 'filter.d/catchallthebadies' under %ssUnable to read the filter(	RR�R�R5R6RMR;R�R�(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestJailActionFilterMissing"scCsbtddtdt�}|j|j��|j|j��|j|j��|jd�dS(NtbrokenactiondefRR�s$Invalid action definition 'joho[foo'(	RR�R�R5R6RMR;R�R�(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestJailActionBrokenDef*s	cCsltddtdt�}|j|j��|j|j��|j|j��|j|jdd�dS(Nt
tz_correctRR�tlogtimezonesUTC+0200(	RR�R�R5R6R;R�RItoptions(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestJailLogTimeZone2s	cCsbtddtdt�}|j|j��|j|j��|j|j��|jd�dS(NtbrokenfilterdefRR�s$Invalid filter definition 'flt[test'(	RR�R�R5R6RMR;R�R�(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestJailFilterBrokenDef:s	cCs�tjjdt�tddtdt�}|j|j��|j|j	��|j
|j��|j|j
�d�|jd�|j|j
�d�dS(NtstocktsshdRR�sssh-funky-blocker(ROtF2BtSkipIfCfgMissingRFRRR�R5R6R;RMR�RItgetNametsetName(RRt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestStockSSHJailBs
cCs�tjjdt�tddtdtdt�}|j|j��|j|j	��|j|j
��|j�}|jddddggg|D].}t
|�d	kr�|d	dkr�|^q��|jddd
dggg|D].}t
|�d	kr�|d	d
kr�|^q��|jdddd	ggg|D].}t
|�d	kr=|d	dkr=|^q=�|jddd
dg�}d}xT|D]L}|jt
|�d	ko�|d	jd��|d7}||kr�Pq�q�WdS(NR�ssshd-override-flt-optsRR�tforce_enableRDt	prefregexs^Testitaddjournalmatchs
_COMM=testtmaxlinestusednstnoitregexi(ROR�R�RFRR�R�R5R6R;R�tconvertRItlentindexRMtendswith(RRttstreamRdt	usednsidxRf((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestOverrideFilterOptInJailLs(<<<
,
c
Cs�tjjdt�x�dD]�}x�dD]�}td|j�d	td
tdt�}|j|j	��|j|j
��|j�}|jd|j
�d
d|ggg|D].}t|�dkr�|dd
kr�|^q��q'WqWdS(NR�iitJRNLtFILEtTESTtINITt
checklogtype_RR�R�RDtaddfailregexs^%s failure from <HOST>$(ii(R�R�R�R�(ROR�R�RFRtlowerR�R�R5R6R;R�RIR�R�(RRftpreflineRtR�Rd((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestLogTypeOfBackendInJailfs

"cCs�d}didd6f}t|�}|j||�|jdiftd��|jdidd6dd	6ftd
��|jdiftd��|jdiftd��|jd
idd6ftd��d}dif}t|�}|j||�d}didd6dd6dd6dd6dd6dd6dd 6d!d"6d#d$6d%d&6d%d'6f}t|�}|j||�t|jdd(��}|d)td*�|d+j�D��f}|j||�dS(,Nsmail-whois[name=SSH]s
mail-whoistSSHtnamesmail.who_istcatR>tdogR@smail.who_is[a=cat,b=dog]smail--ho_issmail--ho_is['s']tmailt,smail[a=',']sabc[]tabcs�option[opt01=abc,opt02="123",opt03="with=okay?",opt04="andwith,okay...",opt05="how about spaces",opt06="single'in'double",opt07='double"in"single',  opt08= leave some space, opt09=one for luck, opt10=, opt11=]R:topt01t123topt02s
with=okay?topt03sandwith,okay...topt04show about spacestopt05ssingle'in'doubletopt06sdouble"in"singletopt07sleave some spacetopt08sone for lucktopt09ttopt10topt11s][icss-|]#\}}||jdd�fVqdS(R�s][N(treplace(t.0tktv((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pys	<genexpr>�si(RRIR�tdictt	iteritems(RR:texpectedtresultt	expected2((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestSplitOptionus@*#
#c
Cshtddtdtdt�}|j|j��|j|j��|j|jdd�|j|jdd�|j	g|j
D]}|j�^q�d	dd
dgddddd
dgddgddggggd	dd
dgddddd
dgddgddgddggggd	dd
dgddddd
dgddgddggggg�dS(Ns	multi-logR�RR�tlogpathsa.log
b.log
c.logtactionseaction[actname='ban']
action[actname='log', logpath="a.log
b.log
c.log
d.log"]
action[actname='test']RDt	addactiontbans	multi-sett	actionbans4echo "name: ban, ban: <ip>, logs: a.log
b.log
c.log"tactnameR�tlogs:echo "name: log, ban: <ip>, logs: a.log
b.log
c.log
d.log"sa.log
b.log
c.log
d.logRAs5echo "name: test, ban: <ip>, logs: a.log
b.log
c.log"(RRFR�R�R5R6R;RIR�REt_JailReader__actionsR�(RRtR>((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestMultiLineOption�s$%						c
Cstjjdt�tddtdt�}tj|d�|jj	�}t
d d!d"d#d$d%f�|d<|j|j��|j
�}g}x�|D]�}t|�dkr�q�n|ddkr�|ddks�|djd�r�|j|�q�|ddkr�|jg|dD].}|ddkrdg|dd!|^q�q�q�Wdt}|jt|�d�|j|dddddd|g�|j|dddddd|g�|jt|dd�jdd�|�|j|dddddd|g�dS(&NR�t
blocklisttestR�RRtR\tfilterR�t	failregexs
^test <HOST>$tsendersf2b-test@example.comtblocklist_de_apikeystest-keyR�s�%(action_blocklist_de)s
%(action_badips_report)s
%(action_badips)s
mynetwatchman[port=1234,protocol=udp,agent="%(fail2ban_agent)s"]iiRDtagents	badips.pys	multi-setisFail2Ban/%stblocklist_detbadipsiis<wrong>it
mynetwatchman(s__name__R�(sfilterR�(R�s
^test <HOST>$(R�sf2b-test@example.com(R�stest-key(sactions�%(action_blocklist_de)s
%(action_badips_report)s
%(action_badips)s
mynetwatchman[port=1234,protocol=udp,agent="%(fail2ban_agent)s"](ROR�R�RFRRRR6t_cfgtget_sectionsR�R5R;R�R�R�tappendtextendRRItevalRc(RRtRoR�tacttcmdRdt	useragent((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestVersionAgent�s2
3M
&&*cCs�tjj|d�}t|d�j�tjj|d�}tjd|�|jtjtjj|d��|g�|jtj|�g�|j	d|�|jtjtjj|d��g�dS(Ntf1R"tf2tnonexistingt*s4File %s is a dangling link, thus cannot be monitored(
R#R$R'R*R-tsymlinkRIRt_globR�(RRR�R�((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestGlob�s+cCs�tdi�}|j|j�g�|j|jd��|jt|jdi�|jt|jd�|jt|j	dd�|jt|j
di�dS(NR�RAtany(RRIRoRMthas_sectionRvRt
merge_sectionR�RcR;(RR((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestCommonFunction�s(R\R]RzR~R�R�R�R�R�R�R�R�R�R�R�R�RR�R�(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyRys 									
			2		%tFilterReaderTestcBsYeZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
RS(	c
Cs(ddddgdddddd	ggddd
dgdddd
dddgddddddgddddgg}tddi�}|jt�|j�|jd�|j|j�|�tddidd6dtdt�}|j�|jd�d|dd<|j|j�|�dS(NRDt
testcase01R�is	multi-setR�s�^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*(?:error: PAM: )?Authentication failure for .* from <HOST>\s*$s�^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*(?:error: PAM: )?User not known to the underlying authentication module for .* from <HOST>\s*$s^\s*(?:\S+ )?(?:kernel: \[\d+\.\d+\] )?(?:@vserver_\S+ )?(?:(?:\[\d+\])?:\s+[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?|[\[\(]?sshd(?:\(\S+\))?[\]\)]?:?(?:\[\d+\])?:)?\s*(?:error: PAM: )?User not known to the\nunderlying authentication.+$<SKIPLINES>^.+ module for .* from <HOST>\s*$taddignoreregexs"^.+ john from host 192.168.1.1\s*$R�s
_COMM=sshdt+s_SYSTEMD_UNIT=sshd.services_UID=0sFIELD= with spaces sAFIELD= with + char and spacestdatepatterns%Y %m %d %H:%M:%St5R�Riii����(	R	RatTEST_FILES_DIRR6R;R+RER�tTEST_FILES_DIR_SHARE_CFG(RtoutputtfilterReader((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyRHs.					




cCsttddidd6dd6dtdt�}|j�|jd�|j�}|j|dd�|jd�dS(	NR�s<test>R�tXRAR�Rs6Wrong int value 'X' for 'maxlines'. Using default one:(	R	R�R�R6R;R+RbtassertNotEqualR�(RR�RG((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestConvertOptions.s

cCsjddddgg}tddidtdt�}|j�|jd�|j�}|j||�dS(NRDtjailnameR�s to=sweet@example.com fromip=<IP>t
substitionR�R(R	R�R�R6R;R+R�RE(RR�R�R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt!testFilterReaderSubstitionDefault7s

cCs\tddidtdt�}|j�|jd�|j�}|jd|dk�dS(Nt
testcase02RR�RR�R�(R	R�R�R6R;R+RbR5(RR�RG((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestFilterReaderSubstKnown@s

cCsqddddgg}tddidd6dtd	t�}|j�|jd�|j�}|j||�dS(
NRDRR�sto=sour@example.com fromip=<IP>Rssour@example.comthoneypotR�R(R	R�R�R6R;R+R�RE(RR�R�R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestFilterReaderSubstitionSetKs

cCs|ddddgg}td�\}}tdd|dtdt�}|j�|jd�|j�}|j||�dS(	NRDRR�s?^to=test,sweet@example.com,test2,sweet@example.com fromip=<IP>$susubstition[failregex="^<known/failregex>$", honeypot="<sweet>,<known/honeypot>", sweet="test,<known/honeypot>,test2"]RR�R(	RR	R�R�R6R;R+R�RE(RR�t
filterNamet	filterOptR�R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestFilterReaderSubstitionKnownTs

cCs|ddddgg}td�\}}tdd|dtdt�}|j�|jd�|j�}|j||�dS(	NRDRR�s)^\s*to=fail2ban@localhost fromip=<IP>\s*$sUsubstition[failregex="^\s*<Definition/failregex>\s*$", honeypot="<default/honeypot>"]RR�R(	RR	R�R�R6R;R+R�RE(RR�R
RR�R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt!testFilterReaderSubstitionSection_s

cCs�tddidd6dtdt�}|j�|jd�|jttj|�tddidd6dd6dtdt�}|j�|jd�|jttj|�dS(	NRRs
<honeypot>RR�Rs<sweet>tsweet(	R	R�R�R6R;R+RvR�R�(RR�((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestFilterReaderSubstitionFailjs



cCs�tjjtjjtd��}ttjj|d�di�}|j|j�tjj|d�tjj|d�g�yA|jd�|j
dd�|j
dd�|j
dd�Wn$tk
r�}|jd	|�nXdS(
Nsfilter.dstestcase01.confR�stestcase-common.confR=t
__prefix_lineR�tignoreregexs)unexpected options after readexplicit: %s(
R#R$tabspathR'R�R	RItreadexplicitR;R+RcRwtfail(Rtpath_R�Rj((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestFilterReaderExplicitxs!!+
(R\R]RHRRRR	RR
RR(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR�s	,										tJailsReaderTestCachecBs/eZedd�Zd�Zed��ZRS(cCsZtd|d|�}|j|�|j�|j�|j�|j|jd��dS(NR�R�(R
Rat	readEarlytgetEarlyOptionstreadAllR5R;R+(RRR�R�tconfigurator((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt_readWholeConf�s



cCsMd}x@|j�jd�D])}tjd||�r|d7}qqW|S(Nis
s^\s*Reading files?: .*/i(tgetLogtrsplittretmatch(Rt	filematchtcntts((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt_getLoggedReadCount�s
cCs]tjj�tj}tjt_z*tj|�tj	t
|�tjt
d|d�tjt
d|d�t�}|j
|d|�|jd�}|j|dkd|�|j
|d	td|�|jd
�}|j|dkd|�|jd�}|j|dkd
|�|jd�}|j|dkd|�Wd|t_XdS(Ns
/jail.confs/jail.locals/fail2ban.confs/fail2ban.localR�s
jail.localis3Unexpected count by reading of jail files, cnt = %sR�sjail\.locals:Unexpected count by second reading of jail files, cnt = %ssfilter\.d/common\.confs5Unexpected count by reading of filter files, cnt = %ssaction\.d/iptables-common\.confs5Unexpected count by reading of action files, cnt = %s(ROR�t
SkipIfFastRtlogLeveltloggingtDEBUGRR tcopytreeRtcopyR�RR$R5RF(RRtsaved_llt	share_cfgR"((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestTestJailConfCache�s(
	
	N(R\R]tFalseR+RR$RR-(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR�s
	tJailsReaderTestcBs�eZd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
d��Zd	�Zd
�Z
e
d��ZRS(cOstt|�j||�dS(N(RR/Rz(RR{R|((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyRz�scCs;tjjd�s7tdd�}|jt|j�ndS(Ns/XXXR(R#R$R(R
RvR�R6(Rtreader((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestProvidingBadBasedir�scCs�tdtdt�}|j|j��|j|jdt��|jt	|j
�|j
dt�}d|_
|j|dddgdddgd	dd
ddd
ggddgdddgddd
dgdddgddd
dgddddgd	dddddgddgddgggdddgddd
dgddd
dgddddgddgddgddgddgdddgddgddgddgdd gdd!gg�|jd"�|jd#�|jd$�dS(%NRR�tignoreWrongtallow_no_filestaddR�tautostest-known-interps	multi-setR�s*failure test 1 (filter.d/test.conf) <HOST>s+failure test 2 (filter.d/test.local) <HOST>s"failure test 3 (jail.local) <HOST>tstarttmissinglogfilesRDs<IP>tbrokenactionR�R�R�shit with big stick <ip>R�R�sparse_to_end_of_jail.confR�R�sUTC+0200sconfig-errorsdJail 'brokenactiondef' skipped, because of wrong configuration: Invalid action definition 'joho[foo'sdJail 'brokenfilterdef' skipped, because of wrong configuration: Invalid filter definition 'flt[test'soJail 'missingaction' skipped, because of wrong configuration: Unable to read action 'noactionfileforthisaction'smJail 'missingbitsjail' skipped, because of wrong configuration: Unable to read the filter 'catchallthebadies's!Errors in jail 'missingbitsjail'.sSkipping...s6No file(s) found for glob /weapons/of/mass/destruction(R
R�R�R5R6RMR;R.RvR�R�RFR+tmaxDiffRER�tassertNotLogged(Rtjailst
comm_commands((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestReadTestJailConf�sX												


cCs�tjjdt�x�tjtjjtdd��D]n}tjj	|�j
dd�}t|didt�}|j|j
��y|ji�Wn6tk
r�}|jd|t|�j|f�nX|jd	�s5|jd
|j�dd|�|j|jjd
d�j�dd|�|jdtjtd�B�}|j|jd�ddd|�|dkr�|jd|jdd�dd|�q�q5q5WdS(NR�saction.ds*.confs.confR�R�Rsaction %r
%s: %ss-commonR=tmsgs.Action file %r is lacking [Definition] sectionR�s#Action file %r is lacking actionbantignorettimeouttbantimeR�s5Action file %r does not contains jail-name 'f2b-TEST'tpfsiptables-allportssiptables-multiportsf2b-TESTtactionstartsSAction file %r: interpolation of actionstart does not contains jail-name 'f2b-TEST'(stimeoutRA(spfsiptables-allportssiptables-multiport(ROR�R�RFtglobR#R$R'RtbasenameR�RR5R6R;RwRttypeR\R�tassertInRot_optsRctstripRbRt_escapedTagsRDRI(RtactionConfigt
actionNametactionReaderRjRG((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestReadStockActionConf�s*('!	c
Csftjjdt�tdtdt�}|j|j��|j|j	��|j
�}|j|g�t�}x�|j
�D]�}|dkr�q�n|j|d�}t|�\}}|j|�|jt|��t|||dtdt�}|j|j�d|�|j	i�|j|jjdd�j��|j|d	�}|jt|j���x�t|�D]�}	t|	�\}
}|jt|
��|jt|t��|
d
kr�|jd|�nt|
|idtdt�}|j|j��|j	i�|j
�}
|jt|
��|j|jjdd�j��q{Wq�WdS(
NR�RR�tINCLUDESR�sFailed to read filter:R�R�R�siptables-multiporttportR�(ROR�R�RFR
RR�R5R6R;R�RIRDRoRcRR4R�R	RHRIRt
isinstanceR�RGR(RR;R<t
allFiltersRtR
RR�tactionsR�tactNametactOptRMtcmds((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestReadStockJailConfsD	

"
cCs�tjjdt�tdtdtdt�}|j|j��|j|j	��t
d�tjtj
jddd��D��}t
d	�|jD��}d|_|j|j|�d
|j|��|j|j|�d|j|��dS(NR�RR�R�cssS|]I}|jd�p$|jd�stjjtjj|�d�dVqdS(scommon.confs-aggressive.confiiN(R�R#R$tsplitexttsplit(R�R>((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pys	<genexpr>_sRsfilter.ds*.confcss&|]}t|jd�dVqdS(R�iN(RR�(R�Rt((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pys	<genexpr>dss=More filters exists than are referenced in stock jail.conf %rs2Stock jail.conf references non-existent filters %r(ROR�R�RFR
RR�R5R6R;RDRDR#R$R'R;R+R9tissubsett
difference(RR;tfilterstfilters_jail((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestReadStockJailFilterCompleteYs	(	c

Cs�tjjdt�tdtdtdt�}|j|j��|j|j	��|j
dt�}|jt|��xc|D][}t|�dkr�|d|dgd	d
gkr�|jtj
|d�dk�q�q�WxfddgD]X}|jd
|gd�|D��|jd	|ddg|�|jd|g|�q�W|j|ddd�x�|jD]�}|j}|j�}|jt|�dd|�xN|D]F}|j
�}|j�}	dt|�kr�|jd|j�t}
|d|	g}x�|D]�}t|�dkrm|ddkrm|dd!|krmdg|dD]}|d^qQk}
nNt|�dkr�|dd	kr�|dd!|kr�|ddkr�t}
n|
rPqqW|j|
dd|t|�f�q�q�WqjWdS(NR�RR�R�R3iiiRDRAR�trecidiveR4css;|]1}t|�dkr|ddkr|d VqdS(iiR4iN(R�(R�R�((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pys	<genexpr>�sR�twarnR6i����R>sNo actions found for jail %ss<blocktype>t	blocktypeR�is	multi-setiisFound no %s command among %s(ROR�R�RFR
RR�R5R6R;R�R�Rtstr2secondsRGRIt_JailsReader__jailsR�R�tstrt	_initOptsR.(
RR;R<tcommandtjRSt	jail_nameR�tcommandstaction_nametblocktype_presentttarget_commandR�((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt!testReadStockJailConfForceEnabledlsP
2'	

"*"#	cs�tjjdt�t�}|jt�|j|j�t�|j	�|j
�}|j|dd�|j|dd�|j�|j�|j
�|j���fd�}|j|d�|d�ko�|d	�kn�|j|d
�|d�k�|j|d�|d�k�|j�d
ddgd
ddgd
d	dgd
ddgd
ddgd
d
dgg�|jjd�|j|jj�d�|j|j�t�dS(NR�tsockets/var/run/fail2ban/fail2ban.socktpidfiles/var/run/fail2ban/fail2ban.pidcs[x>t��D]0\}}|ddkr
|d|kr
|Sq
Wtd|�f��dS(NiRDis/Did not find command 'set %s' among commands %s(t	enumerateR�(R:RfRj(Ri(sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pytfind_set�s
 tsyslogsockettloglevelt	logtargett
dbpurgeagetdbfiletdbmaxmatchesRDR5tINFOs/var/log/fail2ban.logs"/var/lib/fail2ban/fail2ban.sqlite3i
t1ds/tmp(ROR�R�RFR
RaRRIt
getBaseDirRRRR;tconvertToProtocoltgetConfigStreamR5REt_Configurator__jails(RRRGRq((RisG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestStockConfigurator�s6	




/	cCs|tjtjj|d��tjtjj|d��ttjj|dd�d�j�ttjj|dd�d�j�ttjj|d�d�}|jd�|j�td|d	i�}|j|j	��|j|j
��|jd
t�}g|D])}|d dd
dgkr|d^q}|j
ttd�|D���d�|j
|ddd�dS(Nsfilter.dsaction.dstestaction1.confR"stestfilter1.confs	jail.confs�
[testjail1]
enabled = true
action = testaction1[actname=test1]
         testaction1[actname=test2]
         testaction.py
         testaction.py[actname=test3]
filter = testfilter1
RR�R3iRDt	testjail1R�css|]}|dVqdS(iN((R�R�((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pys	<genexpr>�sii����s{}(R#tmkdirR$R'R*R-R,R
R5R6R;R�RFRIR�RD(RRtjailfdR;R<tcommtadd_actions((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestMultipleSameAction�s %%

)&cCs |jtd|jdd�dS(Ns'Have not found any log file for .* jailtbackendtpolling(tassertRaisesRegexpR�t_testLogPath(R((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestLogPathFileFilterBackend�scCs]yddlm}Wn"tk
r8}tjd��nX|jdd�|jdd�dS(Ni(t
FilterSystemds&systemd python interface not availableR�tsystemdssystemd[journalflags=2](tserver.filtersystemdR�RwRORPR�(RR�Rj((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyttestLogPathSystemdBackendscCs�ttjj|d�d�}|jd||f�|j�td|�}|j|j��|j|j	��|j
�dS(Ns	jail.confR"s�
[testjail1]
enabled = true
backend = %s
logpath = %s/not/exist.log
          /this/path/should/not/exist.log
action = 
filter = 
failregex = test <HOST>
R(R*R#R$R'R,R-R
R5R6R;R�(RRR�R�R;((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR�s	
(R\R]RzR1R=RNRWR^RmR~RR�R�R�R�(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyR/�s			1		?		?	3		(6t
__author__t
__copyright__t__license__RDR'R#RRRROtclient.configreaderRRRRtclientRtclient.jailreaderRRRtclient.filterreaderR	tclient.jailsreaderR
tclient.actionreaderRRtclient.configuratorR
t
server.mytimeRRtutilsRRR$R'R&t__file__R�R�RR�R�R�R�R�tTestCaseRRyR�RR/(((sG/usr/lib/python2.7/site-packages/fail2ban/tests/clientreadertestcase.pyt<module>s<"!!���:

Zerion Mini Shell 1.0