-
Notifications
You must be signed in to change notification settings - Fork 955
47701 abm errors UI #49896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
andymFleet
wants to merge
31
commits into
main
Choose a base branch
from
47701-abm-errors-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
47701 abm errors UI #49896
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bf45347
Set token_invalid on token_rejected or signature_invalid DEP errors
andymFleet 4b77ea1
Fix token_invalid never updating on the common success path
andymFleet 3ddb8e3
Add test coverage for token_invalid detection in the DEP client hook
andymFleet 9c003d9
Read token_invalid on ABM token list/get, with integration test coverage
andymFleet 01d83a5
Add dep_error classification to the DEP assignment endpoint
andymFleet f83e5db
add change file
andymFleet fc9aeed
Merge branch '47700-abm-token-invalid-errors' into 47701-abm-errors-ui
andymFleet 9557d8b
Show specific AB error reasons in MDM status modal
andymFleet f42a3cf
Add global banner for invalid Apple Business tokens
andymFleet 4787a70
Fix host_dep_assignment nullability in MDMStatusModal
andymFleet 680655d
Add MDMStatusModal test coverage for dep_error and non-DEP hosts
andymFleet cc4fb1e
Add test coverage for the invalid-AB-token banner
andymFleet 0517a2e
Merge remote-tracking branch 'origin/main' into 47700-abm-token-inval…
andymFleet 9b6143c
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet 2b80585
Reconcile NOT_FOUND detection with a ResponseStatus safety net
andymFleet 9a2137c
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet 39b8a9a
Add 401 handling to IsTokenRejected, fix test mock gaps and require-i…
andymFleet fcb4a1d
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet 7233664
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet 0863adc
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet 8737d73
Add missing SetABMTokenInvalidForOrgName test mocks
andymFleet 8c54ecd
Check both 401 and 403 for AuthError in token/signature checks
andymFleet 7097b65
Detect 5xx AuthError in IsServerError, add test coverage
andymFleet bf88f50
Add ClassifyDEPDeviceError test case for 5xx AuthError
andymFleet b8c1e6b
Clear token_invalid on terms-not-signed, not just success
andymFleet 2b84554
Update TestDEPClient for token_invalid clearing on terms-not-signed
andymFleet e3684b3
Merge remote-tracking branch 'origin/47700-abm-token-invalid-errors' …
andymFleet a6ecae3
Rename dep_error to dep_device_error in host DEP assignment response
andymFleet e470c68
Return human-readable dep_device_error message instead of the raw sta…
andymFleet 9ef994f
Merge branch '47700-abm-token-invalid-errors' into 47701-abm-errors-ui
andymFleet 83e6c57
Rename dep_error to dep_device_error and drop client-side error messa…
andymFleet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Added `token_invalid` to the ABM token API responses and `dep_error` to `GET /hosts/:id/dep_assignment`, to help identify why a host's Apple Business Manager device lookup or ABM token isn't returning expected data (e.g. a rejected or invalid-signature token, unsigned terms, a server-side error, or the device no longer being assigned to Fleet). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
frontend/components/MDM/AppleBMTokenInvalidMessage/AppleBMTokenInvalidMessage.tests.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
|
|
||
| import AppleBMTokenInvalidMessage from "./AppleBMTokenInvalidMessage"; | ||
|
|
||
| describe("AppleBMTokenInvalidMessage", () => { | ||
| it("renders singular copy for a single org name", () => { | ||
| render(<AppleBMTokenInvalidMessage orgNames={["Acme Inc."]} />); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| "Your Apple Business (AB) token for Acme Inc. is invalid. macOS, iOS, and iPadOS hosts won’t automatically enroll into Fleet. Users with the admin role in Fleet can renew the token." | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("joins two org names with 'and' and uses plural copy", () => { | ||
| render( | ||
| <AppleBMTokenInvalidMessage orgNames={["Acme Inc.", "Globex Corp."]} /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| "Your Apple Business (AB) tokens for Acme Inc. and Globex Corp. are invalid. macOS, iOS, and iPadOS hosts won’t automatically enroll into Fleet. Users with the admin role in Fleet can renew the tokens." | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("joins three or more org names with an Oxford comma", () => { | ||
| render( | ||
| <AppleBMTokenInvalidMessage | ||
| orgNames={["Acme Inc.", "Globex Corp.", "Initech"]} | ||
| /> | ||
| ); | ||
|
|
||
| expect( | ||
| screen.getByText( | ||
| "Your Apple Business (AB) tokens for Acme Inc., Globex Corp., and Initech are invalid. macOS, iOS, and iPadOS hosts won’t automatically enroll into Fleet. Users with the admin role in Fleet can renew the tokens." | ||
| ) | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); |
36 changes: 36 additions & 0 deletions
36
frontend/components/MDM/AppleBMTokenInvalidMessage/AppleBMTokenInvalidMessage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import React from "react"; | ||
|
|
||
| import InfoBanner from "components/InfoBanner"; | ||
|
|
||
| const baseClass = "apple-bm-token-invalid-message"; | ||
|
|
||
| const orgNameList = (orgNames: string[]) => { | ||
| if (orgNames.length <= 2) { | ||
| return orgNames.join(" and "); | ||
| } | ||
| return `${orgNames.slice(0, -1).join(", ")}, and ${ | ||
| orgNames[orgNames.length - 1] | ||
| }`; | ||
| }; | ||
|
|
||
| interface IAppleBMTokenInvalidMessageProps { | ||
| /** Organization names of the invalid AB tokens */ | ||
| orgNames: string[]; | ||
| } | ||
|
|
||
| const AppleBMTokenInvalidMessage = ({ | ||
| orgNames, | ||
| }: IAppleBMTokenInvalidMessageProps) => { | ||
| const isPlural = orgNames.length > 1; | ||
|
|
||
| return ( | ||
| <InfoBanner className={baseClass} color="yellow"> | ||
| Your Apple Business (AB) {isPlural ? "tokens" : "token"} for{" "} | ||
| {orgNameList(orgNames)} {isPlural ? "are" : "is"} invalid. macOS, iOS, and | ||
| iPadOS hosts won’t automatically enroll into Fleet. Users with the admin | ||
| role in Fleet can renew the {isPlural ? "tokens" : "token"}. | ||
| </InfoBanner> | ||
| ); | ||
| }; | ||
|
|
||
| export default AppleBMTokenInvalidMessage; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from "./AppleBMTokenInvalidMessage"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import React, { useContext } from "react"; | ||
|
|
||
| import { screen } from "@testing-library/react"; | ||
| import { renderWithSetup } from "test/test-utils"; | ||
| import createMockUser from "__mocks__/userMock"; | ||
|
|
||
| import AppProvider, { AppContext, sortAvailableTeams } from "./app"; | ||
|
|
||
| describe("sortAvailableTeams", () => { | ||
| it("places Unassigned last for global team users", () => { | ||
| const teams = [ | ||
| { id: 0, name: "Unassigned" }, | ||
| { id: 2, name: "Zebra" }, | ||
| { id: 1, name: "Alpha" }, | ||
| { id: -1, name: "All fleets" }, | ||
| ]; | ||
| const result = sortAvailableTeams(teams, createMockUser()); | ||
| expect(result.map((t) => t.name)).toEqual([ | ||
| "All fleets", | ||
| "Alpha", | ||
| "Zebra", | ||
| "Unassigned", | ||
| ]); | ||
| }); | ||
|
|
||
| it("does not include All fleets or Unassigned for non-global users", () => { | ||
| const teams = [ | ||
| { id: 0, name: "Unassigned" }, | ||
| { id: 2, name: "Zebra" }, | ||
| { id: 1, name: "Alpha" }, | ||
| { id: -1, name: "All fleets" }, | ||
| ]; | ||
| const result = sortAvailableTeams( | ||
| teams, | ||
| createMockUser({ global_role: null }) | ||
| ); | ||
| expect(result.map((t) => t.name)).toEqual(["Alpha", "Zebra"]); | ||
| }); | ||
|
|
||
| it("sorts named teams alphabetically (case-insensitive)", () => { | ||
| const teams = [ | ||
| { id: 3, name: "charlie" }, | ||
| { id: 1, name: "Alpha" }, | ||
| { id: 2, name: "Bravo" }, | ||
| ]; | ||
| const result = sortAvailableTeams( | ||
| teams, | ||
| createMockUser({ global_role: null }) | ||
| ); | ||
| expect(result.map((t) => t.name)).toEqual(["Alpha", "Bravo", "charlie"]); | ||
| }); | ||
| }); | ||
|
|
||
| const AbmExpiryConsumer = () => { | ||
| const { | ||
| hasAbmTokenInvalid, | ||
| invalidAbmTokenOrgNames, | ||
| setABMExpiry, | ||
| } = useContext(AppContext); | ||
|
|
||
| return ( | ||
| <div> | ||
| <button | ||
| type="button" | ||
| onClick={() => | ||
| setABMExpiry({ | ||
| earliestExpiry: "", | ||
| needsAbmTermsRenewal: false, | ||
| hasAbmTokenInvalid: true, | ||
| invalidAbmTokenOrgNames: [ | ||
| "Acme Inc.", | ||
| "Fleet Device Management Inc.", | ||
| ], | ||
| }) | ||
| } | ||
| > | ||
| Set invalid tokens | ||
| </button> | ||
| <div data-testid="has-invalid">{String(hasAbmTokenInvalid)}</div> | ||
| <div data-testid="org-names">{invalidAbmTokenOrgNames.join(", ")}</div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| describe("AppProvider - setABMExpiry", () => { | ||
| it("defaults hasAbmTokenInvalid to false and invalidAbmTokenOrgNames to an empty list", () => { | ||
| renderWithSetup( | ||
| <AppProvider> | ||
| <AbmExpiryConsumer /> | ||
| </AppProvider> | ||
| ); | ||
|
|
||
| expect(screen.getByTestId("has-invalid")).toHaveTextContent("false"); | ||
| expect(screen.getByTestId("org-names")).toHaveTextContent(""); | ||
| }); | ||
|
|
||
| it("updates hasAbmTokenInvalid and invalidAbmTokenOrgNames when setABMExpiry is called", async () => { | ||
| const { user } = renderWithSetup( | ||
| <AppProvider> | ||
| <AbmExpiryConsumer /> | ||
| </AppProvider> | ||
| ); | ||
|
|
||
| await user.click( | ||
| screen.getByRole("button", { name: "Set invalid tokens" }) | ||
| ); | ||
|
|
||
| expect(screen.getByTestId("has-invalid")).toHaveTextContent("true"); | ||
| expect(screen.getByTestId("org-names")).toHaveTextContent( | ||
| "Acme Inc., Fleet Device Management Inc." | ||
| ); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Document the correct response property.
The endpoint serializes
dep_device_error, notdep_error; clients following this note will look for a field that is never returned.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents