U
    ÓZjË  ã                   @   s„   d Z ddlZddlZddlZddlmZ G dd„ dejƒZG dd„ dejƒZG dd	„ d	ejƒZ	G d
d„ dejƒZ
edkr€e ¡  dS )zTests for josepy.util.é    N)Ú	test_utilc                   @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )ÚComparableX509Testz%Tests for josepy.util.ComparableX509.c                 C   sL   t  d¡| _t  d¡| _t  d¡| _t  d¡| _t  d¡| _t  d¡| _d S )Nzcsr.pemzcsr-san.pemzcert.pemzcert-san.pem)	r   Zload_comparable_csrÚreq1Úreq2Ú	req_otherZload_comparable_certÚcert1Úcert2Ú
cert_other©Úself© r   úS/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/josepy/util_test.pyÚsetUp   s    zComparableX509Test.setUpc                 C   s   |   | j ¡ ¡ d S ©N)Ú
assertTruer   Zhas_expiredr
   r   r   r   Útest_getattr_proxy   s    z%ComparableX509Test.test_getattr_proxyc                 C   s$   |   | j| j¡ |   | j| j¡ d S r   )ÚassertEqualr   r   r   r   r
   r   r   r   Útest_eq   s    zComparableX509Test.test_eqc                 C   s$   |   | j| j¡ |   | j| j¡ d S r   )ÚassertNotEqualr   r   r   r	   r
   r   r   r   Útest_ne   s    zComparableX509Test.test_nec                 C   s    |   | jd¡ |   | jd¡ d S ©Né   )r   r   r   r
   r   r   r   Útest_ne_wrong_types"   s    z&ComparableX509Test.test_ne_wrong_typesc                 C   sd   |   t| jƒt| jƒ¡ |  t| jƒt| jƒ¡ |   t| jƒt| jƒ¡ |  t| jƒt| jƒ¡ d S r   )	r   Úhashr   r   r   r   r   r   r	   r
   r   r   r   Ú	test_hash&   s    zComparableX509Test.test_hashc                 C   s.   | j | jfD ]}|  t|ƒd |j¡¡ qd S )Nz<ComparableX509({0!r})>)r   r   r   ÚreprÚformatÚwrapped)r   Úx509r   r   r   Ú	test_repr-   s    

ÿzComparableX509Test.test_reprN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r   
   s   
r   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚComparableRSAKeyTestz'Tests for josepy.util.ComparableRSAKey.c                 C   s(   t  d¡| _t  d¡| _t  d¡| _d S )Nzrsa256_key.pemzrsa512_key.pem)r   Zload_rsa_private_keyÚkeyÚkey_sameÚkey2r
   r   r   r   r   6   s    zComparableRSAKeyTest.setUpc                 C   s   |   d| jj¡ d S )Né   )r   r%   Zkey_sizer
   r   r   r   r   <   s    z'ComparableRSAKeyTest.test_getattr_proxyc                 C   s   |   | j| j¡ d S r   )r   r%   r&   r
   r   r   r   r   ?   s    zComparableRSAKeyTest.test_eqc                 C   s   |   | j| j¡ d S r   )r   r%   r'   r
   r   r   r   r   B   s    zComparableRSAKeyTest.test_nec                 C   s   |   | jd¡ d S r   )r   r%   r
   r   r   r   Útest_ne_different_typesE   s    z,ComparableRSAKeyTest.test_ne_different_typesc                 C   s   |   | j| jj¡ d S r   )r   r%   r&   Z_wrappedr
   r   r   r   Útest_ne_not_wrappedH   s    z(ComparableRSAKeyTest.test_ne_not_wrappedc                 C   s$   ddl m} |  |dƒ|dƒ¡ d S )Nr   ©ÚComparableRSAKeyr   )Újosepy.utilr,   r   ©r   r,   r   r   r   Útest_ne_no_serializationL   s    z-ComparableRSAKeyTest.test_ne_no_serializationc                 C   sJ   |   tt| jƒtƒ¡ |  t| jƒt| jƒ¡ |  t| jƒt| jƒ¡ d S r   )	r   Ú
isinstancer   r%   Úintr   r&   r   r'   r
   r   r   r   r   P   s    zComparableRSAKeyTest.test_hashc                 C   s   |   t| jƒ d¡¡ d S )Nz'<ComparableRSAKey(<cryptography.hazmat.)r   r   r%   Ú
startswithr
   r   r   r   r   U   s    ÿzComparableRSAKeyTest.test_reprc                 C   s&   ddl m} |  t| j ¡ |ƒ¡ d S )Nr   r+   )r-   r,   r   r0   r%   Z
public_keyr.   r   r   r   Útest_public_keyY   s    z$ComparableRSAKeyTest.test_public_keyN)r    r!   r"   r#   r   r   r   r   r)   r*   r/   r   r   r3   r   r   r   r   r$   3   s   r$   c                   @   sp   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚImmutableMapTestz#Tests for josepy.util.ImmutableMap.c                 C   s|   ddl m} G dd„ d|ƒ}G dd„ d|ƒ}|| _|| _| jddd	�| _| jddd
�| _| jddd	�| _| jddd	�| _d S )Nr   )ÚImmutableMapc                   @   s   e Zd ZdZdS )z!ImmutableMapTest.setUp.<locals>.A©ÚxÚyN©r    r!   r"   Ú	__slots__r   r   r   r   ÚAf   s   r;   c                   @   s   e Zd ZdZdS )z!ImmutableMapTest.setUp.<locals>.Br6   Nr9   r   r   r   r   ÚBi   s   r<   é   é   r6   )r8   r7   é   é   )r-   r5   r;   r<   Úa1Úa1_swapÚa2Úb)r   r5   r;   r<   r   r   r   r   a   s    zImmutableMapTest.setUpc                 C   s>   |   | jddd�| jjdd�¡ |   | j| jjddd�¡ d S )Nr>   r6   ©r7   r?   r@   )r   r;   rA   ÚupdaterC   r
   r   r   r   Útest_updatet   s     zImmutableMapTest.test_updatec                 C   s   |   t| jjd¡ d S ©NÚz)ÚassertRaisesÚKeyErrorrA   Ú__getitem__r
   r   r   r   Ú&test_get_missing_item_raises_key_errorx   s    z7ImmutableMapTest.test_get_missing_item_raises_key_errorc                 C   s   |   | j| j¡ d S r   )r   rA   rB   r
   r   r   r   Ú"test_order_of_args_does_not_matter{   s    z3ImmutableMapTest.test_order_of_args_does_not_matterc                 C   s(   | j t| jdd� | j t| jdd� d S )Nr=   rE   r>   )r8   ©rJ   Ú	TypeErrorr;   r
   r   r   r   Útest_type_error_on_missing~   s    z+ImmutableMapTest.test_type_error_on_missingc                 C   s.   | j t| jddd� | j t| jdddd� d S )Nr=   r>   )r7   rI   r?   )r7   r8   rI   rO   r
   r   r   r   Útest_type_error_on_unrecognized‚   s    z0ImmutableMapTest.test_type_error_on_unrecognizedc                 C   sD   |   d| jj¡ |   d| jj¡ |   d| jj¡ |   d| jj¡ d S )Nr=   r>   )r   rA   r7   r8   rB   r
   r   r   r   Útest_get_attr†   s    zImmutableMapTest.test_get_attrc                 C   s   |   tt | jjd¡d¡ d S )Nr7   é
   )rJ   ÚAttributeErrorÚ	functoolsÚpartialrA   Ú__setattr__r
   r   r   r   Ú$test_set_attr_raises_attribute_errorŒ   s
      ÿz5ImmutableMapTest.test_set_attr_raises_attribute_errorc                 C   s4   |   | j| j¡ |   | j| j¡ |  | j| j¡ d S r   )r   rA   rC   r   r
   r   r   r   Ú
test_equal�   s    zImmutableMapTest.test_equalc                 C   s   |   tdƒt| jƒ¡ d S )N)r=   r>   )r   r   rA   r
   r   r   r   r   •   s    zImmutableMapTest.test_hashc                 C   s   |   t| jdi d�j¡ d S )Nr=   r6   )rJ   rP   r;   Ú__hash__r
   r   r   r   Útest_unhashable˜   s    z ImmutableMapTest.test_unhashablec                 C   sT   |   dt| jƒ¡ |   dt| jƒ¡ |   dt| jƒ¡ |   dt| jddd�ƒ¡ d S )NzA(x=1, y=2)zB(x=1, y=2)zB(x='foo', y='bar')ZfooÚbarr6   )r   r   rA   rB   rD   r<   r
   r   r   r   r   ›   s    zImmutableMapTest.test_reprN)r    r!   r"   r#   r   rG   rM   rN   rQ   rR   rS   rY   rZ   r   r\   r   r   r   r   r   r4   ^   s   r4   c                   @   sX   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ ZdS )ÚfrozendictTestz!Tests for josepy.util.frozendict.c                 C   s   ddl m} |ddd�| _d S ©Nr   ©Ú
frozendictr=   Ú2r6   )r-   ra   Úfdict©r   ra   r   r   r   r   ¥   s    zfrozendictTest.setUpc                 C   s(   ddl m} |  | j|dddœƒ¡ d S r_   )r-   ra   r   rc   rd   r   r   r   Útest_init_dict©   s    zfrozendictTest.test_init_dictc                 C   s(   ddl m} |  t|t ddi¡¡ d S )Nr   r`   ÚarD   )r-   ra   rJ   rP   ÚsixÚ	iteritemsrd   r   r   r   Ú!test_init_other_raises_type_error­   s    z0frozendictTest.test_init_other_raises_type_errorc                 C   s   |   dt| jƒ¡ d S )Nr>   )r   Úlenrc   r
   r   r   r   Útest_len²   s    zfrozendictTest.test_lenc                 C   s   |   tt| jƒtƒ¡ d S r   )r   r0   r   rc   r1   r
   r   r   r   r   µ   s    zfrozendictTest.test_hashc                 C   s$   |   d| jj¡ |   d| jj¡ d S )Nr=   rb   )r   rc   r7   r8   r
   r   r   r   r   ¸   s    z!frozendictTest.test_getattr_proxyc                 C   s   |   t| jjd¡ d S rH   )rJ   rU   rc   Ú__getattr__r
   r   r   r   Ú#test_getattr_raises_attribute_error¼   s    z2frozendictTest.test_getattr_raises_attribute_errorc                 C   s   |   t| jjdd¡ d S )NrI   r?   )rJ   rU   rc   rX   r
   r   r   r   Útest_setattr_immutable¿   s    z%frozendictTest.test_setattr_immutablec                 C   s   |   dt| jƒ¡ d S )Nzfrozendict(x=1, y='2'))r   r   rc   r
   r   r   r   r   Â   s    zfrozendictTest.test_reprN)r    r!   r"   r#   r   re   ri   rk   r   r   rm   rn   r   r   r   r   r   r^   ¢   s   r^   Ú__main__)r#   rV   Zunittestrg   Zjosepyr   ZTestCaser   r$   r4   r^   r    Úmainr   r   r   r   Ú<module>   s   )+D$