

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















A+ VERIFIED
Clinical | Rationale-Driven - Pass Guaranteed - A+ Graded
109
QUESTIONS
1
SECTIONS
109
RATIONALES
WHAT THIS COVERS
01 Python Security Testing, API Testing, and Vulnerability Verification
02 API security validation
03 Vulnerability verification aligned with OWASP Top 10 (2021)
04 OWASP API Security Top 10 (2023). It emphasizes pytest framework mastery
05 Secure coding practices
06 Automated vulnerability detection
ABOUT THIS ASSESSMENT This exam assesses advanced proficiency in Python-based security testing, API security validation, and vulnerability verification aligned with OWASP Top 10 (2021) and OWASP API Security Top 10 (2023). It emphasizes pytest framework mastery, secure coding practices, and automated vulnerability detection.
Page 2 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY VERIFICATION
Page 4 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY VERIFICATION
Page 5 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY VERIFICATION
Page 7 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY VERIFICATION
Page 8 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY VERIFICATION
A. API1: Broken Object Level Authorization B. API2: Broken Authentication C. API3: Broken Object Property Level Authorization D. API5: Broken Function Level Authorization Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: API1: Broken Object Level Authorization (BOLA) occurs when an API fails to verify that the requesting user has access to the specific object. Enforcing object-level authorization directly mitigates BOLA. API2 concerns authentication mechanisms, API concerns property-level exposure, and API5 concerns function-level access.
A. pytest-html B. pytest-json-report C. pytest-cov D. pytest-xdist Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: pytest-json-report produces structured JSON suitable for automated vulnerability reporting and severity tagging; pytest-html is for human-readable HTML, pytest-cov measures coverage, and pytest-xdist parallelizes execution.
A. Algorithm confusion attack B. Weak signature verification C. Token expiration bypass D. Insecure token storage Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Accepting 'alg: none' means the server does not verify the signature, allowing attackers to forge tokens. This is a signature verification weakness, not algorithm confusion (which involves switching algorithms), expiration bypass, or storage issues.
A. Fuzzing with payloads like '; rm -rf /' B. Static analysis with Bandit C. Unit testing with valid inputs only D. Load testing with high concurrency Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Fuzzing with malicious payloads directly tests runtime input validation. Static analysis finds patterns but not runtime behavior; valid inputs miss injection; load testing checks performance.
A. Send payloads like ' OR '1'='1 and assert no SQL errors or data leakage. B. Send payloads and assert the response time increases significantly. C. Send payloads and assert the response contains the payload string. D. Send payloads and assert the HTTP status code is 500. Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Parameterized queries treat input as data, so injection payloads should not cause SQL errors or return unauthorized data. Checking for absence of errors and leakage confirms the defense. Timing or status code changes may indicate vulnerability, not mitigation.
Page 10 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. with pytest.raises(AuthError) as exc: ...; assert 'invalid token' in str(exc.value) B. with pytest.raises(AuthError, match='invalid token'): ... C. with pytest.raises(AuthError) as exc: ...; assert exc.type == 'invalid token' D. with pytest.raises(AuthError) as exc: ...; assert exc.value.args[0] == 'invalid token' Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: pytest.raises accepts a match parameter that uses re.search on the string representation of the exception, directly asserting the message contains the pattern. Option A also works but is more verbose; however, B is the idiomatic pytest approach. Option C compares exception type incorrectly, and D requires exact equality, not containment. The question asks for the assertion that ensures containment; match does that succinctly.
A. A01 Broken Access Control; enforce role checks. B. A05 Security Misconfiguration; disable debug mode and return generic errors. C. A03 Injection; parameterize database queries. D. A02 Cryptographic Failures; enable TLS 1.3. Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Exposed stack traces indicate verbose error handling, a security misconfiguration; remediation is disabling debug and returning generic messages. Access control (A), injection (C), and crypto (D) do not address information leakage via error output.
A. Reviewing the source code for parameterized queries B. Reproducing the injection with a benign payload and observing behavior C. Running a static analysis tool scan D. Checking the API documentation for input validation Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Verification requires actively reproducing the vulnerability to confirm exploitability. Reproducing with a benign payload (e.g., a single quote) and observing database errors or behavior changes confirms the finding. Source code review, static analysis, and documentation are passive and may not confirm exploitability.
A. Using string concatenation for query building B. Escaping user input with regular expressions C. Employing parameterized queries with prepared statements D. Validating input length only Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Parameterized queries with prepared statements separate SQL code from data, preventing injection. String concatenation and inadequate escaping are vulnerable. Input validation alone is insufficient. Thus, C is the correct secure practice.
A. To mock external dependencies and simulate attack conditions. B. To generate random test data for fuzzing. C. To measure code coverage of security tests. D. To parallelize test execution. Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: The monkeypatch fixture allows temporary modification of objects, functions, or environment variables during tests, enabling simulation of external dependencies or attack conditions (e.g., mocking authentication failures). It is not used for data generation, coverage measurement, or parallelization.
Page 11 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. Branch coverage B. Mutation score C. Cyclomatic complexity D. Code churn Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Mutation testing evaluates whether tests detect injected faults, revealing weak assertions even with high line coverage; branch coverage, complexity, and churn do not measure assertion effectiveness.
A. GET with query parameters B. POST with JSON body containing extra fields C. DELETE with path parameters D. HEAD with headers Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Mass assignment typically occurs when an API accepts JSON or form data and blindly binds it to internal objects. Sending a POST with extra fields can test if the API improperly assigns them. GET, DELETE, and HEAD are less likely to involve object creation/update.
A. Reproducing the exploit in a controlled environment B. Running an automated scanner again C. Reviewing the scanner's CVSS score D. Checking the vendor's patch history Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Manual reproduction in a controlled environment confirms exploitability and distinguishes true positives from false positives. Re-running scanners, relying on CVSS, or checking patch history do not independently verify the specific finding.
A. monkeypatch.setenv B. pytest.mark.parametrize C. pytest.fixture(autouse=True) D. pytest.mark.skipif Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: monkeypatch.setenv allows safe temporary modification of environment variables within a test, automatically reverting after. Parametrize is for input variation, autouse fixtures apply globally, and skipif conditionally skips tests.
A. Function scope, because it ensures each test gets a fresh transaction and minimizes side effects. B. Session scope, because it creates the database once and rolls back after all tests. C. Module scope, because it groups tests by file and shares the transaction across tests. D. Class scope, because it ties the transaction to the test class lifecycle. Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Function scope provides the highest isolation by creating and tearing down the fixture per test, which is critical for transaction tests to avoid state leakage. Session, module, and class scopes share state across tests, risking false positives/negatives and violating test independence.
Page 13 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. The response time is under 200 ms for all payloads. B. The response body never contains database error strings and login fails with 401. C. The response status is 200 for the payload ' OR '1'='1. D. The response includes a Set-Cookie header. Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Mitigation means the payload neither authenticates nor leaks DB errors; 401 with no error strings confirms parameterization. A is a weak timing heuristic, C indicates successful injection, and D is unrelated to injection.
A. Static analysis with Bandit B. Fuzzing with malicious payloads C. Unit testing with mocked database D. Code review for parameterized queries Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Fuzzing with malicious payloads dynamically tests input handling and can reveal SQL injection if the application executes unsanitized input. Static analysis and code review can hint at issues but don't confirm exploitability. Mocked unit tests bypass actual database interactions.
A. Using a live staging server for all tests B. Mocking HTTP responses with the responses library C. Increasing the request timeout to 60 seconds D. Running tests only during off-peak hours Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Mocking HTTP responses with responses (or similar) makes tests deterministic and fast by removing network dependencies; live servers introduce flakiness, timeouts only delay failures, and scheduling does not ensure isolation.
A. assert 'DROP TABLE' not in response.text B. assert response.status_code == 400 C. assert db.query('SELECT count(*) FROM users') == baseline_count D. assert response.elapsed < 0. Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Verifying database state against a baseline directly confirms the payload did not execute, which is the true security property. String matching can be bypassed by encoding, a 400 may reflect unrelated validation, and timing is nondeterministic and not a security guarantee.
A. Logging full request/response bodies at DEBUG level B. Using a custom formatter to redact tokens and passwords C. Disabling logging entirely during tests D. Writing logs to a world-readable file Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Redacting sensitive fields via a custom formatter prevents accidental exposure in logs. Logging full bodies risks leaking secrets; disabling logging hinders debugging; world-readable files are insecure.
Page 14 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. API4:2023 Unrestricted Resource Consumption B. API8:2023 Security Misconfiguration C. API10:2023 Unsafe Consumption of APIs D. API6:2023 Unrestricted Access to Sensitive Business Flows Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Returning 200 with an error body instead of a proper 4xx/5xx status is a security misconfiguration that can mask failures and bypass monitoring. API4 concerns rate limiting, API10 concerns trusting third-party API data, and API6 concerns business flow abuse. The key is improper HTTP status handling, a misconfiguration.
A. Screenshot of a 500 error B. Reproducible request/response with payload and impact proof C. Scanner output listing the endpoint D. Developer email acknowledging the issue Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: NIST 800-115 requires reproducible evidence demonstrating exploitability and impact, including exact requests, responses, and payloads. A 500 error, scanner output, or informal acknowledgment does not prove exploitation or impact.
A. Using os.system() with sanitized input B. Using subprocess.run() with shell=True C. Using subprocess.run() with a list of arguments and shell=False D. Using eval() on user input Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: subprocess.run() with a list of arguments and shell=False avoids shell interpretation, preventing command injection. os.system() and shell=True invoke a shell, and eval() executes arbitrary code, all of which are unsafe.
A. 200 OK B. 400 Bad Request C. 500 Internal Server Error D. 302 Found Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: A 400 Bad Request indicates the server rejected the request due to invalid input, which is appropriate for malicious payloads. 200 OK would indicate success, 500 suggests server error, and 302 is a redirect. Proper input validation should return 400.
A. pytest-xdist B. pytest-cov C. pytest-mock D. pytest-html Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: pytest-xdist enables parallel test execution across multiple CPUs, reducing runtime for large suites. pytest-cov measures coverage, pytest-mock provides mocking, and pytest-html generates reports. Only xdist offers parallelism.
Page 16 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. API3:2023 Broken Object Property Level Authorization B. API4:2023 Unrestricted Resource Consumption C. API6:2023 Unrestricted Access to Sensitive Business Flows D. API7:2023 Server Side Request Forgery Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: API3:2023 Broken Object Property Level Authorization (BOPLA) occurs when APIs expose sensitive object properties without proper authorization checks. This includes excessive data exposure. The other risks involve resource consumption, business flows, and SSRF, which are unrelated to data exposure via property-level authorization.
A. Sending tokens with 'alg':'none' and verifying rejection B. Brute-forcing the HMAC secret C. Testing token expiration with a clock skew D. Checking for HTTPS enforcement Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Algorithm confusion often involves accepting 'none' or switching RS256 to HS256; explicitly testing 'alg':'none' and verifying rejection is the direct check, while brute-forcing, clock skew, and HTTPS checks address different concerns.
A. function B. class C. module D. session Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: A module-scoped fixture is instantiated once per module, reducing setup overhead while still providing isolation between modules; function scope is too slow, session scope risks cross-module state leakage, and class scope only groups within a class.
A. Return the full exception traceback in the HTTP response B. Log the traceback server-side and return a generic error message with a correlation ID C. Suppress all exceptions and return 200 OK D. Include the exception type and message in the response body Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Logging the traceback server-side maintains debuggability, while returning a generic message with a correlation ID avoids information leakage. Returning tracebacks or exception details exposes sensitive internals. Suppressing exceptions and returning 200 masks errors and violates HTTP semantics. Thus B is the secure practice.
A. Checking if the response Content-Type is application/json B. Injecting a script payload and observing execution in a browser context C. Reviewing server logs for the payload string D. Verifying the presence of a CSP header Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Reflected XSS exploitability requires the payload to execute in a browser context; merely reflecting input in JSON is not sufficient if the browser does not interpret it as HTML/JS. Observing actual script execution (e.g., alert box) confirms the vulnerability, whereas Content-Type, logs, and CSP affect mitigation but do not alone prove exploitability.
Page 17 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. pytest.ini addopts = -p no:cacheprovider B. conftest.py autouse fixture patching requests.get C. pytest-socket with --disable-socket --allow-unix-socket D. tox envlist with network namespace isolation Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: pytest-socket globally blocks socket creation, catching any library that attempts outbound connections, including requests, httpx, and urllib3. Patching a single function misses other clients, disabling cache is unrelated, and tox alone does not enforce network isolation inside the test process.
A. 413 Payload Too Large; API4:2023 Unrestricted Resource Consumption B. 400 Bad Request; API8:2023 Security Misconfiguration C. 422 Unprocessable Entity; API6:2023 Unrestricted Access to Sensitive Business Flows D. 429 Too Many Requests; API5:2023 Broken Function Level Authorization Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Oversized payloads should be rejected with 413, addressing API4:2023 Unrestricted Resource Consumption. 400 (B) is generic, 422 (C) is semantic validation, and 429 (D) is rate limiting, not size enforcement.
A. Once per test function, because autouse forces re-execution. B. Once per module, before the first test that requests it. C. Once per session, because conftest.py fixtures default to session scope. D. Five times, once for each test, because module scope only caches within a single test. Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Module-scoped fixtures are instantiated once per module and cached for all tests in that module; autouse only ensures automatic use, not re-instantiation. Session scope (C) applies only if explicitly set, and function scope (A, D) is the default but overridden here.
A. pytest.mark.parametrize B. pytest.fixture(params=...) C. pytest.mark.skipif D. pytest.mark.xfail Answer: A [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: pytest.mark.parametrize generates distinct test instances for each parameter set, improving reporting and isolation; fixture params also parametrize but are intended for setup variations, skipif conditionally skips, and xfail marks expected failures.
A. Use pytest-xdist to parallelize and ignore failures. B. Mark the XSS test with @pytest.mark.xfail(strict=True) and assert no script reflection. C. Write the test to assert the payload is reflected unescaped and let it fail the build. D. Use pytest --lf to rerun only last failed tests. Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: A security test should assert the secure condition (no unescaped reflection); if the payload is reflected, the assertion fails and CI blocks the build. xfail (B) would invert the logic, xdist (A) ignores failures, and --lf (D) only reruns.
Page 19 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY
A. assert response.status_code == 200 B. assert response.status_code in (200, 201) C. assert response.status_code == 201 and 'Location' in response.headers D. assert response.ok and response.json() is not None Answer: C [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: For a resource-creating POST, 201 Created with a Location header is the correct REST semantic; asserting both status and header verifies compliance. Option B is too permissive, A expects the wrong code, and D only checks generic success without validating creation semantics.
A. API1: Broken Object Level Authorization B. API3: Broken Object Property Level Authorization C. API5: Broken Function Level Authorization D. API8: Security Misconfiguration Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: API3:2023 Broken Object Property Level Authorization covers excessive data exposure and mass assignment, where an API returns or accepts more object properties than the client should access; BOLA concerns object access, BFLA concerns function access, and misconfiguration is broader.
A. A single test function with a for-loop over inputs and assert statements. B. pytest.mark.parametrize with a list of input tuples and expected status codes. C. A fixture with scope='session' that yields each input sequentially. D. pytest.mark.skipif applied to each invalid input case. Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Parametrization generates separate test cases per input, giving distinct pass/fail reporting and isolation. A for-loop (A) stops at first failure and obscures which input failed; fixtures (C) are for setup, and skipif (D) skips rather than tests.
A. Positive security control validation B. Negative testing for improper error handling C. Fuzzing for input validation bypass D. Regression testing for authentication bypass Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: The test verifies that malicious input is safely rejected without leaking information, which is negative testing of error handling; positive validation would confirm legitimate input succeeds, fuzzing would generate random inputs, and regression testing would re-run prior defect cases.
A. Using subprocess with shell=True and sanitized input. B. Using subprocess with a list of arguments and shell=False. C. Using os.system with escaped input. D. Using eval() on user input after validation. Answer: B [Concept: Python Security Testing, API Testing, and Vulnerability Verification] Rationale: Using subprocess with a list of arguments and shell=False avoids shell interpretation, preventing command injection. shell=True, os.system, and eval() are dangerous because they interpret metacharacters or execute arbitrary code.
Page 20 | WGU D385 PYTEST & SECURITY UNIT TESTING WORKBOOK PYTHON SECURITY API TESTING & VULNERABILITY