ó
O'—^c           @  sé   d  d l  m Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d d l
 m Z m Z d d l m Z m Z m Z d d	 l m Z d
 d l m Z e ƒ  Z e ƒ  Z d e e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   unicode_literalsN(   t   TestCaset   RequestFactory(   t   reverse(   t   timezonei   (   t	   urlencodet   get_user_model(   t   get_application_modelt   AccessTokent   RefreshToken(   t   oauth2_settingsi   (   t   TestCaseUtilst   BaseTestc           B  s   e  Z d  „  Z d „  Z RS(   c         C  s•   t  ƒ  |  _ t j j d d d ƒ |  _ t j j d d d ƒ |  _ t d d d d	 d
 |  j d t j d t j	 ƒ |  _
 |  j
 j ƒ  d d g t _ d  S(   Nu	   test_useru   test@user.comu   123456u   dev_useru   dev@user.comt   nameu   Test Applicationt   redirect_urisu5   http://localhost http://example.com http://example.itt   usert   client_typet   authorization_grant_typeu   readu   write(   R   t   factoryt	   UserModelt   objectst   create_usert	   test_usert   dev_usert   Applicationt   CLIENT_CONFIDENTIALt   GRANT_AUTHORIZATION_CODEt   applicationt   saveR
   t   _SCOPES(   t   self(    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   setUp   s    		c         C  s+   |  j  j ƒ  |  j j ƒ  |  j j ƒ  d  S(   N(   R   t   deleteR   R   (   R   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   tearDown%   s    (   t   __name__t
   __module__R   R!   (    (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyR      s   	t   TestRevocationViewc           B  s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C  sø   t  j j d |  j d d d |  j d t j ƒ  t j d d ƒ d d	 ƒ } t	 i |  j j
 d
 6|  j j d 6| j d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ |  j | j d ƒ |  j t  j j d | j ƒ j ƒ  ƒ d S(   u
   

        R   t   tokenu
   1234567890R   t   expirest   daysi   t   scopeu
   read writeu	   client_idu   client_secretu   tokenu
   {url}?{qs}t   urlu   oauth2_provider:revoke-tokent   qsiÈ   t    t   idN(   R   R   t   createR   R   R   t   nowt   datetimet	   timedeltaR   t	   client_idt   client_secretR%   t   formatR   t   clientt   postt   assertEqualt   status_codet   contentt   assertFalset   filterR,   t   exists(   R   t   tokt   query_stringR)   t   response(    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   test_revoke_access_token,   s    		c         C  sç   t  d d d d d |  j d t  j d t  j ƒ } | j ƒ  t j j d |  j d d	 d
 | d t	 j
 ƒ  t j d d ƒ d d ƒ } t i | j d 6| j d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ d  S(   NR   u   Test ApplicationR   u5   http://localhost http://example.com http://example.itR   R   R   R%   u
   1234567890R   R&   R'   i   R(   u
   read writeu	   client_idu   tokenu
   {url}?{qs}R)   u   oauth2_provider:revoke-tokenR*   iÈ   (   R   R   t   CLIENT_PUBLICR   R   R   R   R-   R   R   R.   R/   R0   R   R1   R%   R3   R   R4   R5   R6   R7   (   R   t
   public_appR<   R=   R)   R>   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   test_revoke_access_token_public?   s"    		
	
c         C  sì   t  j j d |  j d d d |  j d t j ƒ  t j d d ƒ d d	 ƒ } t	 i |  j j
 d
 6|  j j d 6| j d 6d d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ |  j t  j j d | j ƒ j ƒ  ƒ d S(   u
   

        R   R%   u
   1234567890R   R&   R'   i   R(   u
   read writeu	   client_idu   client_secretu   tokenu   access_tokenu   token_type_hintu
   {url}?{qs}R)   u   oauth2_provider:revoke-tokenR*   iÈ   R,   N(   R   R   R-   R   R   R   R.   R/   R0   R   R1   R2   R%   R3   R   R4   R5   R6   R7   R9   R:   R,   R;   (   R   R<   R=   R)   R>   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt"   test_revoke_access_token_with_hintW   s    		
c         C  sì   t  j j d |  j d d d |  j d t j ƒ  t j d d ƒ d d	 ƒ } t	 i |  j j
 d
 6|  j j d 6| j d 6d d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ |  j t  j j d | j ƒ j ƒ  ƒ d S(   u
   

        R   R%   u
   1234567890R   R&   R'   i   R(   u
   read writeu	   client_idu   client_secretu   tokenu   bad_hintu   token_type_hintu
   {url}?{qs}R)   u   oauth2_provider:revoke-tokenR*   iÈ   R,   N(   R   R   R-   R   R   R   R.   R/   R0   R   R1   R2   R%   R3   R   R4   R5   R6   R7   R9   R:   R,   R;   (   R   R<   R=   R)   R>   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt*   test_revoke_access_token_with_invalid_hintj   s    		
c         C  s:  t  j j d |  j d d d |  j d t j ƒ  t j d d ƒ d d	 ƒ } t	 j j d |  j d d
 d |  j d | ƒ } t
 i |  j j d 6|  j j d 6| j d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ |  j t	 j j d | j ƒ j ƒ  ƒ |  j t  j j d | j j ƒ j ƒ  ƒ d S(   u
   

        R   R%   u
   1234567890R   R&   R'   i   R(   u
   read writeu	   999999999t   access_tokenu	   client_idu   client_secretu   tokenu
   {url}?{qs}R)   u   oauth2_provider:revoke-tokenR*   iÈ   R,   N(   R   R   R-   R   R   R   R.   R/   R0   R	   R   R1   R2   R%   R3   R   R4   R5   R6   R7   R9   R:   R,   R;   RE   (   R   R<   t   rtokR=   R)   R>   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   test_revoke_refresh_token~   s    		%c         C  sì   t  j j d |  j d d d |  j d t j ƒ  t j d d ƒ d d	 ƒ } t	 i |  j j
 d
 6|  j j d 6| j d 6d d 6ƒ } d j d t d ƒ d | ƒ } |  j j | ƒ } |  j | j d ƒ |  j t  j j d | j ƒ j ƒ  ƒ d S(   u7  
        From the revocation rfc, `Section 4.1.2`_ :

        If the server is unable to locate the token using the given hint,
        it MUST extend its search across all of its supported token types
        .. _`Section 4.1.2`: http://tools.ietf.org/html/draft-ietf-oauth-revocation-11#section-4.1.2
        R   R%   u
   1234567890R   R&   R'   i   R(   u
   read writeu	   client_idu   client_secretu   tokenu   refresh_tokenu   token_type_hintu
   {url}?{qs}R)   u   oauth2_provider:revoke-tokenR*   iÈ   R,   N(   R   R   R-   R   R   R   R.   R/   R0   R   R1   R2   R%   R3   R   R4   R5   R6   R7   R9   R:   R,   R;   (   R   R<   R=   R)   R>   (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt!   test_revoke_token_with_wrong_hint“   s    		
(   R"   R#   R?   RB   RC   RD   RG   RH   (    (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyR$   +   s   					(   t
   __future__R    R/   t   django.testR   R   t   django.core.urlresolversR   t   django.utilsR   t   compatR   R   t   modelsR   R   R	   t   settingsR
   t
   test_utilsR   R   R   R   R$   (    (    (    sM   /tmp/pip-unpacked-wheel-ndW12l/oauth2_provider/tests/test_token_revocation.pyt   <module>   s   		