AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3/dist-packages/twisted/cred/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /usr/lib/python3/dist-packages/twisted/cred/test/__pycache__/test_strcred.cpython-310.pyc
o

�be�@s6dZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZddl
mZmZmZmZdd	lmZmZmZdd
lmZddlmZddlmZdd
lmZddlmZed�Z ed�Z!ed�Z"dd�Z#Gdd�de�Z$Gdd�de�Z%Gdd�de�Z&Gdd�de�Z'ee!d�ee d�ee"d�Gdd �d e����Z(ee d!�Gd"d#�d#e��Z)Gd$d%�d%e�Z*eed&�d'�eed(�d)�Gd*d+�d+e���Z+Gd,d-�d-ej,ej-�Z.Gd.d/�d/e�Z/Gd0d1�d1ej,ej-�Z0Gd2d3�d3ej,ej-�Z1Gd4d5�d5ej,ej-�Z2Gd6d7�d7ej,ej-�Z3Gd8d9�d9e�Z4dS):z
L{twisted.cred.strcred}.
�N)�StringIO)�Sequence�Type)�skipIf)�	Interface)�plugin)�checkers�credentials�error�strcred)�cred_anonymous�	cred_file�	cred_unix)�usage)�UserDatabase)�FilePath)�
requireModule)�TestCase�crypt�pwd�spwdcCs<d}|dd�t��D�vr|d7}|dd�t��D�vs
|S)zC
    Helper method to produce an auth type that doesn't exist.
    �ThisPluginDoesNotExistcSsg|]}|j�qS�)�authType)�.0�factoryrr�@/usr/lib/python3/dist-packages/twisted/cred/test/test_strcred.py�
<listcomp>#s�z&getInvalidAuthType.<locals>.<listcomp>�_)r�findCheckerFactories)�invalidAuthTyperrr�getInvalidAuthTypes���r!c@�eZdZdd�Zdd�ZdS)�PublicAPITestscC�.t�}|�tjtj|�|�tjtj|�dS)z9
        The description string cannot be empty.
        N�r!�assertRaisesr�InvalidAuthType�makeChecker�findCheckerFactory��self�iatrrr�test_emptyDescription+�z$PublicAPITests.test_emptyDescriptioncCr$)z@
        An unrecognized auth type raises an exception.
        Nr%r*rrr�test_invalidAuthType3r.z#PublicAPITests.test_invalidAuthTypeN)�__name__�
__module__�__qualname__r-r/rrrrr#*�r#c@r")�StrcredFunctionsTestscCs.tt���}t�tj�D]}|�||�qdS)zP
        L{strcred.findCheckerFactories} returns all available plugins.
        N)�listrrr�
getPlugins�ICheckerFactory�assertIn)r+�availablePlugins�plgrrr�test_findCheckerFactories=s�z/StrcredFunctionsTests.test_findCheckerFactoriescCs|�t�d�tj�dS)z{
        L{strcred.findCheckerFactory} returns the first plugin
        available for a given authentication type.
        �fileN)�assertIdenticalrr)r
�theFileCheckerFactory�r+rrr�test_findCheckerFactoryEs�z-StrcredFunctionsTests.test_findCheckerFactoryN)r0r1r2r;r@rrrrr4<r3r4c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�MemoryCheckerTestscCsHt�dd�|_t�dd�|_t�dd�|_t�dd�|_t�d�|_dS)	N�admin�asdf�alice�foo�foobar�x�yzzmemory:admin:asdf:alice:foo)	r	�UsernamePasswordrBrD�badPass�badUserrr(�checkerr?rrr�setUpPs
zMemoryCheckerTests.setUpcC�*|�tj�|j��|�tj|jj�dS�z�
        Verifies that strcred.makeChecker('memory') returns an object
        that implements the L{ICredentialsChecker} interface.
        N�	�
assertTruer�ICredentialsChecker�
providedByrLr8r	�IUsernamePassword�credentialInterfacesr?rrr�test_isCheckerW�z!MemoryCheckerTests.test_isCheckercCs|�tjtjd�dS)z�
        An argument string which does not contain user:pass pairs
        (i.e., an odd number of ':' characters) raises an exception.
        zmemory:a:b:cN)r&r�InvalidAuthArgumentStringr(r?rrr�test_badFormatArgString_s
�z*MemoryCheckerTests.test_badFormatArgStringc� �fdd�}�j��j��|�S)�;
        The checker works with valid credentials.
        c���|�jj�dS�N��assertEqualrB�username�r`r?rr�
_gotAvatarm�zAMemoryCheckerTests.test_memoryCheckerSucceeds.<locals>._gotAvatar�rL�requestAvatarIdrB�addCallback�r+rbrr?r�test_memoryCheckerSucceedsh�z-MemoryCheckerTests.test_memoryCheckerSucceedscC�|�|j�|j�tj�S�z=
        The checker fails with an invalid username.
        ��
assertFailurerLrerKr
�UnauthorizedLoginr?rrr�test_memoryCheckerFailsUsernamer��z2MemoryCheckerTests.test_memoryCheckerFailsUsernamecCrj�z=
        The checker fails with an invalid password.
        �rmrLrerJr
rnr?rrr�test_memoryCheckerFailsPasswordzrpz2MemoryCheckerTests.test_memoryCheckerFailsPasswordN)	r0r1r2rMrVrYrhrorsrrrrrAOs	
rAc@r")�AnonymousCheckerTestscC�0t�d�}|�tj�|��|�tj|j	�dS)z�
        Verifies that strcred.makeChecker('anonymous') returns an object
        that implements the L{ICredentialsChecker} interface.
        �	anonymousN)
rr(rQrrRrSr8r	�
IAnonymousrU)r+rLrrrrV��
z$AnonymousCheckerTests.test_isCheckercs.t�d�}|�t���}�fdd�}|�|�S)z?
        We can log in anonymously using this checker.
        rvcs��tj|�dSr])r=r�	ANONYMOUS)�avatarr?rrrb�szEAnonymousCheckerTests.testAnonymousAccessSucceeds.<locals>._gotAvatar)rr(rer	�	Anonymousrf)r+rL�requestrbrr?r�testAnonymousAccessSucceeds�s

z1AnonymousCheckerTests.testAnonymousAccessSucceedsN)r0r1r2rVr}rrrrrt�s	rtz"Required module not available: pwdz$Required module not available: cryptz#Required module not available: spwdc@s^eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�UnixCheckerTestsrCrE)rBrDcCs*t�|t�|j|d�dddddddf	�S)N�F/ri������)r�struct_spwdr�users)r+r`rrr�_spwd_getspnam�s��zUnixCheckerTests._spwd_getspnamc
Cs�t�dd�|_t�dd�|_t�dd�|_t�dd�|_t�d�|_t�d	d
�|_	t�dd�|_
t�dd
�|_t�dd�|_t�d�|_
trlt�}|j��D]\}}|�|t�|d�dd|d|d�qN|�td|j�trx|�td|j�dSdS)NrBrCrDrErFrGrH�unix�admin�asdf�alice�foo�foobar�x�yzri�z/home/z/bin/sh�getpwnam�getspnam)r	rIrBrDrJrKrr(rL�
adminBytes�
aliceBytes�badPassBytes�badUserBytes�checkerBytesrrr��items�addUserr�patchr�rr�)r+�databaser`�passwordrrrrM�s4
�	�zUnixCheckerTests.setUpcCsP|�tj�|j��|�tj|jj�|�tj�|j	��|�tj|j	j�dS)z�
        Verifies that strcred.makeChecker('unix') returns an object
        that implements the L{ICredentialsChecker} interface.
        N)
rQrrRrSrLr8r	rTrUr�r?rrrrV�s
�zUnixCheckerTests.test_isCheckercrZ)r[cr\r]r^rar?rrrb�rcz=UnixCheckerTests.test_unixCheckerSucceeds.<locals>._gotAvatarrdrgrr?r�test_unixCheckerSucceeds�riz)UnixCheckerTests.test_unixCheckerSucceedscrZ)zD
        The checker works with valid L{bytes} credentials.
        cs��|�jj�d��dS)N�utf-8)r_r�r`�decoderar?rrrb�szBUnixCheckerTests.test_unixCheckerSucceedsBytes.<locals>._gotAvatar)r�rer�rfrgrr?r�test_unixCheckerSucceedsBytes�s�z.UnixCheckerTests.test_unixCheckerSucceedsBytescCrjrkrlr?rrr�test_unixCheckerFailsUsername�rpz.UnixCheckerTests.test_unixCheckerFailsUsernamecCrj)zF
        The checker fails with an invalid L{bytes} username.
        )rmr�rer�r
rnr?rrr�"test_unixCheckerFailsUsernameBytes���z3UnixCheckerTests.test_unixCheckerFailsUsernameBytescCrjrqrrr?rrr�test_unixCheckerFailsPasswordrpz.UnixCheckerTests.test_unixCheckerFailsPasswordcCrj)zF
        The checker fails with an invalid L{bytes} password.
        )rmr�rer�r
rnr?rrr�"test_unixCheckerFailsPasswordBytesr�z3UnixCheckerTests.test_unixCheckerFailsPasswordBytesN)
r0r1r2r�r�rMrVr�r�r�r�r�r�rrrrr~�s�
	r~z%Required module is unavailable: cryptc@s eZdZdZdd�Zdd�ZdS)�
CryptTestsz9
    L{crypt} has functions for encrypting password.
    c
	Cs*d}dD]2}zt�||�}t|t�r|�d�}Wn	ty!Yqwd}|�t�||��|�t�||��qdD]Y}t	t|d�}|sDq9d}t�||�}t|t�rV|�d�}|d}t�||�}	|�|	�t�|�
d�|�
d��}	|�|	�t�||�}	|�|	�t�|�
d�|�
d��}	|�|	�q9dS)	z4
        L{cred_unix.verifyCryptedPassword}
        �sample password ^%$)N�abr�z$1x1234)�
METHOD_SHA512�
METHOD_SHA256�
METHOD_MD5�METHOD_CRYPTNzinteresting password xyz�blahfooincorrect)r�
isinstance�bytesr��	TypeErrorrQr�verifyCryptedPassword�assertFalse�getattr�encode)
r+r��salt�cryptedCorrect�cryptedIncorrect�method�cryptMethod�crypted�incorrectCrypted�resultrrr�test_verifyCryptedPasswordsJ

��
�


�

��z%CryptTests.test_verifyCryptedPasswordcCs<dd�}d}t�|d�}|�td|�|�t�||��dS)zK
        L{cred_unix.verifyCryptedPassword} when OSError is raised
        cSstd��)N�)�OSError)r�r�rrr�	mockCryptQsz?CryptTests.test_verifyCryptedPasswordOSError.<locals>.mockCryptr�r�rN)rr�r�rr�)r+r�r�r�rrr�!test_verifyCryptedPasswordOSErrorLs
z,CryptTests.test_verifyCryptedPasswordOSErrorN)r0r1r2�__doc__r�r�rrrrr�s0r�c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�FileDBCheckerTestsz*
    C{--auth=file:...} file checker.
    cCsht�dd�|_t�dd�|_t�dd�|_t�dd�|_|��|_t|j��	d�t
�d	|j�|_dS)
Nr�r�r�r�r�r�r��admin:asdf
alice:foo
�file:)
r	rIrBrDrJrK�mktemp�filenamer�
setContentrr(rLr?rrrrM_s
zFileDBCheckerTests.setUpcCs(d}tj�|�r|d7}tj�|�s|S)Nz
/DoesNotExistr)�os�path�exists)r+r�rrr�
_fakeFilenamehs
�z FileDBCheckerTests._fakeFilenamecCrNrOrPr?rrrrVnrWz!FileDBCheckerTests.test_isCheckercrZ)r[cr\r]r^rar?rrrb{rcz?FileDBCheckerTests.test_fileCheckerSucceeds.<locals>._gotAvatarrdrgrr?r�test_fileCheckerSucceedsvriz+FileDBCheckerTests.test_fileCheckerSucceedscCrjrkrlr?rrr�test_fileCheckerFailsUsername�rpz0FileDBCheckerTests.test_fileCheckerFailsUsernamecCrjrqrrr?rrr�test_fileCheckerFailsPassword�rpz0FileDBCheckerTests.test_fileCheckerFailsPasswordcCs$|�ttjd�|�ttjd�dS)z4
        An empty filename raises an error.
        r<r�N)r&�
ValueErrorrr(r?rrr�test_failsWithEmptyFilename�sz.FileDBCheckerTests.test_failsWithEmptyFilenamecCsFtjj}t�}|tj_t�d|���|tj_|�tj|�	��dS)zt
        When the file auth plugin is given a file that doesn't exist, it
        should produce a warning.
        r�N)
r
r>�errorOutputrrr(r�r8�invalidFileWarning�getvalue)r+�	oldOutput�	newOutputrrr�test_warnWithBadFilename�sz+FileDBCheckerTests.test_warnWithBadFilenameN)r0r1r2r�rMr�rVr�r�r�r�r�rrrrr�Zs	
r��cryptographyzcryptography is not available�pyasn1zpyasn1 is not availablec@seZdZdZdd�ZdS)�SSHCheckerTestsz�
    Tests for the C{--auth=sshkey:...} checker.  The majority of the
    tests for the ssh public key database checker are in
    L{twisted.conch.test.test_checkers.SSHPublicKeyCheckerTestCase}.
    cCru)z�
        Verifies that strcred.makeChecker('sshkey') returns an object
        that implements the L{ICredentialsChecker} interface.
        �sshkeyN)
rr(rQrrRrSr8r	�ISSHPrivateKeyrU)r+�
sshCheckerrrrrV�rxzSSHCheckerTests.test_isCheckerN)r0r1r2r�rVrrrrr��sr�c@seZdZdZdS)�DummyOptionsz@
    Simple options for testing L{strcred.AuthOptionMixin}.
    N)r0r1r2r�rrrrr���r�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�CheckerOptionsTestscCsTt�}|�ddg�|�t|d�d�t�}|�gd��|�t|d�d�dS)zu
        The C{--auth} command line creates a list in the
        Options instance and appends values to it.
        �--auth�memory�credCheckers�)r�r�r�r��N)r��parseOptionsr_�len�r+�optionsrrr�test_createsList�sz$CheckerOptionsTests.test_createsListcCs<t�}t�}|�tj|jd|g�|�tj|jd|g�dS)zx
        The C{--auth} command line raises an exception when it
        gets a parameter it doesn't understand.
        r��--help-auth-typeN)r�r!r&r�
UsageErrorr�)r+r��invalidParameterrrr�test_invalidAuthError�s��z)CheckerOptionsTests.test_invalidAuthErrorcCs�t�}|�gd��|d}|�t|tj�d�|�t|tj�d�|tjd}|tjd}|�tj	�
|��|�tj	�
|��|�tj|j�|�tj|j�dS)z�
        The C{--auth} command line creates a dictionary mapping supported
        interfaces to the list of credentials checkers that support it.
        )r�r�r�rv�credInterfacesr�rN)
r�r�r_r�r	rwrTrQrrRrSr8rU)r+r��chd�chdAnonymous�chdUserPassrrr�test_createsDictionary�sz*CheckerOptionsTests.test_createsDictionarycCs2t�}|�gd��|�|d|dtj�dS)z�
        When two C{--auth} arguments are passed along which support the same
        interface, a list with both is created.
        )r�r�r�r�r�r�N)r�r�r_r	rTr�rrr� test_credInterfacesProvidesLists�s�z4CheckerOptionsTests.test_credInterfacesProvidesListscCs6g}t�}|��D]}|�|j|�|�|j�q	dS)zG
        The list for C{--help-auth} does not duplicate items.
        N)r��_checkerFactoriesForOptHelpAuth�assertNotInr�append)r+�	authTypesr��cfrrr�!test_listDoesNotDisplayDuplicates�s�z5CheckerOptionsTests.test_listDoesNotDisplayDuplicatescCsHt�}t�}||_|�t|jdg�t��D]}|�|j	|�
��qdS)zz
        The C{--help-auth} argument correctly displays all
        available authentication plugins, then exits.
        z--help-authN)rr��
authOutputr&�
SystemExitr�rrr8rr�)r+�	newStdoutr��checkerFactoryrrr�test_displaysListCorrectlys�z.CheckerOptionsTests.test_displaysListCorrectlycCsTt�}t�}||_|�t|jddg�tjjD]}|�	�r'|�
|�	�|���qdS)z�
        The C{--help-auth-for} argument will correctly display the help file
        for a particular authentication plugin.
        r�r<N)rr�r�r&r�r�r
r>�authHelp�stripr8r�)r+r�r��linerrr�test_displaysHelpCorrectlys���z.CheckerOptionsTests.test_displaysHelpCorrectlycCs0t�}|�tj|jddg�}|�t|�d�dS)z�
        When the checker specified by C{--auth} raises an unexpected error, it
        should be caught and re-raised within a L{usage.UsageError}.
        r�r<z,Unexpected error: 'file' requires a filenameN)r�r&rr�r�r_�str)r+r��errrrr�test_unexpectedExceptions
�z,CheckerOptionsTests.test_unexpectedExceptionN)r0r1r2r�r�r�r�r�r�r�rrrrrr��s
r�c@�eZdZejfZdS)�OptionsForUsernamePasswordN)r0r1r2r	rT�supportedInterfacesrrrrr*�rc@r)� OptionsForUsernameHashedPasswordN)r0r1r2r	�IUsernameHashedPasswordrrrrrr.rrc@seZdZdZdS)�OptionsSupportsAllInterfacesN)r0r1r2rrrrrr	2r�r	c@s"eZdZUgZeeeed<dS)�OptionsSupportsNoInterfacesrN)r0r1r2rrrr�__annotations__rrrrr
6s
r
c@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�LimitingInterfacesTestsa�
    Tests functionality that allows an application to limit the
    credential interfaces it can support. For the purposes of this
    test, we use IUsernameHashedPassword, although this will never
    really be used by the command line.

    (I have, to date, not thought of a half-decent way for a user to
    specify a hash algorithm via the command-line. Nor do I think it's
    very useful.)

    I should note that, at first, this test is counter-intuitive,
    because we're using the checker with a pre-defined hash function
    as the 'bad' checker. See the documentation for
    L{twisted.cred.checkers.FilePasswordDB.hash} for more details.
    cCsp|��|_t|jd��
}|�d�Wd�n1swYt�|j�|_tj|j|jd�|_t�	�|_
dS)N�wbr�)�hash)r�r��open�writer�FilePasswordDB�goodChecker�_hash�
badChecker�AllowAnonymousAccess�anonChecker)r+�frrrrMKs
�zLimitingInterfacesTests.setUpcCs|S)z>
        A dumb hash that doesn't really do anything.
        r)r+�networkUsername�networkPassword�storedPasswordrrrrSszLimitingInterfacesTests._hashcCsBt�}|�|�tj��|�|�tj��|�tj	|j
|j�dS)zE
        The supportsInterface method behaves appropriately.
        N)rrQ�supportsInterfacer	rTr�rwr&r�UnsupportedInterfaces�
addCheckerrr�rrr�test_supportsInterfaceYs�z.LimitingInterfacesTests.test_supportsInterfacecCs.t�}|�|�tj��|�|�tj��dS)z|
        The supportsInterface method behaves appropriately
        when the supportedInterfaces attribute is None.
        N)r	rQrr	rTrwr�rrr�test_supportsAllInterfacesdsz2LimitingInterfacesTests.test_supportsAllInterfacescCs6t�}tj}tj}|�|�|��|�|�|��dS)zJ
        The supportsCheckerFactory method behaves appropriately.
        N)rr
r>r�theAnonymousCheckerFactoryrQ�supportsCheckerFactoryr�)r+r��fileCF�anonCFrrr�test_supportsCheckerFactoryms
z3LimitingInterfacesTests.test_supportsCheckerFactorycCs|t�}|�|j�|jd}|�|d|d|j�|�|dd|j�|�t|d|�d�|�t|d�d�dS)z�
        When addChecker is called with a checker that implements at least one
        of the interfaces our application supports, it is successful.
        rr�r�r�N)rrrrr=r_r�)r+r��ifacerrr�test_canAddSupportedCheckerws
z3LimitingInterfacesTests.test_canAddSupportedCheckercCst�}|�tj|j|j�dS)z~
        When addChecker is called with a checker that does not implement any
        supported interfaces, it fails.
        N)rr&rrrrr�rrr�#test_failOnAddingUnsupportedChecker�s�z;LimitingInterfacesTests.test_failOnAddingUnsupportedCheckercCs(t�}tjj}|�tj|jd|g�dS)zq
        The C{--auth} command line raises an exception when it
        gets a checker we don't support.
        r�N)r
rr rr&rr�r�)r+r�rrrr�test_unsupportedInterfaceError�sz6LimitingInterfacesTests.test_unsupportedInterfaceErrorcCsBt�}|��D]}d}|jD]	}|�|�rd}q|rt���qdS)z�
        C{--help-auth} will only list checkers that purport to
        supply at least one of the credential interfaces our
        application can use.
        TFN)rr�rUrrr)r+r�r�invalid�	interfacerrr�test_helpAuthLimitsOutput�s

���z1LimitingInterfacesTests.test_helpAuthLimitsOutputcCslt�}d}t��D]}|�|�s|}nq	|�|d�t�}||_|�t|j	ddg�|�
tj|���dS)z�
        C{--help-auth-type} will display a warning if you get
        help for an authType that does not supply at least one of the
        credential interfaces our application can use.
        Nr�rv)
rrrr!�assertNotIdenticalrr�r&r�r�r8�notSupportedWarningr�)r+r��invalidFactoryrr�rrr�test_helpAuthTypeLimitsOutput�s
��z5LimitingInterfacesTests.test_helpAuthTypeLimitsOutputN)r0r1r2r�rMrrrr$r&r'r(r+r/rrrrr:s	

	r)5r�r��ior�typingrr�unittestr�zope.interfacer�twistedr�twisted.credrr	r
r�twisted.pluginsrr
r�twisted.pythonr�twisted.python.fakepwdr�twisted.python.filepathr�twisted.python.reflectr�twisted.trial.unittestrrrrr!r#r4rArtr~r�r�r��Options�AuthOptionMixinr�r�rrr	r
rrrrr�<module>sN4



yCJm

Anon7 - 2022
AnonSec Team