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