def test_no_unicode_in_request_params(self):
    access_token = 'foo'
    client_id = 'some_client_id'
    client_secret = 'cOuDdkfjxxnv+'
    refresh_token = '1/0/a.df219fjls0'
    token_expiry = str(datetime.datetime.utcnow())
    token_uri = str(GOOGLE_TOKEN_URI)
    revoke_uri = str(GOOGLE_REVOKE_URI)
    user_agent = 'refresh_checker/1.0'
    credentials = OAuth2Credentials(access_token, client_id, client_secret,
                                    refresh_token, token_expiry, token_uri,
                                    user_agent, revoke_uri=revoke_uri)

    http = HttpMock(headers={'status': '200'})
    http = credentials.authorize(http)
    http.request('http://example.com', method='GET', headers={'foo': 'bar'})
    for k, v in http.headers.items():
      self.assertEqual(str, type(k))
      self.assertEqual(str, type(v))

    # Test again with unicode strings that can't simple be converted to ASCII.
    try:
      http.request(
          'http://example.com', method='GET', headers={'foo': '\N{COMET}'})
      self.fail('Expected exception to be raised.')
    except NonAsciiHeaderError:
      pass

    self.credentials.token_response = 'foobar'
    instance = OAuth2Credentials.from_json(self.credentials.to_json())
    self.assertEqual('foobar', instance.token_response)
Beispiel #2
0
    def test_no_unicode_in_request_params(self):
        access_token = 'foo'
        client_id = 'some_client_id'
        client_secret = 'cOuDdkfjxxnv+'
        refresh_token = '1/0/a.df219fjls0'
        token_expiry = str(datetime.datetime.utcnow())
        token_uri = str(GOOGLE_TOKEN_URI)
        revoke_uri = str(GOOGLE_REVOKE_URI)
        user_agent = 'refresh_checker/1.0'
        credentials = OAuth2Credentials(access_token,
                                        client_id,
                                        client_secret,
                                        refresh_token,
                                        token_expiry,
                                        token_uri,
                                        user_agent,
                                        revoke_uri=revoke_uri)

        http = HttpMock(headers={'status': '200'})
        http = credentials.authorize(http)
        http.request('http://example.com',
                     method='GET',
                     headers={'foo': 'bar'})
        for k, v in http.headers.items():
            self.assertEqual(str, type(k))
            self.assertEqual(str, type(v))

        # Suspect missing usage of client.py clean_headers function (only place where NonAsciiHeaderError is raised)
        # Until that is used this part of the test is useless
        #
        # Test again with unicode strings that can't simple be converted to ASCII.
        # try:
        #   http.request(
        #       'http://example.com', method='GET', headers={'foo': '\N{COMET}'})
        #   self.fail('Expected exception to be raised.')
        # except NonAsciiHeaderError:
        #   pass

        self.credentials.token_response = 'foobar'
        instance = OAuth2Credentials.from_json(self.credentials.to_json())
        self.assertEqual('foobar', instance.token_response)
    def test_no_unicode_in_request_params(self):
        access_token = u'foo'
        client_id = u'some_client_id'
        client_secret = u'cOuDdkfjxxnv+'
        refresh_token = u'1/0/a.df219fjls0'
        token_expiry = unicode(datetime.datetime.utcnow())
        token_uri = unicode(GOOGLE_TOKEN_URI)
        revoke_uri = unicode(GOOGLE_REVOKE_URI)
        user_agent = u'refresh_checker/1.0'
        credentials = OAuth2Credentials(access_token,
                                        client_id,
                                        client_secret,
                                        refresh_token,
                                        token_expiry,
                                        token_uri,
                                        user_agent,
                                        revoke_uri=revoke_uri)

        http = HttpMock(headers={'status': '200'})
        http = credentials.authorize(http)
        http.request(u'http://example.com',
                     method=u'GET',
                     headers={u'foo': u'bar'})
        for k, v in http.headers.iteritems():
            self.assertEqual(str, type(k))
            self.assertEqual(str, type(v))

        # Test again with unicode strings that can't simple be converted to ASCII.
        try:
            http.request(u'http://example.com',
                         method=u'GET',
                         headers={u'foo': u'\N{COMET}'})
            self.fail('Expected exception to be raised.')
        except NonAsciiHeaderError:
            pass

        self.credentials.token_response = 'foobar'
        instance = OAuth2Credentials.from_json(self.credentials.to_json())
        self.assertEqual('foobar', instance.token_response)