|
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*-# |
| 3 | +# |
| 4 | +# |
| 5 | +# Copyright (c) 2019 MasterCard International Incorporated |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# Redistribution and use in source and binary forms, with or without modification, are |
| 9 | +# permitted provided that the following conditions are met: |
| 10 | +# |
| 11 | +# Redistributions of source code must retain the above copyright notice, this list of |
| 12 | +# conditions and the following disclaimer. |
| 13 | +# Redistributions in binary form must reproduce the above copyright notice, this list of |
| 14 | +# conditions and the following disclaimer in the documentation and/or other materials |
| 15 | +# provided with the distribution. |
| 16 | +# Neither the name of the MasterCard International Incorporated nor the names of its |
| 17 | +# contributors may be used to endorse or promote products derived from this software |
| 18 | +# without specific prior written permission. |
| 19 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 20 | +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
| 22 | +# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 24 | +# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 25 | +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
| 26 | +# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 27 | +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | +# SUCH DAMAGE. |
| 29 | +# |
| 30 | +import unittest |
| 31 | +import requests |
| 32 | +from urllib.parse import urlencode |
| 33 | +from oauth1.oauth import OAuth |
| 34 | +from oauth1.signer_interceptor import SignerInterceptor |
| 35 | +import oauth1.authenticationutils as authenticationutils |
| 36 | +from os.path import dirname, realpath, join, os |
| 37 | +from oauth1.signer import OAuthSigner |
| 38 | +from oauth1.signer_interceptor import add_signing_layer |
| 39 | +from oauth1.signer_interceptor import get_signing_layer |
| 40 | + |
| 41 | + |
| 42 | +class OAuthInterceptorTest(unittest.TestCase): |
| 43 | + |
| 44 | + |
| 45 | + """ add an interceptor, check api client has changed """ |
| 46 | + def test_add_interceptor(self): |
| 47 | + if os.path.exists('./test_key_container.p12'): |
| 48 | + key_file = './test_key_container.p12' |
| 49 | + key_password = "Password1" |
| 50 | + consumer_key = 'uLXKmWNmIkzIGKfA2injnNQqpZaxaBSKxa3ixEVu2f283c95!33b9b2bd960147e387fa6f3f238f07170000000000000000' |
| 51 | + |
| 52 | + signing_layer1 = get_signing_layer(self, requests) |
| 53 | + |
| 54 | + add_signing_layer(self, requests, key_file, key_password, consumer_key) |
| 55 | + |
| 56 | + signing_layer2 = get_signing_layer(self, requests) |
| 57 | + |
| 58 | + self.assertNotEqual(signing_layer1, signing_layer2) |
| 59 | + |
| 60 | + |
| 61 | + else: |
| 62 | + print("Please add a ./test_key_container.p12 file to enable key tests") |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +if __name__ == '__main__': |
| 67 | + unittest.main() |
0 commit comments