|
| 1 | +import logging |
1 | 2 | from unittest import mock |
2 | 3 |
|
3 | 4 | from lxml import etree |
4 | 5 |
|
5 | | -from src.legacy_soap_api.legacy_soap_api_auth import USE_SOAP_JWT_HEADER_KEY |
| 6 | +from src.constants.lookup_constants import Privilege |
| 7 | +from src.legacy_soap_api.legacy_soap_api_auth import ( |
| 8 | + USE_SOAP_JWT_HEADER_KEY, |
| 9 | + SOAPAuth, |
| 10 | + SOAPClientCertificate, |
| 11 | +) |
6 | 12 | from src.legacy_soap_api.legacy_soap_api_utils import get_invalid_path_response |
| 13 | +from tests.lib.data_factories import setup_cert_user |
| 14 | +from tests.src.db.models.factories import ( |
| 15 | + AgencyFactory, |
| 16 | + ApplicationFactory, |
| 17 | + ApplicationSubmissionFactory, |
| 18 | + CompetitionFactory, |
| 19 | + LegacyAgencyCertificateFactory, |
| 20 | + OpportunityFactory, |
| 21 | +) |
7 | 22 |
|
8 | 23 | NSMAP = { |
9 | 24 | "envelope": "http://schemas.xmlsoap.org/soap/envelope/", |
|
15 | 30 | LEGACY_TRACKING_NUMBER = "GRANT00000008" |
16 | 31 | GET_APPLICATION_PATH = f"{{{NSMAP['envelope']}}}Body/{{{NSMAP['application_request']}}}GetApplicationRequest/{{{NSMAP['tracking_number']}}}GrantsGovTrackingNumber" |
17 | 32 | GET_APPLICATION_ZIP_PATH = f"{{{NSMAP['envelope']}}}Body/{{{NSMAP['application_request']}}}GetApplicationZipRequest/{{{NSMAP['tracking_number']}}}GrantsGovTrackingNumber" |
| 33 | +MOCK_FINGERPRINT = "123" |
| 34 | +MOCK_CERT = "456" |
| 35 | +MOCK_CERT_STR = "certstr" |
18 | 36 |
|
19 | 37 |
|
20 | 38 | def test_successful_request(client, fixture_from_file, caplog) -> None: |
@@ -244,3 +262,43 @@ def test_simpler_getapplicationzip_operation_returns_not_found_response_includes |
244 | 262 | assert ( |
245 | 263 | response.headers["Set-Cookie"] == "JSESSIONID=xyz; Path=/grantsws-agency; Secure; HttpOnly" |
246 | 264 | ) |
| 265 | + |
| 266 | + |
| 267 | +def test_simpler_getapplicationzip_operation_raising_httperror_due_to_privileges_logs_info( |
| 268 | + client, fixture_from_file, enable_factory_create, caplog |
| 269 | +) -> None: |
| 270 | + caplog.set_level(logging.INFO) |
| 271 | + agency = AgencyFactory.create() |
| 272 | + user, role, soap_client_certificate = setup_cert_user( |
| 273 | + agency, {Privilege.LEGACY_AGENCY_GRANT_RETRIEVER} |
| 274 | + ) |
| 275 | + opportunity = OpportunityFactory.create(agency_code=agency.agency_code) |
| 276 | + competition = CompetitionFactory( |
| 277 | + opportunity=opportunity, |
| 278 | + ) |
| 279 | + application = ApplicationFactory.create(competition=competition) |
| 280 | + submission = ApplicationSubmissionFactory.create(application=application) |
| 281 | + full_path = "/grantsws-agency/services/v2/AgencyWebServicesSoapPort" |
| 282 | + fixture_path = "/legacy_soap_api/grantors/get_application_zip_request.xml" |
| 283 | + mock_data = fixture_from_file(fixture_path) |
| 284 | + envelope = etree.fromstring(mock_data) |
| 285 | + tracking_number = envelope.find(GET_APPLICATION_ZIP_PATH) |
| 286 | + tracking_number.text = f"GRANT{submission.legacy_tracking_number}" |
| 287 | + mock_client_cert = SOAPClientCertificate( |
| 288 | + cert=MOCK_CERT_STR, |
| 289 | + fingerprint=MOCK_FINGERPRINT, |
| 290 | + serial_number="1235", |
| 291 | + legacy_certificate=LegacyAgencyCertificateFactory.create(), |
| 292 | + ) |
| 293 | + with mock.patch("src.legacy_soap_api.legacy_soap_api_routes.get_soap_auth") as mock_get_auth: |
| 294 | + mock_get_auth.return_value = SOAPAuth(certificate=mock_client_cert) |
| 295 | + response = client.post( |
| 296 | + full_path, data=etree.tostring(envelope), headers={"Use-Simpler-Override": "true"} |
| 297 | + ) |
| 298 | + assert response.status_code == 500 |
| 299 | + post_message = next( |
| 300 | + record |
| 301 | + for record in caplog.records |
| 302 | + if record.message == "User did not have permission to access this application" |
| 303 | + ) |
| 304 | + assert post_message.message == "User did not have permission to access this application" |
0 commit comments