Fix API test authentication in BCApps - #10085
Prangshuman Das (t-prda) wants to merge 166 commits into
Conversation
5dee938 to
d459cb4
Compare
There was a problem hiding this comment.
Pull request overview
This PR centralizes Basic authentication injection for Library - Graph Mgt-based API tests so they can run in NavUserPassword (UserPassword) containers, and then re-enables several previously disabled API/E2E test suites. It replaces an app-specific Expense Agent auth helper with a shared TestLibraries subscriber and adds a container-side “credential bridge” file so the test runner can obtain the password without requiring Azure Key Vault.
Changes:
- Added
Library - Graph Auth Mgt.as an event subscriber to inject Basic auth for non-Windows test users, sourcing the password from a container file or (fallback) Azure Key Vault. - Removed the Expense Agent test-only auth helper + manual subscription binding; tests now rely on the shared subscriber.
- Re-enabled multiple API/E2E test suites by removing entries from various
*.DisabledTest.jsonfiles (and deleting the APIV1/APIV2 exclusion lists), and updated container provisioning to create the API-test password bridge file.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Layers/W1/Tests/TestLibraries/LibraryGraphAuthMgt.Codeunit.al | New shared subscriber that injects Basic auth into Library - Graph Mgt requests for NavUserPassword scenarios. |
| build/scripts/NewBcContainer.ps1 | Writes the container password bridge file and sets ACLs so server-side AL can read it. |
| src/Apps/W1/ExpenseAgent/test/src/Helper/ExpenseAPITestAuthHelper.Codeunit.al | Removes app-specific auth injection helper in favor of shared TestLibraries implementation. |
| src/Apps/W1/ExpenseAgent/test/src/API/ExpenseUsersAPITest.Codeunit.al | Drops manual subscription binding to the removed helper. |
| src/Apps/W1/ExpenseAgent/test/src/API/ExpenseProjectsAPITest.Codeunit.al | Drops manual subscription binding to the removed helper. |
| src/Apps/W1/ExpenseAgent/test/src/API/ExpensePerDiemLocationsTest.Codeunit.al | Drops manual subscription binding to the removed helper. |
| src/Apps/W1/ExpenseAgent/test/src/API/ExpenseCapabilitiesAPITest.Codeunit.al | Drops manual subscription binding to the removed helper. |
| src/DisabledTests/Tests-Integration/Tests-Integration.DisabledTest.json | Re-enables specific integration API tests by removing disable entries. |
| src/DisabledTests/Tests-Graph/Tests-Graph.DisabledTest.json | Re-enables specific Graph E2E tests by removing disable entries. |
| src/DisabledTests/Sustainability_Tests/Sustainability_Tests.DisabledTest.json | Re-enables Sustainability API tests by removing disable entries. |
| src/DisabledTests/Quality_Management-Tests/Quality_Management-Tests.DisabledTest.json | Re-enables Quality Management API tests by removing disable entry. |
| src/DisabledTests/IRS_Forms_Tests/IRS_Forms_Tests.DisabledTest.json | Re-enables IRS 1099 API test by removing disable entry. |
| src/DisabledTests/E-Document_Core_Tests/E-Document Core Tests.DisabledTest.json | Re-enables E-Document API tests by removing disable entry. |
| src/DisabledTests/_Exclude_APIV2__Tests/_Exclude_APIV2__Tests.DisabledTest.json | Deletes the APIV2 exclusion list (re-enables APIV2 suite). |
| src/DisabledTests/_Exclude_APIV1__Tests/_Exclude_APIV1__Tests.DisabledTest.json | Deletes the APIV1 exclusion list (re-enables APIV1 suite). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Agentic PR Review - Round 1Recommendation: AcceptWhat this PR doesThis PR adds an explicit authentication bridge for API tests that use Library - Graph Mgt. in BCApps UserPassword containers. The subscriber is manual, each affected API test codeunit opts in, Windows-authenticated NAV gates keep their existing behavior, and local NAV UserPassword runs can use the existing Key Vault secret. The change addresses the gate difference directly. It does not change application API behavior, and it avoids making partner test code automatically depend on the BCApps credential bridge. SuggestionsNone. Risk assessment and necessityRisk: The change touches shared test infrastructure and re-enables many existing suites, so CI isolation and concurrency failures may still need separate gate work. The authentication subscriber itself is manually scoped and internal. Necessity: The change is required because BCApps runs these tests with UserPassword while NAV's normal uptake gates use Windows authentication. Without the bridge, the API suites fail with 401 responses and remain disabled.
|
After merging main 2f3b868, final JUnit from run34867798875 still fails exactly six CU148338 permission methods and six CU148339 Spend Request methods. Preserve all22 existing exclusions and add only these12 named methods. Follow-up layers own permission assertions, negative/posting fixtures, default-approver filtering and indirect header updates; each must remove its own deferrals when fixed. No whole-codeunit exclusions or weakened assertions. AB#646383 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
Good Sense Reviewer - Round 15Recommendation: Accept with SuggestionsWhat this PR doesThis change adds shared authentication for API tests, prepares clean tenants for tests that require Disabled isolation, and re-enables affected API suites under UserPassword while keeping ambient-auth runs. Since round 14, the only author commit adds a narrow set of temporary Expense test deferrals for confirmed permission and spend-request failures. That does not change product code and does not address the two older runner concerns, so those remain open. Status of previous suggestions
New observations (commits since round 14)None - the latest commit only adds specific temporary test deferrals and does not add a new changed-span issue in the runner. S6 (🟠 Moderate): Narrow the transient error match S7 (🟠 Moderate): Use separate clean-test result files Risk assessment and necessityRisk: Product behavior is unchanged, but the test runner path is broad. The latest change narrows the current failing Expense scope into named temporary deferrals, but the remaining runner risk is unchanged: a real failure may be retried as transient, or clean-codeunit result evidence may be overwritten by a later normal job on the same tenant. Necessity: The API suites need a shared authentication path and clean Disabled-isolation execution to run reliably in UserPassword containers. The latest deferrals may be a practical way to keep this base focused, but they should stay temporary and the two runner issues above should still be fixed or accepted knowingly.
|
|
Review follow-up at For Good Sense round 15: S6 remains useful. A plain No source changes, CI reruns, merges, or NAV selection changes were made in this comment-review pass. |
Good Sense Reviewer - ReplyThanks for the details. Responses to your points:
|
Retain the twelve auth-stack deferrals alongside three new upstream page-action exclusions. Preserve upstream artifact and configuration updates. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
Create credential files atomically with restrictive ACLs in the shared mount; remove generic InError retry classification. Restore empty-subpage behavior, hide the no-op implementation, avoid unnecessary SaaS mock mutation, add URL regressions, and initialize safe work dates for seven posting suites. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
|
S6 is now addressed in 4c4b30f: removed the standalone ClientSession State is InError transient match. Focused negative tests cover plain InError and unrelated assertion/permission errors plus InError; positive known race fingerprints and the one-retry cap remain covered. All 102 tests in the affected PowerShell suites pass, and the new PowerShell CI checks pass. Fresh AL/container runtime validation is running. S7 remains withdrawn; no result-file naming changes were made. |
Match CreateTenantWebService option arguments to existing callers rather than relying on conversion from the built-in ObjectType type. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
Remove seven precautionary initializer changes introduced during review. Preserve the existing date fixes and defer broader work-date and Microsoft-provider branch coverage as requested. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
Encode from a scoped SecureString BSTR through clearable character and byte buffers, zero/free them in finally, and cover Unicode and the no-plaintext-string contract. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
|
The changed file name Knowledge: Line mapping was unavailable, so this was posted as an issue comment. 👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.41.6 |
Good Sense Reviewer - Round 16Recommendation: AcceptWhat this PR doesThis change enables API tests in UserPassword containers by adding shared request authentication and clean-tenant execution for tests that need committed fixtures. Since round 15, the new commits narrow transient-failure detection, avoid extra immutable plaintext credential copies, use the declared web-service option type in URL fixtures, and keep WorkDate changes within the agreed failure scope. The two remaining runner concerns are now resolved, and no new changed-span issue was found. Status of previous suggestions
New observations (commits since round 15)None - the latest commits address review feedback without adding a new changed-span issue. Risk assessment and necessityRisk: The regression surface remains broad test infrastructure: request authentication, tenant restore sequencing, result aggregation, and many API test initializers. The latest changes reduce the identified retry and credential-handling risks; the reported focused PowerShell suite covers those script paths, while fresh container and AL validation still governs the full integration surface. Necessity: API tests need explicit request credentials in UserPassword containers and clean tenants when fixtures must be committed across NST sessions. The current scope provides both while keeping existing ambient-authentication paths unchanged.
|
Preserve new upstream exclusions and bug links for 650245/650277 without duplicates. Keep existing auth re-enablement and the twelve linked-fix deferrals; do not broaden Expense test enablement in the base PR. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3952f078-a881-4da8-ad96-13b727e48a91
Good Sense Reviewer - Round 17Recommendation: Request ChangesWhat this PR doesThis change enables API tests in UserPassword containers by adding shared request authentication and clean-tenant execution for tests that need committed fixtures. Since round 16, the head has only been refreshed with the current base and the Expense test deferrals were reconciled. The main design still looks targeted: API requests get explicit credentials only where ambient authentication is not enough, the credential file is written and cleaned up with a protected lifetime, and clean test codeunits run on restored secondary tenants. The runtime build is green, but the current static security check fails on a changed PowerShell test file, so the head is not clean yet. Problem-solution fitFit: Strong The change matches the reported need to run API tests in UserPassword containers while preserving existing Windows and SaaS behavior. The latest refresh does not expand the feature scope; it keeps unrelated Expense test failures deferred instead of counting them as part of this fix. Status of previous suggestions
New observations (commits since round 16)S8 (🔴 High): Plaintext SecureString fixture fails code scanning Risk assessment and necessityRisk: The regression surface remains broad test infrastructure: request authentication, credential lifetime, tenant restore sequencing, result aggregation, and many API test initializers. The runtime build passed at this head, and there is no BaseApp event-publisher dependency, but the changed PowerShell test file currently fails static security analysis. Necessity: API tests need explicit request credentials in UserPassword containers and clean tenants when fixtures must be committed across NST sessions. The scope is still justified, but the static security check should be clean before merge.
|
Summary
Enable AL API tests in BCApps UserPassword containers while preserving existing Windows/SaaS authentication behavior. The solution combines pluggable request authentication with clean-tenant execution for tests that commit data.
AB#646383
Current update:
ae9265e44cmerges mainb6ff7f07faand resolves the Expense exclusion-list conflict while preserving upstream bug links and existing auth re-enablement. The PR is conflict-free; 104 affected PowerShell tests and PowerShell CI pass. Fresh runtime CI is running. Expense re-enablement remains a later step; earlier runtime results below do not validate this refreshed head.Why both changes are needed
Library - Graph Mgt.; authenticating the AL test runner alone is insufficient.Authentication design
The extensible enum/interface keeps environment-specific credential handling out of individual tests.
Noneis the default no-op provider.The Microsoft provider leaves Windows/SaaS ambient behavior unchanged. Otherwise, it uses the current AL user's ID and the container password file, falling back to the existing Key Vault secret only when the file is absent. Invalid configured credentials fail explicitly. A successfully read password is cached as
SecretTexton the provider instance, not globally.Tests select the provider in
Initializeon the same retained Graph instance. Re-selecting it is idempotent.OnAfterInitializeWebRequestWithURLremains the final customization event. License-safe WorkDate setup runs before initialization guards where required, because the runner resets session WorkDate between methods.The trust boundary is admitted OnPrem test code and environment credential access—not
Internalor a destination-URL restriction.Pipeline design
The existing test lanes remain; there is no separate API-test job.
RequiredTestIsolation = Disabledcodeunits on a secondary tenant, then restore that worker so discovery cannot contaminate the primary fixture.Task Scheduler is explicitly enabled only for the existing Uncategorized profile that contains background-task polling tests. The clean-tenant scheduler does not override NST scheduling settings.
Scope and later Expense re-enablement
Unrelated fixes stay separately reviewable in the native stack: #11224, #11225, #11226, #11227, #11228, #11229, #11230, #11322, and Expense follow-ups #11451–#11454. This base retains the 47 API-business deferrals and 12 Expense cases owned by those follow-ups.
The existing Expense drafts already contain scoped re-enablement, but must be reconciled with newly merged #11333 before use:
The base keeps 48 unique Expense exclusions, including upstream bug metadata. Six new posted/reapproval cases under AB#650277 and five new API cases are outside the old stack's ownership and remain excluded. The drafts and validation-only #11455 have not been blindly refreshed: their earlier green results are historical. #11340's three action-result assertion fixes are now upstream through #11333, but those page-action tests remain excluded. CZ prerequisite #11370 remains separate.
Prior-head validation
f516524e10: runtime CI passed, PowerShell CI passed, and all 11 auth-contract/URL tests passed.cfcf9b5993: CI passed. W1 verifies all 12 Expense fixes, six added regressions and the 11 contract/URL tests; complete affected suites pass 20/20, 56/56 and 31/31. Each run recorded successful credential removal/cleanup in all 113 final test jobs; disconnected first-attempt workers are not counted as successful cleanup.Excluded/absent and tolerated-native failures are not counted as passes. IN/RU retain coverage gaps. Additional Microsoft-provider branch tests and broader work-date normalization remain deferred by agreement; existing failure-driven date fixes are preserved.