> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# SCIM Test Cases

This page contains the tests that are done by Edupass for SCIM onboarding.<br>It should cover:

1. What resources are created during the test
2. What is being tested in the test
3. What is expected from each request in the test

***

## Overview

The suite runs two groups of tests against the RP's SCIM base URL:

1. **JWT Authentication** – the RP correctly rejects invalid/missing tokens.
2. **SCIM Operations** – the RP correctly implements User and Group CRUD, membership (including full replace), concurrency, error handling, and SCIM discovery endpoints (`ResourceTypes`, `ServiceProviderConfig`).

Every request is authenticated with a signed Edupass JWT (issuer = the configured Edupass issuer, audience = the RP's `appCode`, TTL 900s), except the authentication tests which deliberately send missing/invalid tokens.

**Group and Group-membership tests only run if the RP exposes the Group schema at `GET /Schemas`.**

***

## Resources created during the test

All test resources use fixed identifiers so they are recognisable in RP logs. Every resource is deleted before the run finishes (nothing should persist if the run completes). The suite also pre-cleans these identifiers before it starts, so a previous interrupted run cannot block the next one.

| Resource                   | Identifier / externalId | name                | Purpose                                                                           |
| -------------------------- | ----------------------- | ------------------- | --------------------------------------------------------------------------------- |
| Test user 1                | `999900000001`          | Test User 001       | Create / Update / Patch / Add group membership / Remove group membership / Delete |
| Test user 2                | `999900000002`          | Test User 002       | Create / Update / Add group membership / Delete                                   |
| Concurrent-duplicate user  | `999900000099`          | Test User 001       | Concurrency test; deleted immediately                                             |
| Test group 1               | `X_<APPCODE>_TEST1`     | `X_<APPCODE>_TEST1` | Create / Update group membership / Delete                                         |
| Test group 2               | `X_<APPCODE>_TEST2`     | `X_<APPCODE>_TEST2` | Create / Replace group membership / Delete                                        |
| Concurrent-duplicate group | `X_<APPCODE>_DUP`       | `X_<APPCODE>_DUP`   | Concurrency test; deleted immediately                                             |

`<APPCODE>` is the RP's app code (e.g. `RBS`).

## Request payloads

The exact request bodies sent when creating each resource. Which optional fields appear depends on what the RP advertises at `GET /Schemas` – fields the RP does not declare are omitted. The bodies below show the full schema variant (core User schema plus the Edupass User extension).

### User 1 – `POST /Users`

```json
{
  "schemas": [
    "urn:ietf:params:scim:schemas:core:2.0:User",
    "urn:ietf:params:scim:schemas:extension:Edupass:2.0:User"
  ],
  "userName": "999900000001",
  "externalId": "999900000001",
  "name": { "formatted": "Test User 001" },
  "title": "Test Title",
  "emails": [
    { "primary": true, "type": "WOG", "value": "test001@test.gov.sg" }
  ],
  "urn:ietf:params:scim:schemas:extension:Edupass:2.0:User": {
    "identitySource": "HRPS",
    "identityType": "Staff",
    "uinFin": null,
    "schoolOrHq": "School"
  }
}
```

### User 2 – `POST /Users`

```json
{
  "schemas": [
    "urn:ietf:params:scim:schemas:core:2.0:User",
    "urn:ietf:params:scim:schemas:extension:Edupass:2.0:User"
  ],
  "userName": "999900000002",
  "externalId": "999900000002",
  "name": { "formatted": "Test User 002" },
  "title": "Test Title",
  "emails": [
    { "primary": true, "type": "WOG", "value": "test002@test.gov.sg" }
  ],
  "urn:ietf:params:scim:schemas:extension:Edupass:2.0:User": {
    "identitySource": "MIMS",
    "identityType": "Staff",
    "uinFin": null,
    "schoolOrHq": "School"
  }
}
```

The concurrent-duplicate user (`999900000099`) uses an identical body to User 1 with `userName` / `externalId` set to `999900000099`.

### Group – `POST /Groups`

```json
{
  "schemas": ["urn:ietf:params:scim:schemas:core:2.0:Group"],
  "externalId": "X_<APPCODE>_TEST1",
  "displayName": "X_<APPCODE>_TEST1"
}
```

***

## 1. JWT Authentication tests

Each test calls `GET /Users` with a different token. All are expected to return **HTTP 401**.

| # | Test case        | Request                                                                | Expected |
| - | ---------------- | ---------------------------------------------------------------------- | -------- |
| 1 | No auth token    | `GET /Users` with no `Authorization` header                            | 401      |
| 2 | Unsigned JWT     | `GET /Users` with a token using `alg: none` and an empty signature     | 401      |
| 3 | Expired token    | `GET /Users` with a correctly-signed token whose `exp` is in the past  | 401      |
| 4 | Invalid issuer   | `GET /Users` with a signed token whose `iss` is not the Edupass issuer | 401      |
| 5 | Invalid audience | `GET /Users` with a signed token whose `aud` is not the RP's appCode   | 401      |

## 2. SCIM Operation tests

Tests are run in the order below. All tests are run if possible.

### Setup

- `GET /Schemas` – read advertised schemas; determines whether Group tests run.
- `GET /ResourceTypes` – read the resource types the RP advertises; expect `User` present (and `Group` if the Group schema is exposed).
- `GET /ServiceProviderConfig` – read the RP’s service provider configuration; expect `patch.supported == true`.
- **Pre-clean** – for each fixed identifier, `GET` by `userName`/`displayName` and `DELETE` any match left over from a prior run.

### Test 1a – Concurrent duplicate user

- Two **simultaneous** `POST /Users` for user `999900000099` (identical body).
- **Expected:** exactly one succeeds (2xx) and one returns **409 Conflict**. Not both success (duplicate accepted); not both failed.
- Cleanup: `DELETE /Users/{id}` for whichever succeeded.

:::info

This tests whether the RP’s server is safe under concurrent / duplicate requests, which may occur in the event of network retries or issues.

:::

### Test 1 – Create User

- `POST /Users` for `999900000001` → expect 2xx.
- `POST /Users` for `999900000002` → expect 2xx.
- `GET /Users?filter=userName eq "999900000001"` → expect exactly 1 result with matching `externalId`.
- Same GET for `999900000002`.

### Test 2 – Update User

- `PUT /Users/{user1Id}` setting the full name to "Test User 001 Updated" → expect 2xx.
- `GET /Users/{user1Id}` → expect `name.formatted == "Test User 001 Updated"`.

:::info

This is not run if the user was not found by `GET /Users?filter=userName eq "999900000001"` above.

:::

### Test 2a – Patch User

- `PATCH /Users/{user1Id}` with `op: replace`, `path: name.formatted`, value "Test User 001 Patched" → expect 2xx/204.
- `GET /Users/{user1Id}` → expect `name.formatted == "Test User 001 Patched"`.

### Test 2b – Get non-existent User

- `GET /Users/non-existent-user-id` → expect **404**.

### Test 2c – Update non-existent User

- `PUT /Users/non-existent-user-id` → expect **404**.

_The following group tests only run if the RP exposes the Group schema:_

### Test 3a – Concurrent duplicate group

- Two **simultaneous** `POST /Groups` for `X_<APPCODE>_DUP`.
- **Expected:** exactly one 2xx and one **409**. Cleanup: delete the winner.

### Test 3 – Create Group

- `POST /Groups` for `X_<APPCODE>_TEST1` and `X_<APPCODE>_TEST2` → expect 2xx each.
- `GET /Groups?filter=displayName eq "..."` for each → expect exactly 1 result with matching `externalId`.

### Test 3b – Get non-existent Group

- `GET /Groups/non-existent-group-id` → expect **404**.

### Test 3c – Update memberships for non-existent Group

- `PATCH /Groups/non-existent-group-id` (add member) → expect **404**.

### Test 4 – Add Group membership

- `PATCH /Groups/{group1Id}` with `op: add`, `path: members`, adding both users → expect 2xx.
- Verified bidirectionally via `GET` on each user and the group:
  - Each user's `groups` array contains `group1Id`.
  - The group's `members` array contains both `user1Id` and `user2Id`.

### Test 5 – Remove Group membership

- `PATCH /Groups/{group1Id}` with `op: remove`, `path: members[value eq "{user1Id}"]` (remove user 1 only) → expect 2xx.
- **Expected:** user 1 no longer in group and no longer in `members`; user 2 **still** in group and **still** in `members` (removing one member must not drop the other).
- Then `PATCH` remove user 2 → expect 2xx (cleanup).

### Test 5a – Replace Group membership (full replace)

- `PATCH /Groups/{group2Id}` with `op: replace`, `path: members`, setting the full member list to `[user1Id, user2Id]` in one call → expect 2xx/204.
- **Expected:** `GET /Groups/{group2Id}` shows exactly user 1 and user 2 as members (group 2 had no members beforehand – this is a full replace, not an incremental add).
- `PATCH /Groups/{group2Id}` with `op: replace`, `path: members`, value `[]` → expect 2xx/204.
- **Expected:** `GET /Groups/{group2Id}` shows an empty `members` list – confirms a `replace` can clear membership.

### Test 6 – Delete Group

- `DELETE /Groups/{group1Id}` → expect 2xx.
- `GET /Groups` → expect group 1 absent, group 2 still present.
- `DELETE /Groups/{group2Id}` → expect 2xx.

### Test 7 – Delete User (Runs at the end)

- `DELETE /Users/{user1Id}` → expect 2xx.
- `GET /Users` → expect user 1 absent, user 2 still present.
- `DELETE /Users/{user2Id}` → expect 2xx.
