<s> from __future__ import absolute_import , unicode_literals <EOL> from oauthlib . common import Request <EOL> from oauthlib . oauth1 import SIGNATURE_RSA , SIGNATURE_PLAINTEXT <EOL> from oauthlib . oauth1 import SIGNATURE_TYPE_BODY , SIGNATURE_TYPE_QUERY <EOL> from oauthlib . oauth1 . rfc5849 import Client , bytes_type <EOL> from ... unittest import TestCase <EOL> class ClientRealmTests ( TestCase ) : <EOL> def test_client_no_realm ( self ) : <EOL> client = Client ( "<STR_LIT>" ) <EOL> uri , header , body = client . sign ( "<STR_LIT>" ) <EOL> self . assertTrue ( <EOL> header [ "<STR_LIT>" ] . startswith ( '<STR_LIT>' ) ) <EOL> def test_client_realm_sign_with_default_realm ( self ) : <EOL> client = Client ( "<STR_LIT>" , realm = "<STR_LIT>" ) <EOL> self . assertEqual ( client . realm , "<STR_LIT>" ) <EOL> uri , header , body = client . sign ( "<STR_LIT>" ) <EOL> self . assertTrue ( <EOL> header [ "<STR_LIT>" ] . startswith ( '<STR_LIT>' ) ) <EOL> def test_client_realm_sign_with_additional_realm ( self ) : <EOL> client = Client ( "<STR_LIT>" , realm = "<STR_LIT>" ) <EOL> uri , header , body = client . sign ( "<STR_LIT>" , realm = "<STR_LIT>" ) <EOL> self . assertTrue ( <EOL> header [ "<STR_LIT>" ] . startswith ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( client . realm , "<STR_LIT>" ) <EOL> class ClientConstructorTests ( TestCase ) : <EOL> def test_convert_to_unicode_resource_owner ( self ) : <EOL> client = Client ( '<STR_LIT>' , <EOL> resource_owner_key = b'<STR_LIT>' ) <EOL> self . assertFalse ( isinstance ( client . resource_owner_key , bytes_type ) ) <EOL> self . assertEqual ( client . resource_owner_key , '<STR_LIT>' ) <EOL> def test_give_explicit_timestamp ( self ) : <EOL> client = Client ( '<STR_LIT>' , timestamp = '<STR_LIT:1>' ) <EOL> params = dict ( client . get_oauth_params ( Request ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( params [ '<STR_LIT>' ] , '<STR_LIT:1>' ) <EOL> def test_give_explicit_nonce ( self ) : <EOL> client = Client ( '<STR_LIT>' , nonce = '<STR_LIT:1>' ) <EOL> params = dict ( client . get_oauth_params ( Request ( '<STR_LIT>' ) ) ) <EOL> self . assertEqual ( params [ '<STR_LIT>' ] , '<STR_LIT:1>' ) <EOL> def test_decoding ( self ) : <EOL> client = Client ( '<STR_LIT>' , decoding = '<STR_LIT:utf-8>' ) <EOL> uri , headers , body = client . sign ( '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertIsInstance ( uri , bytes_type ) <EOL> self . assertIsInstance ( body , bytes_type ) <EOL> for k , v in headers . items ( ) : <EOL> self . assertIsInstance ( k , bytes_type ) <EOL> self . assertIsInstance ( v , bytes_type ) <EOL> def test_rsa ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_method = SIGNATURE_RSA ) <EOL> self . assertIsNone ( client . rsa_key ) <EOL> class SignatureMethodTest ( TestCase ) : <EOL> def test_rsa_method ( self ) : <EOL> private_key = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> client = Client ( '<STR_LIT>' , signature_method = SIGNATURE_RSA , <EOL> rsa_key = private_key , timestamp = '<STR_LIT>' , nonce = '<STR_LIT:abc>' ) <EOL> u , h , b = client . sign ( '<STR_LIT>' ) <EOL> correct = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , correct ) <EOL> def test_plaintext_method ( self ) : <EOL> client = Client ( '<STR_LIT>' , <EOL> signature_method = SIGNATURE_PLAINTEXT , <EOL> timestamp = '<STR_LIT>' , <EOL> nonce = '<STR_LIT:abc>' , <EOL> client_secret = '<STR_LIT:foo>' , <EOL> resource_owner_secret = '<STR_LIT:bar>' ) <EOL> u , h , b = client . sign ( '<STR_LIT>' ) <EOL> correct = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , correct ) <EOL> def test_invalid_method ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_method = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , client . sign , '<STR_LIT>' ) <EOL> def test_rsa_no_key ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_method = SIGNATURE_RSA ) <EOL> self . assertRaises ( ValueError , client . sign , '<STR_LIT>' ) <EOL> def test_register_method ( self ) : <EOL> Client . register_signature_method ( '<STR_LIT>' , <EOL> lambda base_string , client : '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT>' in Client . SIGNATURE_METHODS ) <EOL> client = Client ( '<STR_LIT>' , signature_method = '<STR_LIT>' , <EOL> timestamp = '<STR_LIT>' , nonce = '<STR_LIT:abc>' ) <EOL> u , h , b = client . sign ( '<STR_LIT>' ) <EOL> self . assertEquals ( h [ '<STR_LIT>' ] , ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) ) <EOL> class SignatureTypeTest ( TestCase ) : <EOL> def test_params_in_body ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_type = SIGNATURE_TYPE_BODY , <EOL> timestamp = '<STR_LIT>' , nonce = '<STR_LIT>' ) <EOL> _ , h , b = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> correct = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( b , correct ) <EOL> def test_params_in_query ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_type = SIGNATURE_TYPE_QUERY , <EOL> timestamp = '<STR_LIT>' , nonce = '<STR_LIT>' ) <EOL> u , _ , _ = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' ) <EOL> correct = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( u , correct ) <EOL> def test_invalid_signature_type ( self ) : <EOL> client = Client ( '<STR_LIT>' , signature_type = '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , client . sign , '<STR_LIT>' ) <EOL> class SigningTest ( TestCase ) : <EOL> def test_case_insensitive_headers ( self ) : <EOL> client = Client ( '<STR_LIT>' ) <EOL> _ , h , _ = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> _ , h , _ = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> _ , h , _ = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> _ , h , _ = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_sign_no_body ( self ) : <EOL> client = Client ( '<STR_LIT>' , decoding = '<STR_LIT:utf-8>' ) <EOL> self . assertRaises ( ValueError , client . sign , '<STR_LIT>' , <EOL> http_method = '<STR_LIT:POST>' , body = None , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> def test_sign_body ( self ) : <EOL> client = Client ( '<STR_LIT>' ) <EOL> _ , h , b = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( h [ '<STR_LIT:Content-Type>' ] , '<STR_LIT>' ) <EOL> def test_sign_get_with_body ( self ) : <EOL> client = Client ( '<STR_LIT>' ) <EOL> for method in ( '<STR_LIT:GET>' , '<STR_LIT>' ) : <EOL> self . assertRaises ( ValueError , client . sign , '<STR_LIT>' , <EOL> http_method = method , body = '<STR_LIT>' , <EOL> headers = { <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT>' <EOL> } ) <EOL> def test_sign_unicode ( self ) : <EOL> client = Client ( '<STR_LIT>' , nonce = '<STR_LIT:abc>' , timestamp = '<STR_LIT:abc>' ) <EOL> _ , h , b = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , <EOL> body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( b , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , h [ '<STR_LIT>' ] ) <EOL> _ , h , b = client . sign ( '<STR_LIT>' , http_method = '<STR_LIT:POST>' , <EOL> body = '<STR_LIT>' , <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( b , '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , h [ '<STR_LIT>' ] ) </s>
