Skip to content
Draft
Show file tree
Hide file tree
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 Jul 21, 2026
4b77ea1
Fix token_invalid never updating on the common success path
andymFleet Jul 21, 2026
3ddb8e3
Add test coverage for token_invalid detection in the DEP client hook
andymFleet Jul 21, 2026
9c003d9
Read token_invalid on ABM token list/get, with integration test coverage
andymFleet Jul 21, 2026
01d83a5
Add dep_error classification to the DEP assignment endpoint
andymFleet Jul 22, 2026
f83e5db
add change file
andymFleet Jul 22, 2026
fc9aeed
Merge branch '47700-abm-token-invalid-errors' into 47701-abm-errors-ui
andymFleet Jul 22, 2026
9557d8b
Show specific AB error reasons in MDM status modal
andymFleet Jul 23, 2026
f42a3cf
Add global banner for invalid Apple Business tokens
andymFleet Jul 23, 2026
4787a70
Fix host_dep_assignment nullability in MDMStatusModal
andymFleet Jul 23, 2026
680655d
Add MDMStatusModal test coverage for dep_error and non-DEP hosts
andymFleet Jul 23, 2026
cc4fb1e
Add test coverage for the invalid-AB-token banner
andymFleet Jul 23, 2026
0517a2e
Merge remote-tracking branch 'origin/main' into 47700-abm-token-inval…
andymFleet Jul 23, 2026
9b6143c
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet Jul 23, 2026
2b80585
Reconcile NOT_FOUND detection with a ResponseStatus safety net
andymFleet Jul 23, 2026
9a2137c
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet Jul 23, 2026
39b8a9a
Add 401 handling to IsTokenRejected, fix test mock gaps and require-i…
andymFleet Jul 23, 2026
fcb4a1d
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet Jul 23, 2026
7233664
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet Jul 23, 2026
0863adc
Merge branch 'main' into 47700-abm-token-invalid-errors
andymFleet Jul 23, 2026
8737d73
Add missing SetABMTokenInvalidForOrgName test mocks
andymFleet Jul 23, 2026
8c54ecd
Check both 401 and 403 for AuthError in token/signature checks
andymFleet Jul 23, 2026
7097b65
Detect 5xx AuthError in IsServerError, add test coverage
andymFleet Jul 23, 2026
bf88f50
Add ClassifyDEPDeviceError test case for 5xx AuthError
andymFleet Jul 23, 2026
b8c1e6b
Clear token_invalid on terms-not-signed, not just success
andymFleet Jul 24, 2026
2b84554
Update TestDEPClient for token_invalid clearing on terms-not-signed
andymFleet Jul 24, 2026
e3684b3
Merge remote-tracking branch 'origin/47700-abm-token-invalid-errors' …
andymFleet Jul 24, 2026
a6ecae3
Rename dep_error to dep_device_error in host DEP assignment response
andymFleet Jul 24, 2026
e470c68
Return human-readable dep_device_error message instead of the raw sta…
andymFleet Jul 24, 2026
9ef994f
Merge branch '47700-abm-token-invalid-errors' into 47701-abm-errors-ui
andymFleet Jul 24, 2026
83e6c57
Rename dep_error to dep_device_error and drop client-side error messa…
andymFleet Jul 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/47700-abm-token-invalid-dep-error
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).

Copy link
Copy Markdown
Contributor

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, not dep_error; clients following this note will look for a field that is never returned.

Proposed fix
- `dep_error` to `GET /hosts/:id/dep_assignment`
+ `dep_device_error` to `GET /hosts/:id/dep_assignment`
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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).
- Added `token_invalid` to the ABM token API responses and `dep_device_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).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@changes/47700-abm-token-invalid-dep-error` at line 1, Update the changelog
entry to document the serialized response property dep_device_error instead of
dep_error, while preserving the existing endpoint and ABM token context.

6 changes: 6 additions & 0 deletions cmd/fleetctl/fleetctl/apply_deprecated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ func TestApplyAsGitOpsDeprecatedKeys(t *testing.T) {
ds.CountABMTokensWithTermsExpiredFunc = func(ctx context.Context) (int, error) {
return 0, nil
}
ds.SetABMTokenInvalidForOrgNameFunc = func(ctx context.Context, orgName string, invalid bool) (bool, error) {
return false, nil
}

ds.GetABMTokenOrgNamesAssociatedWithTeamFunc = func(ctx context.Context, teamID *uint) ([]string, error) {
return []string{"foobar"}, nil
Expand Down Expand Up @@ -768,6 +771,9 @@ func TestApplyMacosSetupDeprecatedKeys(t *testing.T) {
ds.CountABMTokensWithTermsExpiredFunc = func(ctx context.Context) (int, error) {
return 0, nil
}
ds.SetABMTokenInvalidForOrgNameFunc = func(ctx context.Context, orgName string, invalid bool) (bool, error) {
return false, nil
}

ds.GetABMTokenOrgNamesAssociatedWithTeamFunc = func(ctx context.Context, teamID *uint) ([]string, error) {
return []string{"foobar"}, nil
Expand Down
6 changes: 6 additions & 0 deletions cmd/fleetctl/fleetctl/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,9 @@ func TestApplyAsGitOps(t *testing.T) {
ds.CountABMTokensWithTermsExpiredFunc = func(ctx context.Context) (int, error) {
return 0, nil
}
ds.SetABMTokenInvalidForOrgNameFunc = func(ctx context.Context, orgName string, invalid bool) (bool, error) {
return false, nil
}

ds.GetABMTokenOrgNamesAssociatedWithTeamFunc = func(ctx context.Context, teamID *uint) ([]string, error) {
return []string{"foobar"}, nil
Expand Down Expand Up @@ -2378,6 +2381,9 @@ func TestApplyMacosSetup(t *testing.T) {
ds.CountABMTokensWithTermsExpiredFunc = func(ctx context.Context) (int, error) {
return 0, nil
}
ds.SetABMTokenInvalidForOrgNameFunc = func(ctx context.Context, orgName string, invalid bool) (bool, error) {
return false, nil
}

ds.GetABMTokenOrgNamesAssociatedWithTeamFunc = func(ctx context.Context, teamID *uint) ([]string, error) {
return []string{"foobar"}, nil
Expand Down
3 changes: 2 additions & 1 deletion ee/server/service/apple_mdm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,10 @@ func setupReleaseABTest(t *testing.T) (*Service, *mock.Store, *nanodep_mock.Stor
svc.logger = slog.New(slog.NewTextHandler(io.Discard, nil))
base.NewActivityFunc = func(context.Context, *fleet.User, fleet.ActivityDetails) error { return nil }

// Short-circuit the DEP client's terms-expired after-hook.
// Short-circuit the DEP client's terms-expired and token-invalid after-hooks.
ds.CountABMTokensWithTermsExpiredFunc = func(context.Context) (int, error) { return 0, nil }
ds.AppConfigFunc = func(context.Context) (*fleet.AppConfig, error) { return &fleet.AppConfig{}, nil }
ds.SetABMTokenInvalidForOrgNameFunc = func(context.Context, string, bool) (bool, error) { return false, nil }
ds.DeleteHostDEPAssignmentsFunc = func(context.Context, uint, []string) error { return nil }

dep := &nanodep_mock.Storage{}
Expand Down
3 changes: 3 additions & 0 deletions ee/server/service/mdm_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ func TestGetOrCreatePreassignTeam(t *testing.T) {
ds.CountABMTokensWithTermsExpiredFunc = func(ctx context.Context) (int, error) {
return 0, nil
}
ds.SetABMTokenInvalidForOrgNameFunc = func(ctx context.Context, orgName string, invalid bool) (bool, error) {
return false, nil
}
ds.ConditionalAccessMicrosoftGetFunc = func(ctx context.Context) (*fleet.ConditionalAccessMicrosoftIntegration, error) {
return nil, &eeservice.NotFoundError{}
}
Expand Down
6 changes: 6 additions & 0 deletions frontend/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ const App = ({ children, location, router }: IAppProps): JSX.Element => {
needsAbmTermsRenewal: ab_tokens.some(
(token) => token.terms_expired
),
hasAbmTokenInvalid: ab_tokens.some((token) => token.token_invalid),
invalidAbmTokenOrgNames: ab_tokens
.filter((token) => token.token_invalid)
.map((token) => token.org_name),
});
},
// TODO: Do we need to catch and check for a 400 status code? The old
Expand All @@ -146,6 +150,8 @@ const App = ({ children, location, router }: IAppProps): JSX.Element => {
setABMExpiry({
earliestExpiry: GUARANTEED_PAST_DATE,
needsAbmTermsRenewal: true, // TODO: if order of precedence for banners changes, we may need to upate this
hasAbmTokenInvalid: false,
invalidAbmTokenOrgNames: [],
});
}
},
Expand Down
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();
});
});
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./AppleBMTokenInvalidMessage";
7 changes: 7 additions & 0 deletions frontend/components/MainContent/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { hasLicenseExpired } from "utilities/helpers";
import { AppContext } from "context/app";

import AppleBMTermsMessage from "components/MDM/AppleBMTermsMessage";
import AppleBMTokenInvalidMessage from "components/MDM/AppleBMTokenInvalidMessage";
import LicenseExpirationBanner from "components/LicenseExpirationBanner";
import ApplePNCertRenewalMessage from "components/MDM/ApplePNCertRenewalMessage";
import AppleBMRenewalMessage from "components/MDM/AppleBMRenewalMessage";
Expand Down Expand Up @@ -43,6 +44,8 @@ const MainContent = ({
isAppleBmExpired,
isVppExpired,
needsAbmTermsRenewal,
hasAbmTokenInvalid,
invalidAbmTokenOrgNames,
willAppleBmExpire,
willApplePnsExpire,
willVppExpire,
Expand All @@ -68,6 +71,10 @@ const MainContent = ({
banner = <AppleBMRenewalMessage expired={isAppleBmExpired} />;
} else if (needsAbmTermsRenewal) {
banner = <AppleBMTermsMessage />;
} else if (hasAbmTokenInvalid) {
banner = (
<AppleBMTokenInvalidMessage orgNames={invalidAbmTokenOrgNames} />
);
} else if (isVppExpired || willVppExpire) {
banner = <VppRenewalMessage expired={isVppExpired} />;
} else if (isFleetLicenseExpired) {
Expand Down
6 changes: 6 additions & 0 deletions frontend/components/MainContent/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
// TODO: figure out if sticky styling is needed?
position: sticky; // Needed for settings page scroll
z-index: 4; // Needed for settings page scroll

// The AB token invalid banner sits directly above page content that
// already provides its own top spacing, so it doesn't need this margin.
&:has(.apple-bm-token-invalid-message) {
margin-bottom: 0;
}
}

&.manage-hosts,
Expand Down
48 changes: 0 additions & 48 deletions frontend/context/app.tests.ts

This file was deleted.

113 changes: 113 additions & 0 deletions frontend/context/app.tests.tsx
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."
);
});
});
Loading
Loading