예제 #1
0
    def test_params_string_rfc_example_1(self):
        uri = "https://sandbox.api.mastercard.com"

        oauth_parameters1 = OAuthParameters()
        oauth_parameters1.set_oauth_consumer_key("9djdj82h48djs9d2")
        oauth_parameters1.set_oauth_signature_method("HMAC-SHA1")
        oauth_parameters1.set_oauth_timestamp("137131201")
        oauth_parameters1.set_oauth_nonce("7d8f3e4a")

        oauth_parameters_base1 = oauth_parameters1.get_base_parameters_dict()
        merge_parameters1 = oauth_parameters_base1.copy()
        query_params1 = Util.normalize_params(uri, merge_parameters1)

        self.assertEqual("oauth_consumer_key=9djdj82h48djs9d2&oauth_nonce=7d8f3e4a&oauth_signature_method=HMAC-SHA1&oauth_timestamp=137131201", query_params1);
예제 #2
0
    def test_sign_json_body(self):
        uri = "https://sandbox.api.mastercard.com/restservices/clients"
        consumer_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
        method = "POST"
        body = {
            "clientBaseAddressData": {
                "addressLine1": "Testowa 5",
                "city": "Warszawa",
                "postalCode": "23-456"
            },
            "clientContactData": {
                "phoneNumberMobile": "test"
            },
            "clientNumber": "2019102301",
            "clientPersonalData": {
                "countryCode": "BEL",
                "shortName": "test"
            },
            "embossedData": {
                "embossedFirstName": "Pavel",
                "embossedLastName": "TEST"
            },
            "clientType": "PR"
        }
        oauth_parameters = OAuthParameters()
        oauth_parameters.set_oauth_consumer_key(consumer_key)
        oauth_parameters.set_oauth_nonce("1111111111111111111")
        oauth_parameters.set_oauth_timestamp('1111111111')
        oauth_parameters.set_oauth_signature_method("RSA-SHA256")
        oauth_parameters.set_oauth_version("1.0")
        oauth_parameters.set_oauth_body_hash(
            OAuth().get_encoded_body_hash(body))

        base_string = OAuth.get_base_string(
            uri, method, oauth_parameters.get_base_parameters_dict())
        signed_body = OAuth.sign_message(self, base_string, self.signing_key)

        self.assertEqual(
            "F3zw3Cqjqx3bsHM9BItsqwGkZx1esgsmyUIr8G1/ydbMSvnPzTJ6OeTBhlgln4R7MybyxErUbTaiuRRMD8z6P4WQ/QIRzZefqvcDBJ1e/jgmPIvGUZmM9FsQDRZ1EaTVNIGVfxZDbJS1b7114JtxeCWeAuM/O3Si3EzFNbzQSZr17Cma6qxojv63fKWqd8NqGmq3X5ngeA1/4bo8xveBZO3iSamFjJW9H6Gf8P++paP0+ORJ4YLQ1KQR5hmP53b53fPrXk5/06CmoMGltfHJvrUE8XUCBS/Y8bJehoCw4930VVCtCQ5FBmnX0W5kY/XEoWaHWiYmOIK7QmBztSd2zQ==",
            signed_body)