|
1 | 1 | import datetime |
2 | 2 | import json |
| 3 | +import re |
3 | 4 | import tempfile |
4 | 5 | import uuid |
5 | 6 | from collections import OrderedDict |
@@ -788,6 +789,36 @@ def fail(): |
788 | 789 | last_call.get_raw_header("X-Stripe-Client-User-Agent") |
789 | 790 | ) |
790 | 791 |
|
| 792 | + def test_source_field_is_md5_hex(self, requestor, http_client_mock): |
| 793 | + http_client_mock.stub_request( |
| 794 | + "get", path=self.v1_path, rbody="{}", rcode=200 |
| 795 | + ) |
| 796 | + requestor.request("get", self.v1_path, {}, base_address="api") |
| 797 | + |
| 798 | + last_call = http_client_mock.get_last_call() |
| 799 | + client_ua = json.loads( |
| 800 | + last_call.get_raw_header("X-Stripe-Client-User-Agent") |
| 801 | + ) |
| 802 | + assert "source" in client_ua |
| 803 | + assert re.fullmatch(r"[0-9a-f]{32}", client_ua["source"]) |
| 804 | + |
| 805 | + def test_source_field_absent_when_uname_fails( |
| 806 | + self, requestor, mocker, http_client_mock |
| 807 | + ): |
| 808 | + http_client_mock.stub_request( |
| 809 | + "get", path=self.v1_path, rbody="{}", rcode=200 |
| 810 | + ) |
| 811 | + mocker.patch( |
| 812 | + "stripe._api_requestor._get_uname_hash", return_value=None |
| 813 | + ) |
| 814 | + requestor.request("get", self.v1_path, {}, base_address="api") |
| 815 | + |
| 816 | + last_call = http_client_mock.get_last_call() |
| 817 | + client_ua = json.loads( |
| 818 | + last_call.get_raw_header("X-Stripe-Client-User-Agent") |
| 819 | + ) |
| 820 | + assert "source" not in client_ua |
| 821 | + |
791 | 822 | def test_uses_given_idempotency_key(self, requestor, http_client_mock): |
792 | 823 | method = "post" |
793 | 824 | http_client_mock.stub_request( |
|
0 commit comments