|
22 | 22 | from pygitguardian.models import (
|
23 | 23 | Detail,
|
24 | 24 | HoneytokenResponse,
|
| 25 | + HoneytokenWithContextResponse, |
25 | 26 | JWTResponse,
|
26 | 27 | JWTService,
|
27 | 28 | MultiScanResult,
|
@@ -818,6 +819,74 @@ def test_create_honeytoken_error(
|
818 | 819 | assert isinstance(result, Detail)
|
819 | 820 |
|
820 | 821 |
|
| 822 | +@responses.activate |
| 823 | +def test_create_honeytoken_with_context( |
| 824 | + client: GGClient, |
| 825 | +): |
| 826 | + """ |
| 827 | + GIVEN a ggclient |
| 828 | + WHEN calling create_honeytoken_with_context with parameters |
| 829 | + THEN the parameters are passed in the request |
| 830 | + AND the returned honeytoken use the parameters |
| 831 | + """ |
| 832 | + mock_response = responses.post( |
| 833 | + url=client._url_from_endpoint("honeytokens/with-context", "v1"), |
| 834 | + content_type="application/json", |
| 835 | + status=201, |
| 836 | + json={ |
| 837 | + "content": "def return_aws_credentials():\n \ |
| 838 | + aws_access_key_id = XXXXXXXX\n \ |
| 839 | + aws_secret_access_key = XXXXXXXX\n \ |
| 840 | + aws_region = us-west-2,\n \ |
| 841 | + return (aws_access_key_id, aws_secret_access_key, aws_region)\n", |
| 842 | + "filename": "aws.py", |
| 843 | + "language": "python", |
| 844 | + "suggested_commit_message": "Add AWS credentials", |
| 845 | + "honeytoken_id": "d45a123f-b15d-4fea-abf6-ff2a8479de5b", |
| 846 | + "gitguardian_url": "https://dashboard.gitguardian.com/workspace/1/honeytokens/d45a123f-b15d-4fea-abf6-ff2a8479de5b", # noqa: E501 |
| 847 | + }, |
| 848 | + ) |
| 849 | + |
| 850 | + result = client.create_honeytoken_with_context( |
| 851 | + name="honeytoken A", |
| 852 | + description="honeytoken used in the repository AA", |
| 853 | + type_="AWS", |
| 854 | + filename="aws.yaml", |
| 855 | + ) |
| 856 | + |
| 857 | + assert mock_response.call_count == 1 |
| 858 | + assert isinstance(result, HoneytokenWithContextResponse) |
| 859 | + |
| 860 | + |
| 861 | +@responses.activate |
| 862 | +def test_create_honeytoken_with_context_error( |
| 863 | + client: GGClient, |
| 864 | +): |
| 865 | + """ |
| 866 | + GIVEN a ggclient |
| 867 | + WHEN calling create_honeytoken_with_context with parameters without the right access |
| 868 | + THEN I get a Detail object containing the error detail |
| 869 | + """ |
| 870 | + mock_response = responses.post( |
| 871 | + url=client._url_from_endpoint("honeytokens/with-context", "v1"), |
| 872 | + content_type="application/json", |
| 873 | + status=400, |
| 874 | + json={ |
| 875 | + "detail": "Not authorized", |
| 876 | + }, |
| 877 | + ) |
| 878 | + |
| 879 | + result = client.create_honeytoken_with_context( |
| 880 | + name="honeytoken A", |
| 881 | + description="honeytoken used in the repository AA", |
| 882 | + type_="AWS", |
| 883 | + filename="aws.yaml", |
| 884 | + ) |
| 885 | + |
| 886 | + assert mock_response.call_count == 1 |
| 887 | + assert isinstance(result, Detail) |
| 888 | + |
| 889 | + |
821 | 890 | @responses.activate
|
822 | 891 | def test_create_jwt(
|
823 | 892 | client: GGClient,
|
|
0 commit comments