Skip to content

Commit d328048

Browse files
committed
chore: doc + rename
1 parent a7eb2e0 commit d328048

File tree

4 files changed

+144
-13
lines changed

4 files changed

+144
-13
lines changed

deploy-ci-version.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ echo "$OUTPUT"
4242

4343
# Parse the deployment information
4444
WORKER_VERSION_ID=$(echo "$OUTPUT" | grep "Worker Version ID:" | sed 's/.*Worker Version ID: //')
45-
VERSION_PREVIEW_URL=$(echo "$OUTPUT" | grep "Version Preview URL:" | sed 's/.*Version Preview URL: //')
45+
WORKER_PREVIEW_URL=$(echo "$OUTPUT" | grep "Version Preview URL:" | sed 's/.*Version Preview URL: //')
4646

4747
# Write to a file that can be sourced (for local use)
4848
cat > .deployment-env << EOF
4949
export WORKER_VERSION_ID="$WORKER_VERSION_ID"
50-
export VERSION_PREVIEW_URL="$VERSION_PREVIEW_URL"
51-
export VERSION_PREVIEW_BRANCH="$BRANCH"
50+
export WORKER_PREVIEW_URL="$WORKER_PREVIEW_URL"
51+
export WORKER_PREVIEW_BRANCH="$BRANCH"
5252
EOF
5353

5454
# If running in GitHub Actions, also write to GITHUB_ENV
5555
if [ -n "$GITHUB_ENV" ]; then
5656
echo "WORKER_VERSION_ID=$WORKER_VERSION_ID" >> "$GITHUB_ENV"
57-
echo "VERSION_PREVIEW_URL=$VERSION_PREVIEW_URL" >> "$GITHUB_ENV"
58-
echo "VERSION_PREVIEW_BRANCH=$BRANCH" >> "$GITHUB_ENV"
57+
echo "WORKER_PREVIEW_URL=$WORKER_PREVIEW_URL" >> "$GITHUB_ENV"
58+
echo "WORKER_PREVIEW_BRANCH=$BRANCH" >> "$GITHUB_ENV"
5959
echo "Variables exported to GitHub Actions environment"
6060
fi
6161

@@ -67,7 +67,7 @@ echo "Version deployment complete!"
6767
echo "----------------------------------------"
6868
echo "Deployment information: (copy inside a .deployment-env file to run locally)"
6969
echo "export WORKER_VERSION_ID=$WORKER_VERSION_ID"
70-
echo "export VERSION_PREVIEW_URL=$VERSION_PREVIEW_URL"
71-
echo "export VERSION_PREVIEW_BRANCH=$BRANCH"
70+
echo "export WORKER_PREVIEW_URL=$WORKER_PREVIEW_URL"
71+
echo "export WORKER_PREVIEW_BRANCH=$BRANCH"
7272
echo "----------------------------------------"
7373

integration-tests.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# Integration Tests
2+
3+
The `da-admin` worker includes a suite of integration tests designed as "smoke tests". These tests validate:
4+
5+
- **Deployment Integrity**: Ensures the worker can be successfully deployed to the Cloudflare Workers runtime.
6+
- **Core Functionality**: Verifies critical features such as authentication, read/write operations, and permission handling function correctly end-to-end.
7+
8+
## Architecture
9+
10+
The test entry point is [`./test/it/smoke.test.js`](./test/it/smoke.test.js), which sets up the environment and executes the test suite defined in [`./test/it/it-tests.js`](./test/it/it-tests.js). The tests can run in two modes:
11+
12+
1. **Local Mode**: Runs entirely on the local machine using mocks and local servers.
13+
2. **Stage Mode**: Runs against a deployed version of the worker on Cloudflare (used in CI).
14+
15+
### 1. Local Mode
16+
17+
**Local Mode** is the default for development. It orchestrates a local environment consisting of:
18+
- **`wrangler dev`**: Runs the `da-admin` worker locally.
19+
- **`S3rver`**: A local S3-compatible object storage server to mock R2/S3.
20+
- **Mock IMS Server**: A local HTTP server simulating Adobe IMS for authentication.
21+
22+
**Configuration:**
23+
- Environment variables are automatically loaded from [`./.dev.vars.it`](./.dev.vars.it).
24+
- No manual configuration is typically required.
25+
- **Note**: In **Local Mode**, the DA configuration is ephemeral and set up before each test run.
26+
27+
**How to Run:**
28+
```bash
29+
npm run test:it
30+
```
31+
32+
### 2. Stage Mode (CI/CD)
33+
34+
In **Stage Mode**, tests execute against a live worker deployed to Cloudflare. This verifies the actual deployment artifacts and Cloudflare environment behavior.
35+
36+
#### CI/CD Pipeline Flow
37+
38+
The GitHub Actions workflow executes these tests in two phases:
39+
40+
1. **Deployment**:
41+
- `npm run deploy:ci`: Uploads a new version of the worker (tagged with the branch name) to the `ci` environment.
42+
- Generates a `.deployment-env` file containing the `WORKER_VERSION_ID`, `WORKER_PREVIEW_URL` and `WORKER_PREVIEW_BRANCH`.
43+
44+
2. **Verification**:
45+
- `npm run test:postdeploy`: Sources the `.deployment-env` file and runs the test suite.
46+
- When `WORKER_PREVIEW_URL` is present in the environment, [`smoke.test.js`](./test/it/smoke.test.js) switches to **Stage Mode**.
47+
- Tests authenticates against a real IMS environment (Stage/Prod) and requests are sent to the deployed worker.
48+
49+
#### Running Stage Tests Locally
50+
51+
To debug CI failures or test against a deployed worker from your local machine:
52+
53+
1. **Deploy the Worker**:
54+
```bash
55+
npm run deploy:ci
56+
```
57+
This script will generate the `.deployment-env` file in your root directory.
58+
59+
2. **Configure Credentials**:
60+
Create a `.env` file (or set environment variables) with the required IMS credentials for the test account:
61+
```env
62+
IT_IMS_STAGE_ENDPOINT=https://ims-na1.adobelogin.com
63+
IT_IMS_STAGE_CLIENT_ID=<client-id>
64+
IT_IMS_STAGE_CLIENT_SECRET=<client-secret>
65+
IT_IMS_STAGE_SCOPES=openid,AdobeID,aem.frontend.all,read_organizations,additional_info.projectedProductContext
66+
```
67+
68+
3. **Run the Tests**:
69+
```bash
70+
# Loads the deployment vars and runs the tests
71+
npm run test:postdeploy2
72+
```
73+
74+
### Persistence & Configuration
75+
76+
In **Stage Mode**, the tests rely on the `DA_CONFIG_STAGE` KV storage for permissions. This configuration is persistent.
77+
78+
If the configuration is lost or needs to be reset, the expected permission model is:
79+
80+
```json
81+
{
82+
"total": 2,
83+
"limit": 2,
84+
"offset": 0,
85+
"data": [
86+
{
87+
"path": "CONFIG",
88+
"groups": "<test-user-email>",
89+
"actions": "write"
90+
},
91+
{
92+
"path": "/+**",
93+
"groups": "<test-user-email>",
94+
"actions": "write"
95+
}
96+
],
97+
":type": "sheet",
98+
":sheetname": "permissions"
99+
}
100+
```
101+
102+
## IMS Configuration
103+
104+
In **Stage Mode**, tests execute against the **IMS Stage** environment.
105+
106+
### Prerequisites
107+
108+
1. **Worker Configuration**: The `IMS_ORIGIN` secret for the `da-admin` worker (CI environment) must point to the IMS Stage endpoint.
109+
2. **User Existence**: Test users must exist and belong to an IMS Stage organization. No specific organization permissions are required beyond basic membership.
110+
3. **DA Configuration**: The test users must be explicitly granted permissions in the `DA_CONFIG` (as shown in the [Persistence & Configuration](#persistence--configuration) section).
111+
112+
### Test Users Setup
113+
114+
The integration tests use dedicated service accounts defined in the [Adobe Stage Developer Console](https://developer-stage.adobe.com/) under the `Document Authoring Stage` organization. Two distinct projects were created to simulate different user roles:
115+
116+
- **Authenticated User Project**:
117+
- **Purpose**: Simulates a user who is logged in but may not have specific permissions (used for negative testing or basic access).
118+
- **Credentials**: Defined in CI secrets as `IT_IMS_STAGE_CLIENT_ID` / `IT_IMS_STAGE_CLIENT_SECRET`.
119+
- **API**: Uses `Edge Delivery Service` to create OAuth Server-to-Server credentials.
120+
121+
- **Authorized User Project**:
122+
- **Purpose**: Simulates a user with full read/write permissions.
123+
- **Credentials**: (Currently the tests primarily use one set of credentials which are authorized in the config).
124+
- **API**: Uses `Edge Delivery Service` to create OAuth Server-to-Server credentials.
125+
126+
> **Notes on Setup:**
127+
> 1. **Multiple Projects**: Two separate projects were created because generating multiple independent credentials within a single project was not supported.
128+
> 2. **Role Distinction**: The distinction between "authenticated" and "authorized" is managed entirely within the `DA_CONFIG` permissions sheet, not in IMS. The project naming reflects the intended use case.
129+
> 3. **API Selection**: The `Edge Delivery Service` API was selected for convenience. Any API service can be used provided it:
130+
> - Supports IMS connection.
131+
> - Includes the `read_organizations` scope.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"test": "c8 mocha --spec=test/**/*.test.js --ignore=test/it/**/*.test.js",
1616
"test:it": "mocha test/it/**/*.test.js",
1717
"test:all": "npm run test && npm run test:it",
18-
"test:postdeploy": "if [ -f .deployment-env ]; then . ./.deployment-env && rm .deployment-env; fi && npm run test:it",
18+
"test:postdeploy": "if [ -f .deployment-env ]; then . ./.deployment-env; fi && npm run test:it",
1919
"dev": "wrangler dev -e dev",
2020
"deploy:ci": "./deploy-ci-version.sh ci",
2121
"deploy:prod": "node prepare-deploy.js && wrangler deploy -e production -c wrangler-versioned.toml",

test/it/smoke.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,17 @@ describe('Integration Tests: smoke tests', function () {
207207
// Increase timeout for server startup
208208
this.timeout(30000);
209209

210-
if (process.env.VERSION_PREVIEW_URL) {
210+
if (process.env.WORKER_PREVIEW_URL) {
211211
if (!IMS_STAGE.ENDPOINT || !IMS_STAGE.CLIENT_ID
212212
|| !IMS_STAGE.CLIENT_SECRET || !IMS_STAGE.SCOPES) {
213213
throw new Error('IT_IMS_STAGE_ENDPOINT, IT_IMS_STAGE_CLIENT_ID, '
214214
+ 'IT_IMS_STAGE_CLIENT_SECRET, and IT_IMS_STAGE_SCOPES must be set');
215215
}
216216

217-
context.serverUrl = process.env.VERSION_PREVIEW_URL;
218-
const branch = process.env.VERSION_PREVIEW_BRANCH;
217+
context.serverUrl = process.env.WORKER_PREVIEW_URL;
218+
const branch = process.env.WORKER_PREVIEW_BRANCH;
219219
if (!branch) {
220-
throw new Error('VERSION_PREVIEW_BRANCH must be set');
220+
throw new Error('WORKER_PREVIEW_BRANCH must be set');
221221
}
222222
context.repo += `-${branch.toLowerCase().replace(/[ /_]/g, '-')}`;
223223
context.accessToken = await connectToIMSStage();
@@ -238,7 +238,7 @@ describe('Integration Tests: smoke tests', function () {
238238
});
239239

240240
after(async function () {
241-
if (process.env.VERSION_PREVIEW_URL) {
241+
if (process.env.WORKER_PREVIEW_URL) {
242242
return;
243243
}
244244

0 commit comments

Comments
 (0)