Exemple #1
0
 def addHeadersTo(self, full_url, full_headers):
     if self.consumer is not None and self.access_token is not None:
         request = OAuthRequest.from_consumer_and_token(self.consumer, self.access_token, http_url=full_url)
         request.sign_request(OAuthSignatureMethod_PLAINTEXT(), self.consumer, self.access_token)
         full_headers.update(request.to_header(OAUTH_REALM))
     if not self.handle_errors:
         full_headers["X_Zope_handle_errors"] = "False"
    def _getRequestForPersonAndAccountWithDifferentIDs(self):
        """Return a LaunchpadTestRequest with the correct OAuth parameters in
        its form.
        """
        # Create a lone account followed by an account-with-person just to
        # make sure in the second one the ID of the account and the person are
        # different.
        self.factory.makeAccount('Personless account')
        person = self.factory.makePerson()
        self.failIfEqual(person.id, person.account.id)

        # Create an access token for our new person.
        consumer = getUtility(IOAuthConsumerSet).new('test-consumer')
        request_token = consumer.newRequestToken()
        request_token.review(
            person, permission=OAuthPermission.READ_PUBLIC, context=None)
        access_token = request_token.createAccessToken()

        # Use oauth.OAuthRequest just to generate a dictionary containing all
        # the parameters we need to use in a valid OAuth request, using the
        # access token we just created for our new person.
        oauth_request = OAuthRequest.from_consumer_and_token(
            consumer, access_token)
        oauth_request.sign_request(
            OAuthSignatureMethod_PLAINTEXT(), consumer, access_token)
        return LaunchpadTestRequest(form=oauth_request.parameters)
Exemple #3
0
    def _getRequestForPersonAndAccountWithDifferentIDs(self):
        """Return a LaunchpadTestRequest with the correct OAuth parameters in
        its form.
        """
        # Create a lone account followed by an account-with-person just to
        # make sure in the second one the ID of the account and the person are
        # different.
        self.factory.makeAccount('Personless account')
        person = self.factory.makePerson()
        self.assertNotEqual(person.id, person.account.id)

        # Create an access token for our new person.
        consumer = getUtility(IOAuthConsumerSet).new(u'test-consumer')
        request_token, _ = consumer.newRequestToken()
        request_token.review(person,
                             permission=OAuthPermission.READ_PUBLIC,
                             context=None)
        access_token, access_secret = request_token.createAccessToken()

        # Use oauth.OAuthRequest just to generate a dictionary containing all
        # the parameters we need to use in a valid OAuth request, using the
        # access token we just created for our new person.
        oauth_consumer = OAuthConsumer(consumer.key, u'')
        oauth_token = OAuthToken(access_token.key, access_secret)
        oauth_request = OAuthRequest.from_consumer_and_token(
            oauth_consumer, oauth_token)
        oauth_request.sign_request(OAuthSignatureMethod_PLAINTEXT(),
                                   oauth_consumer, oauth_token)
        return LaunchpadTestRequest(form=oauth_request.parameters)
Exemple #4
0
 def addHeadersTo(self, full_url, full_headers):
     if self.consumer is not None and self.access_token is not None:
         request = OAuthRequest.from_consumer_and_token(self.consumer,
                                                        self.access_token,
                                                        http_url=full_url)
         request.sign_request(OAuthSignatureMethod_PLAINTEXT(),
                              self.consumer, self.access_token)
         full_headers.update(request.to_header(OAUTH_REALM))
     if not self.handle_errors:
         full_headers['X_Zope_handle_errors'] = 'False'