Trending

World technology news

→
Keeping a SCIM inventory scan going after a short page
Software Engineering · 2025
Software Engineering2025

Keeping a SCIM inventory scan going after a short page

Try the SCIM cursor rules from RFC 9865 with synthetic directory responses. Distinguish a short page from the final page and surface an interrupted scan.

Archive retrospective · Topic year 2025

Developer's JournalPublished: Dec 5, 20266 min read
Reading progress0%
In this article
  1. A short directory page can hide missing accounts
  2. Keep the filter and selected attributes fixed
  3. Choose index or cursor at the start
  4. Follow three short pages on a current Node runtime
  5. Treat a cursor failure as an interrupted scan
  6. Build an acceptance check around progress

A short directory page can hide missing accounts

Before a directory migration, an application team builds an inventory of active accounts. It reads pages in sequence and writes each provider-assigned identifier to a review file. Suppose it asks for three rows and the server sends two. If the collector stops because the response is short, the review file can appear complete even though it holds only the first page. HTTP success on that request gives the operations team little reason to look for a connection problem. The 2015 SCIM protocol in RFC 7644 defined pagination using result positions. RFC 9865, published in October 2025, extended the same protocol with provider-issued cursors. This example checks whether a scan can follow those cursors when the page sizes vary. The only data collected are resource identifiers, and the directory receives no writes. The output gives the migration reviewer a separate artifact to compare against an expected small inventory.

Keep the filter and selected attributes fixed

The example queries the provider's /scim/v2/Users endpoint. The filter active eq true selects users whose active attribute matches a Boolean value. Sending the word true in quotes would express a string instead. The attributes parameter requests id and active so the fixture can show which fields the collector expects. A real server can also return fields that the resource schema designates as always returned. The collection job needs the identifier for its report, so it can avoid persisting the rest of the response. Filtering is optional in SCIM and its availability can be checked through the provider configuration document. A rejected query should surface as an error rather than an empty result. URLSearchParams handles the encoding of the filter and the comma in the projection. Each continuation keeps the endpoint, filter, selected attributes and count fixed. Only the cursor value comes from the latest response.

Software delivery pipelineConceptual sketch · summary of the article's technical flow

Choose index or cursor at the start

With index pagination, startIndex begins at one and count requests an upper bound for the number of results on a page. Separate requests may see a changing result set. A record inserted ahead of the current position can cause a previous entry to move into a later page. A removal can shift an unseen record backward. The cursor extension lets the provider hand the client its own continuation value. The consumer treats that value as opaque. The existence of a cursor does not establish that the underlying search is an immutable snapshot. If a provider supports both kinds of pagination, an explicit empty cursor can select the cursor method on the first request. Follow-up requests keep the selected method rather than introducing startIndex or adjusting count. A client with distinct paths for the two styles can keep serving older indexed endpoints while adding support for cursor responses.

Follow three short pages on a current Node runtime

The local test uses Node.js v24.19.0 and in-memory response fixtures. The fixture verifies the request path and the fixed values on every call. The first request has an empty cursor and count set to three. Its response carries u04 and u17, followed by a continuation value. The next call returns u23 and a different continuation. The final call returns u40 and u55 and omits nextCursor entirely. The recorded page lengths were two, one and two, for five distinct identifiers. All responses omit totalResults. RFC 9865 permits that omission when a cursor provider cannot estimate the total. The core loop shown below reaches the third page even though neither of the first two pages reaches the requested count. The complete local test also checks the response schema, whether each resource has an identifier, whether a cursor is well formed and whether a page limit has been exceeded.

async function collectIds(fetchPage) {
  const ids = new Set();
  const seenCursors = new Set();
  let cursor = '';
  for (let pageNumber = 1; pageNumber <= 20; pageNumber++) {
    const url = new URL(base);
    url.searchParams.set('cursor', cursor);
    const response = await fetchPage(url);
    const page = await response.json();
    if (!response.ok) throw Error('SCIM ' + response.status + ' ' + page.scimType);
    if (!page.schemas?.includes(responseSchema)) throw Error('Missing ListResponse schema');
    for (const resource of page.Resources ?? []) {
      if (!resource.id) throw Error('Resource without id');
      ids.add(resource.id);
    }
    if (!Object.hasOwn(page, 'nextCursor')) return [...ids];
    if (typeof page.nextCursor !== 'string' || !/^[A-Za-z0-9._~-]+$/.test(page.nextCursor)) {
      throw Error('Invalid nextCursor format');
    }
    if (seenCursors.has(page.nextCursor)) throw Error('Repeated nextCursor');
    seenCursors.add(page.nextCursor);
    cursor = page.nextCursor;
  }
  throw Error('Page limit exceeded');
}

Treat a cursor failure as an interrupted scan

The loop stays incomplete when the provider rejects a continuation. A separate fixture returned the same synthetic value, loop-token, for two responses. The collector rejected the repeated value before requesting it a second time. Another fixture returned HTTP 400 with expiredCursor, which the program surfaced as a distinct error. Both outcomes can therefore be distinguished from a successful search with zero matches. The example stores the resource IDs in a Set and publishes its result only after it reaches the last page. RFC 7643 defines id as a persistent provider-assigned resource identifier, which makes it a suitable basis for deduplicating one collection. Deduplication still cannot recover an entry the collection never observed. Where a migration needs a consistent snapshot, check the provider's documented export guarantees. On expiration, restart the attempt according to the provider's rules and keep its partial output separate from a completed run.

Build an acceptance check around progress

Start a migration check with a small fixture whose expected identities are known. Freeze the filter and include a response with fewer entries than requested. For each page, record the number returned, the number of distinct identifiers accumulated and the presence of a continuation. These three observations show where an incomplete run stopped. A live log does not need raw cursor values. The values in the illustrative output are invented. Query filters can also contain personal data, so record the fields needed to diagnose the traversal. When the provider offers both modes, exercise the old index client independently before enabling the cursor path. A useful acceptance run shows that the collector continues after a short page, reads the terminal page once and reports an expired cursor as an error. The in-memory run establishes the local program's behavior. Repeat the same scenario with the chosen provider in its test environment to verify its response and configuration.

320 reads ✎ Write a comment

Reader discussion

Discussion prompt

How would you measure this development's real-world impact?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.