@rikalabs/akter 0.1.0-alpha.0 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -3
- package/README.md +2 -2
- package/dist/actor/definition.d.ts +13 -9
- package/dist/actor/descriptor.d.ts +2 -2
- package/dist/actor/descriptor.js +4 -4
- package/dist/client/calls.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/errors/actor.d.ts +12 -42
- package/dist/errors/actor.js +13 -42
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/members/payload.d.ts +1 -1
- package/dist/protocol/inspection.d.ts +221 -1
- package/dist/protocol/inspection.js +151 -2
- package/dist/protocol/wire.d.ts +6 -49
- package/dist/protocol/wire.js +1 -10
- package/dist/runtime/actors.d.ts +3 -0
- package/dist/runtime/adoption/backfill.js +1 -1
- package/dist/runtime/adoption/enforce.js +2 -2
- package/dist/runtime/adoption/observe.js +1 -1
- package/dist/runtime/adoption/plan.d.ts +1 -1
- package/dist/runtime/adoption/startup.js +1 -1
- package/dist/runtime/adoption/status.d.ts +1 -1
- package/dist/runtime/app.d.ts +65 -0
- package/dist/runtime/app.js +38 -0
- package/dist/runtime/connections/holder.d.ts +11 -1
- package/dist/runtime/connections/holder.js +8 -4
- package/dist/runtime/connections/streams.d.ts +4 -4
- package/dist/runtime/content/store.js +15 -11
- package/dist/runtime/database/bounded.d.ts +4 -18
- package/dist/runtime/database/bounded.js +36 -22
- package/dist/runtime/database/coordination.d.ts +12 -3
- package/dist/runtime/database/coordination.js +29 -36
- package/dist/runtime/database/migrations.d.ts +61 -29
- package/dist/runtime/database/migrations.js +375 -139
- package/dist/runtime/database/replica.d.ts +4 -1
- package/dist/runtime/database/replica.js +4 -1
- package/dist/runtime/database/schema.d.ts +13 -0
- package/dist/runtime/database/schema.js +13 -0
- package/dist/runtime/database/shards.d.ts +31 -13
- package/dist/runtime/database/shards.js +38 -26
- package/dist/runtime/entity/register.d.ts +8 -1
- package/dist/runtime/entity/register.js +58 -7
- package/dist/runtime/fleet/checks.js +4 -4
- package/dist/runtime/fleet/maintainer.d.ts +1 -1
- package/dist/runtime/fleet/maintainer.js +1 -1
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/inspector/layer.d.ts +20 -0
- package/dist/runtime/inspector/layer.js +224 -5
- package/dist/runtime/inspector/queries.d.ts +54 -8
- package/dist/runtime/inspector/queries.js +84 -15
- package/dist/runtime/layer.d.ts +48 -39
- package/dist/runtime/layer.js +124 -56
- package/dist/runtime/operators/audit.d.ts +3 -0
- package/dist/runtime/operators/audit.js +6 -2
- package/dist/runtime/operators/repair.js +30 -10
- package/dist/runtime/operators/seed.js +4 -2
- package/dist/runtime/payloads/versions.d.ts +4 -4
- package/dist/runtime/payloads/versions.js +24 -15
- package/dist/runtime/queries.js +4 -2
- package/dist/runtime/registration.d.ts +5 -2
- package/dist/runtime/registration.js +3 -3
- package/dist/runtime/runner.d.ts +12 -0
- package/dist/runtime/runner.js +12 -0
- package/dist/runtime/storage/codec.d.ts +19 -7
- package/dist/runtime/storage/codec.js +23 -7
- package/dist/runtime/storage/placements.d.ts +6 -1
- package/dist/runtime/storage/placements.js +98 -6
- package/dist/runtime/storage/retention.d.ts +6 -0
- package/dist/runtime/storage/retention.js +25 -13
- package/dist/runtime/subscriptions/relay.js +47 -44
- package/dist/runtime/subscriptions/storage.d.ts +3 -2
- package/dist/runtime/subscriptions/storage.js +9 -6
- package/dist/runtime/telemetry/live.d.ts +255 -0
- package/dist/runtime/telemetry/live.js +540 -0
- package/dist/runtime/telemetry/metrics.d.ts +2 -0
- package/dist/runtime/telemetry/metrics.js +4 -1
- package/dist/runtime/telemetry/sampler.js +33 -13
- package/dist/runtime/telemetry/spans.d.ts +1 -1
- package/dist/runtime/telemetry/spans.js +1 -1
- package/dist/runtime/topology/locks.d.ts +6 -3
- package/dist/runtime/topology/locks.js +27 -4
- package/dist/runtime/turn/execute.d.ts +2 -0
- package/dist/runtime/turn/execute.js +5 -2
- package/dist/runtime/turn/pipeline.d.ts +5 -12
- package/dist/runtime/turn/pipeline.js +11 -11
- package/dist/runtime/turn/relay.d.ts +13 -3
- package/dist/runtime/turn/relay.js +27 -14
- package/dist/runtime/turn/rows.js +4 -4
- package/dist/runtime/workflows/compatibility.d.ts +1 -1
- package/dist/runtime/workflows/compatibility.js +85 -31
- package/dist/runtime/workflows/engine.js +20 -17
- package/dist/serve/layer.js +3 -2
- package/dist/tables/owned.d.ts +1 -1
- package/dist/tables/owned.js +1 -1
- package/dist/testing/actor-test.d.ts +2 -24
- package/dist/testing/actor-test.js +1 -27
- package/dist/testing/index.d.ts +0 -12
- package/dist/testing/index.js +0 -6
- package/package.json +1 -1
- package/dist/runtime/database/neki/migrations.d.ts +0 -31
- package/dist/runtime/database/neki/migrations.js +0 -276
- package/dist/runtime/database/neki/session.d.ts +0 -23
- package/dist/runtime/database/neki/session.js +0 -31
- package/dist/testing/cluster.d.ts +0 -93
- package/dist/testing/cluster.js +0 -296
- package/dist/testing/conformance/access.d.ts +0 -5
- package/dist/testing/conformance/access.js +0 -531
- package/dist/testing/conformance/admission.d.ts +0 -11
- package/dist/testing/conformance/admission.js +0 -182
- package/dist/testing/conformance/adoption.d.ts +0 -2
- package/dist/testing/conformance/adoption.js +0 -1019
- package/dist/testing/conformance/assertions.d.ts +0 -202
- package/dist/testing/conformance/assertions.js +0 -849
- package/dist/testing/conformance/batches.d.ts +0 -41
- package/dist/testing/conformance/batches.js +0 -388
- package/dist/testing/conformance/blobs.d.ts +0 -14
- package/dist/testing/conformance/blobs.js +0 -405
- package/dist/testing/conformance/capacity.d.ts +0 -8
- package/dist/testing/conformance/capacity.js +0 -433
- package/dist/testing/conformance/client.d.ts +0 -5
- package/dist/testing/conformance/client.js +0 -719
- package/dist/testing/conformance/cold-serve.d.ts +0 -16
- package/dist/testing/conformance/cold-serve.js +0 -254
- package/dist/testing/conformance/connections/actors.d.ts +0 -1143
- package/dist/testing/conformance/connections/actors.js +0 -180
- package/dist/testing/conformance/connections/harness.d.ts +0 -1754
- package/dist/testing/conformance/connections/harness.js +0 -142
- package/dist/testing/conformance/connections/holders.d.ts +0 -4
- package/dist/testing/conformance/connections/holders.js +0 -165
- package/dist/testing/conformance/connections/lifecycle.d.ts +0 -4
- package/dist/testing/conformance/connections/lifecycle.js +0 -113
- package/dist/testing/conformance/connections/limits.d.ts +0 -4
- package/dist/testing/conformance/connections/limits.js +0 -127
- package/dist/testing/conformance/connections/reauthorization.d.ts +0 -4
- package/dist/testing/conformance/connections/reauthorization.js +0 -170
- package/dist/testing/conformance/connections/resync.d.ts +0 -4
- package/dist/testing/conformance/connections/resync.js +0 -360
- package/dist/testing/conformance/connections/takeover.d.ts +0 -4
- package/dist/testing/conformance/connections/takeover.js +0 -287
- package/dist/testing/conformance/connections.d.ts +0 -4
- package/dist/testing/conformance/connections.js +0 -15
- package/dist/testing/conformance/content-blobs.d.ts +0 -16
- package/dist/testing/conformance/content-blobs.js +0 -534
- package/dist/testing/conformance/counter.d.ts +0 -16
- package/dist/testing/conformance/counter.js +0 -813
- package/dist/testing/conformance/cron.d.ts +0 -5
- package/dist/testing/conformance/cron.js +0 -665
- package/dist/testing/conformance/drain.d.ts +0 -26
- package/dist/testing/conformance/drain.js +0 -540
- package/dist/testing/conformance/effect-control.d.ts +0 -38
- package/dist/testing/conformance/effect-control.js +0 -1059
- package/dist/testing/conformance/effects.d.ts +0 -23
- package/dist/testing/conformance/effects.js +0 -432
- package/dist/testing/conformance/events.d.ts +0 -28
- package/dist/testing/conformance/events.js +0 -335
- package/dist/testing/conformance/export.d.ts +0 -2
- package/dist/testing/conformance/export.js +0 -368
- package/dist/testing/conformance/fleet.d.ts +0 -444
- package/dist/testing/conformance/fleet.js +0 -1009
- package/dist/testing/conformance/groups.d.ts +0 -7
- package/dist/testing/conformance/groups.js +0 -353
- package/dist/testing/conformance/heap.d.ts +0 -3
- package/dist/testing/conformance/heap.js +0 -149
- package/dist/testing/conformance/http.d.ts +0 -2809
- package/dist/testing/conformance/http.js +0 -1234
- package/dist/testing/conformance/inspection-views.d.ts +0 -8
- package/dist/testing/conformance/inspection-views.js +0 -272
- package/dist/testing/conformance/inspector.d.ts +0 -7
- package/dist/testing/conformance/inspector.js +0 -650
- package/dist/testing/conformance/mint.d.ts +0 -58
- package/dist/testing/conformance/mint.js +0 -692
- package/dist/testing/conformance/multi-runner.d.ts +0 -8
- package/dist/testing/conformance/multi-runner.js +0 -403
- package/dist/testing/conformance/neki/plan.d.ts +0 -19
- package/dist/testing/conformance/neki/plan.js +0 -30
- package/dist/testing/conformance/observability.d.ts +0 -3
- package/dist/testing/conformance/observability.js +0 -343
- package/dist/testing/conformance/offline.d.ts +0 -4
- package/dist/testing/conformance/offline.js +0 -474
- package/dist/testing/conformance/operator-harness.d.ts +0 -57
- package/dist/testing/conformance/operator-harness.js +0 -78
- package/dist/testing/conformance/operator.d.ts +0 -3
- package/dist/testing/conformance/operator.js +0 -379
- package/dist/testing/conformance/outbox-cross-shard.d.ts +0 -14
- package/dist/testing/conformance/outbox-cross-shard.js +0 -160
- package/dist/testing/conformance/outbox.d.ts +0 -36
- package/dist/testing/conformance/outbox.js +0 -437
- package/dist/testing/conformance/payload-migrations.d.ts +0 -3
- package/dist/testing/conformance/payload-migrations.js +0 -612
- package/dist/testing/conformance/pipeline.d.ts +0 -3
- package/dist/testing/conformance/pipeline.js +0 -1040
- package/dist/testing/conformance/placement.d.ts +0 -22
- package/dist/testing/conformance/placement.js +0 -539
- package/dist/testing/conformance/platform.d.ts +0 -40
- package/dist/testing/conformance/platform.js +0 -101
- package/dist/testing/conformance/progress.d.ts +0 -39
- package/dist/testing/conformance/progress.js +0 -666
- package/dist/testing/conformance/properties.d.ts +0 -6
- package/dist/testing/conformance/properties.js +0 -295
- package/dist/testing/conformance/protocols.d.ts +0 -4
- package/dist/testing/conformance/protocols.js +0 -618
- package/dist/testing/conformance/provider/advertise.d.ts +0 -21
- package/dist/testing/conformance/provider/advertise.js +0 -44
- package/dist/testing/conformance/read-your-writes.d.ts +0 -20
- package/dist/testing/conformance/read-your-writes.js +0 -192
- package/dist/testing/conformance/reducers.d.ts +0 -8
- package/dist/testing/conformance/reducers.js +0 -258
- package/dist/testing/conformance/relay.d.ts +0 -42
- package/dist/testing/conformance/relay.js +0 -1115
- package/dist/testing/conformance/restore.d.ts +0 -43
- package/dist/testing/conformance/restore.js +0 -341
- package/dist/testing/conformance/retention.d.ts +0 -14
- package/dist/testing/conformance/retention.js +0 -463
- package/dist/testing/conformance/rls.d.ts +0 -24
- package/dist/testing/conformance/rls.js +0 -576
- package/dist/testing/conformance/simulation.d.ts +0 -31
- package/dist/testing/conformance/simulation.js +0 -167
- package/dist/testing/conformance/single-shard.d.ts +0 -2
- package/dist/testing/conformance/single-shard.js +0 -125
- package/dist/testing/conformance/singleton.d.ts +0 -3
- package/dist/testing/conformance/singleton.js +0 -293
- package/dist/testing/conformance/statements.d.ts +0 -60
- package/dist/testing/conformance/statements.js +0 -108
- package/dist/testing/conformance/streams.d.ts +0 -7
- package/dist/testing/conformance/streams.js +0 -280
- package/dist/testing/conformance/subscriptions/access.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/access.js +0 -98
- package/dist/testing/conformance/subscriptions/actors.d.ts +0 -4910
- package/dist/testing/conformance/subscriptions/actors.js +0 -372
- package/dist/testing/conformance/subscriptions/cluster.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/cluster.js +0 -89
- package/dist/testing/conformance/subscriptions/delivery.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/delivery.js +0 -253
- package/dist/testing/conformance/subscriptions/deploys.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/deploys.js +0 -162
- package/dist/testing/conformance/subscriptions/epochs.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/epochs.js +0 -169
- package/dist/testing/conformance/subscriptions/failures.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/failures.js +0 -108
- package/dist/testing/conformance/subscriptions/feeds.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/feeds.js +0 -218
- package/dist/testing/conformance/subscriptions/harness.d.ts +0 -124
- package/dist/testing/conformance/subscriptions/harness.js +0 -143
- package/dist/testing/conformance/subscriptions/operator.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/operator.js +0 -128
- package/dist/testing/conformance/subscriptions/retention.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/retention.js +0 -288
- package/dist/testing/conformance/subscriptions/routing.d.ts +0 -4
- package/dist/testing/conformance/subscriptions/routing.js +0 -179
- package/dist/testing/conformance/subscriptions.d.ts +0 -4
- package/dist/testing/conformance/subscriptions.js +0 -19
- package/dist/testing/conformance/tables.d.ts +0 -125
- package/dist/testing/conformance/tables.js +0 -664
- package/dist/testing/conformance/transports/actors.d.ts +0 -1907
- package/dist/testing/conformance/transports/actors.js +0 -163
- package/dist/testing/conformance/transports/client.d.ts +0 -3
- package/dist/testing/conformance/transports/client.js +0 -237
- package/dist/testing/conformance/transports/feeds.d.ts +0 -3
- package/dist/testing/conformance/transports/feeds.js +0 -232
- package/dist/testing/conformance/transports/harness.d.ts +0 -93
- package/dist/testing/conformance/transports/harness.js +0 -84
- package/dist/testing/conformance/transports/streams.d.ts +0 -3
- package/dist/testing/conformance/transports/streams.js +0 -96
- package/dist/testing/conformance/transports/websocket.d.ts +0 -3
- package/dist/testing/conformance/transports/websocket.js +0 -384
- package/dist/testing/conformance/transports/wire.d.ts +0 -141
- package/dist/testing/conformance/transports/wire.js +0 -204
- package/dist/testing/conformance/transports.d.ts +0 -3
- package/dist/testing/conformance/transports.js +0 -11
- package/dist/testing/conformance/watch.d.ts +0 -59
- package/dist/testing/conformance/watch.js +0 -879
- package/dist/testing/conformance/workflow-engine.d.ts +0 -97
- package/dist/testing/conformance/workflow-engine.js +0 -253
- package/dist/testing/conformance/workflow-versions.d.ts +0 -3
- package/dist/testing/conformance/workflow-versions.js +0 -545
- package/dist/testing/conformance/workflows/access.d.ts +0 -4
- package/dist/testing/conformance/workflows/access.js +0 -147
- package/dist/testing/conformance/workflows/actors.d.ts +0 -2317
- package/dist/testing/conformance/workflows/actors.js +0 -305
- package/dist/testing/conformance/workflows/basics.d.ts +0 -4
- package/dist/testing/conformance/workflows/basics.js +0 -144
- package/dist/testing/conformance/workflows/engine.d.ts +0 -4
- package/dist/testing/conformance/workflows/engine.js +0 -80
- package/dist/testing/conformance/workflows/guards.d.ts +0 -4
- package/dist/testing/conformance/workflows/guards.js +0 -172
- package/dist/testing/conformance/workflows/harness.d.ts +0 -14
- package/dist/testing/conformance/workflows/harness.js +0 -44
- package/dist/testing/conformance/workflows/recovery.d.ts +0 -4
- package/dist/testing/conformance/workflows/recovery.js +0 -181
- package/dist/testing/conformance/workflows/starts.d.ts +0 -4
- package/dist/testing/conformance/workflows/starts.js +0 -57
- package/dist/testing/conformance/workflows/suspension.d.ts +0 -4
- package/dist/testing/conformance/workflows/suspension.js +0 -106
- package/dist/testing/conformance/workflows/waits.d.ts +0 -4
- package/dist/testing/conformance/workflows/waits.js +0 -284
- package/dist/testing/conformance/workflows.d.ts +0 -4
- package/dist/testing/conformance/workflows.js +0 -19
- package/dist/testing/conformance.d.ts +0 -330
- package/dist/testing/conformance.js +0 -364
- package/dist/testing/foundation.d.ts +0 -41
- package/dist/testing/foundation.js +0 -517
- package/dist/testing/simulate-cluster.d.ts +0 -112
- package/dist/testing/simulate-cluster.js +0 -257
- package/dist/testing/simulate.d.ts +0 -90
- package/dist/testing/simulate.js +0 -127
|
@@ -1,849 +0,0 @@
|
|
|
1
|
-
import { Clock, Context, Crypto, Deferred, Effect, Fiber, Layer, Option, Schedule, Schema, Stream, } from "effect";
|
|
2
|
-
import { Base64Url } from "effect/encoding";
|
|
3
|
-
import { FetchHttpClient, HttpClient, HttpClientRequest, HttpRouter } from "effect/http";
|
|
4
|
-
import { Unauthorized, User } from "../../index.js";
|
|
5
|
-
import { ActorError } from "../../errors/actor.js";
|
|
6
|
-
import { InternalActors } from "../../runtime/actors.js";
|
|
7
|
-
import { ASSERTION_HEADER, ASSERTION_TYPE, KEY_REFRESH_PATH, KEY_REFRESH_TYPE, reauthenticationDigest, requestDigest, } from "../../serve/assertion/binding.js";
|
|
8
|
-
import { actorErrorBody } from "../../protocol/wire.js";
|
|
9
|
-
import { gate, HttpRoom, receipts, runs, tenantOf, httpSuite } from "./http.js";
|
|
10
|
-
import { endReason, opened, serveSockets, socket } from "./transports/wire.js";
|
|
11
|
-
import { transportsSuite } from "./transports/actors.js";
|
|
12
|
-
import { serveFetch, silentListener } from "./platform.js";
|
|
13
|
-
import { serve } from "../../serve/layer.js";
|
|
14
|
-
import { Auth } from "../../runtime/index.js";
|
|
15
|
-
/**
|
|
16
|
-
* The runner half of hosted assertions: a runner serving with
|
|
17
|
-
* `Auth.assertion` admits a request only with a valid assertion bound
|
|
18
|
-
* to exactly that request. The cases sign assertions as an edge would, with
|
|
19
|
-
* their own Ed25519 keys.
|
|
20
|
-
*/
|
|
21
|
-
export const ISSUER = "https://edge.durable.test";
|
|
22
|
-
export const DEPLOYMENT = "dep-assertions";
|
|
23
|
-
export const REGION = "test-1";
|
|
24
|
-
const utf8 = new TextEncoder();
|
|
25
|
-
export const edgeKey = Effect.fnUntraced(function* (kid) {
|
|
26
|
-
const pair = yield* Effect.promise(() => crypto.subtle.generateKey({ name: "Ed25519" }, true, ["sign", "verify"]));
|
|
27
|
-
const { x } = yield* Effect.promise(() => crypto.subtle.exportKey("jwk", pair.publicKey));
|
|
28
|
-
return {
|
|
29
|
-
kid,
|
|
30
|
-
privateKey: pair.privateKey,
|
|
31
|
-
publicKey: { kid, kty: "OKP", crv: "Ed25519", x: x ?? "" },
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
const encodeJson = Schema.encodeEffect(Schema.fromJsonString(Schema.Json));
|
|
35
|
-
const decodeJson = Schema.decodeEffect(Schema.fromJsonString(Schema.Json));
|
|
36
|
-
const segment = (value) => encodeJson(value).pipe(Effect.orDie, Effect.map(Base64Url.encode));
|
|
37
|
-
/** A compact JWS over `claims`; the header defaults to an Ed25519 assertion under `key`. */
|
|
38
|
-
export const signAssertion = Effect.fnUntraced(function* (key, claims, header) {
|
|
39
|
-
const head = yield* segment({ alg: "EdDSA", typ: ASSERTION_TYPE, kid: key.kid, ...header });
|
|
40
|
-
const signed = `${head}.${yield* segment({ ...claims })}`;
|
|
41
|
-
const signature = yield* Effect.promise(() => crypto.subtle.sign({ name: "Ed25519" }, key.privateKey, utf8.encode(signed)));
|
|
42
|
-
return `${signed}.${Base64Url.encode(new Uint8Array(signature))}`;
|
|
43
|
-
});
|
|
44
|
-
/** A key-set refresh push for `audience`, issued now for 10 seconds, signed with `key`. */
|
|
45
|
-
export const signRefresh = Effect.fnUntraced(function* (key, audience = DEPLOYMENT) {
|
|
46
|
-
const now = Math.floor((yield* Clock.currentTimeMillis) / 1000);
|
|
47
|
-
const claims = { iss: ISSUER, aud: audience, iat: now, exp: now + 10 };
|
|
48
|
-
return yield* signAssertion(key, claims, { typ: KEY_REFRESH_TYPE });
|
|
49
|
-
});
|
|
50
|
-
/** Claims for `tenant`'s `subject`, issued now for 10 seconds, bound to `req`. */
|
|
51
|
-
export const claimsFor = Effect.fnUntraced(function* (options) {
|
|
52
|
-
const now = Math.floor((yield* Clock.currentTimeMillis) / 1000);
|
|
53
|
-
return {
|
|
54
|
-
iss: ISSUER,
|
|
55
|
-
aud: DEPLOYMENT,
|
|
56
|
-
region: REGION,
|
|
57
|
-
iat: now,
|
|
58
|
-
exp: now + 10,
|
|
59
|
-
tenant: options.tenant,
|
|
60
|
-
caller: User.make({ subject: options.subject }),
|
|
61
|
-
req: options.req,
|
|
62
|
-
};
|
|
63
|
-
});
|
|
64
|
-
/** Sends `request` to the server at `url`. */
|
|
65
|
-
const sendTo = (client, url) => (request) => Effect.gen(function* () {
|
|
66
|
-
const base = HttpClientRequest.make(request.method)(`${url}${request.path}`, {
|
|
67
|
-
headers: request.headers,
|
|
68
|
-
});
|
|
69
|
-
const keyed = request.key === undefined
|
|
70
|
-
? base
|
|
71
|
-
: HttpClientRequest.setHeader(base, "idempotency-key", request.key);
|
|
72
|
-
const built = request.body === ""
|
|
73
|
-
? keyed
|
|
74
|
-
: HttpClientRequest.bodyText(keyed, request.body, "application/json");
|
|
75
|
-
const response = yield* client.execute(built);
|
|
76
|
-
const text = yield* response.text;
|
|
77
|
-
return { status: response.status, body: text === "" ? undefined : yield* decodeJson(text) };
|
|
78
|
-
}).pipe(Effect.orDie);
|
|
79
|
-
/** Serves `HttpRoom` with `auth` from a real listening server for the rest of the scope. */
|
|
80
|
-
const serveAsserted = Effect.fnUntraced(function* (auth) {
|
|
81
|
-
const actors = yield* InternalActors;
|
|
82
|
-
const random = yield* Crypto.Crypto;
|
|
83
|
-
const context = yield* Effect.context();
|
|
84
|
-
const fetchLayer = yield* Layer.build(FetchHttpClient.layer);
|
|
85
|
-
const client = Context.get(fetchLayer, HttpClient.HttpClient);
|
|
86
|
-
const app = serve({ actors: [HttpRoom], auth }).pipe(Layer.provide(Layer.succeedContext(context)), Layer.provide(Layer.succeedContext(fetchLayer)));
|
|
87
|
-
const web = HttpRouter.toWebHandler(app, { disableLogger: true });
|
|
88
|
-
yield* Effect.addFinalizer(() => Effect.promise(() => web.dispose()));
|
|
89
|
-
const port = yield* serveFetch((request) => web.handler(request));
|
|
90
|
-
const url = `http://127.0.0.1:${port}`;
|
|
91
|
-
return {
|
|
92
|
-
url,
|
|
93
|
-
send: sendTo(client, url),
|
|
94
|
-
digest: (request) => requestDigest({
|
|
95
|
-
method: request.method,
|
|
96
|
-
target: request.path,
|
|
97
|
-
idempotencyKey: request.key,
|
|
98
|
-
body: utf8.encode(request.body),
|
|
99
|
-
}),
|
|
100
|
-
mint: Effect.gen(function* () {
|
|
101
|
-
const now = yield* actors.databaseNow;
|
|
102
|
-
return `v1.${now}.${now + actors.retryWindowMs}.${yield* random.randomUUIDv4}`;
|
|
103
|
-
}).pipe(Effect.orDie),
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
/** A runner's assertion provider trusting exactly `keys`. */
|
|
107
|
-
export const staticAuth = (keys) => Auth.assertion({
|
|
108
|
-
issuer: ISSUER,
|
|
109
|
-
audience: DEPLOYMENT,
|
|
110
|
-
region: REGION,
|
|
111
|
-
keys: { keys: keys.map((key) => key.publicKey) },
|
|
112
|
-
});
|
|
113
|
-
const unauthorizedBody = (code) => actorErrorBody(ActorError.make({ reason: Unauthorized.make({ code }) }));
|
|
114
|
-
/** A request to `HttpRoom/<id>/<member>` with a fresh command id. */
|
|
115
|
-
export const command = Effect.fnUntraced(function* (server, id, member, body = "") {
|
|
116
|
-
return {
|
|
117
|
-
method: "POST",
|
|
118
|
-
path: `/actors/HttpRoom/${id}/${member}`,
|
|
119
|
-
key: yield* server.mint,
|
|
120
|
-
body,
|
|
121
|
-
headers: {},
|
|
122
|
-
};
|
|
123
|
-
});
|
|
124
|
-
/** A query request, which carries no command id. */
|
|
125
|
-
const query = (id, member) => ({
|
|
126
|
-
method: "POST",
|
|
127
|
-
path: `/actors/HttpRoom/${id}/${member}`,
|
|
128
|
-
key: undefined,
|
|
129
|
-
body: "",
|
|
130
|
-
headers: {},
|
|
131
|
-
});
|
|
132
|
-
/** An assertion for `tenant`'s alice bound to `request`, with `change` applied to its claims. */
|
|
133
|
-
const assertionFor = Effect.fnUntraced(function* (options) {
|
|
134
|
-
const req = yield* options.server.digest(options.request);
|
|
135
|
-
const claims = yield* claimsFor({ tenant: options.tenant, subject: "alice", req });
|
|
136
|
-
return yield* signAssertion(options.edge, options.change === undefined ? claims : options.change(claims));
|
|
137
|
-
});
|
|
138
|
-
/** Sends `request` carrying `assertion`. */
|
|
139
|
-
const asserted = (server, request, assertion) => server.send({ ...request, headers: { ...request.headers, [ASSERTION_HEADER]: assertion } });
|
|
140
|
-
/** A key-set URL whose keys the case changes while the runner polls it. */
|
|
141
|
-
const keySetServer = Effect.fnUntraced(function* (initial) {
|
|
142
|
-
let keys = initial;
|
|
143
|
-
const port = yield* serveFetch(() => Response.json({ keys: keys.map((key) => key.publicKey) }));
|
|
144
|
-
return {
|
|
145
|
-
url: new URL(`http://127.0.0.1:${port}/keys`),
|
|
146
|
-
publish: (next) => Effect.sync(() => {
|
|
147
|
-
keys = next;
|
|
148
|
-
}),
|
|
149
|
-
};
|
|
150
|
-
});
|
|
151
|
-
export const assertionsConformance = [
|
|
152
|
-
{
|
|
153
|
-
name: "refuses forged, unknown-kid, wrong-algorithm, and none-algorithm assertions before admission",
|
|
154
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
155
|
-
const edge = yield* edgeKey("edge-1");
|
|
156
|
-
const impostor = yield* edgeKey("edge-1");
|
|
157
|
-
const stranger = yield* edgeKey("edge-9");
|
|
158
|
-
const server = yield* serveAsserted(staticAuth([edge]));
|
|
159
|
-
const tenant = yield* tenantOf;
|
|
160
|
-
const before = runs.count;
|
|
161
|
-
const unsecured = (claims) => Effect.gen(function* () {
|
|
162
|
-
const header = yield* segment({ alg: "none", typ: ASSERTION_TYPE, kid: "edge-1" });
|
|
163
|
-
return `${header}.${yield* segment({ ...claims })}.`;
|
|
164
|
-
});
|
|
165
|
-
const attempts = [
|
|
166
|
-
(claims) => signAssertion(impostor, claims),
|
|
167
|
-
(claims) => signAssertion(stranger, claims),
|
|
168
|
-
(claims) => signAssertion(edge, claims, { alg: "ES256" }),
|
|
169
|
-
(claims) => signAssertion(edge, claims, { typ: "JWT" }),
|
|
170
|
-
unsecured,
|
|
171
|
-
];
|
|
172
|
-
for (const attempt of attempts) {
|
|
173
|
-
const request = yield* command(server, "forged", "Whoami");
|
|
174
|
-
const req = yield* server.digest(request);
|
|
175
|
-
const claims = yield* claimsFor({ tenant, subject: "alice", req });
|
|
176
|
-
const reply = yield* asserted(server, request, yield* attempt(claims));
|
|
177
|
-
expect(reply.status).toBe(401);
|
|
178
|
-
expect(reply.body).toEqual(yield* unauthorizedBody("invalid_credentials"));
|
|
179
|
-
}
|
|
180
|
-
const missing = yield* server.send(yield* command(server, "forged", "Whoami"));
|
|
181
|
-
expect(missing.status).toBe(401);
|
|
182
|
-
expect(missing.body).toEqual(yield* unauthorizedBody("missing_credentials"));
|
|
183
|
-
expect(runs.count).toBe(before);
|
|
184
|
-
expect(yield* receipts(tenant, "HttpRoom", "forged")).toBe(0);
|
|
185
|
-
const request = yield* command(server, "forged", "Whoami");
|
|
186
|
-
const valid = yield* assertionFor({ edge, server, request, tenant });
|
|
187
|
-
expect(yield* asserted(server, request, valid)).toMatchObject({
|
|
188
|
-
status: 200,
|
|
189
|
-
body: `${tenant}/alice`,
|
|
190
|
-
});
|
|
191
|
-
})),
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: "refuses expired assertions, assertions issued in the future beyond skew, and assertions for another deployment or region",
|
|
195
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
196
|
-
const edge = yield* edgeKey("edge-1");
|
|
197
|
-
const server = yield* serveAsserted(staticAuth([edge]));
|
|
198
|
-
const tenant = yield* tenantOf;
|
|
199
|
-
const before = runs.count;
|
|
200
|
-
const refused = [
|
|
201
|
-
[(claims) => ({ ...claims, iat: claims.iat - 20, exp: claims.iat - 6 }), "expired"],
|
|
202
|
-
[
|
|
203
|
-
(claims) => ({ ...claims, iat: claims.iat + 10, exp: claims.iat + 20 }),
|
|
204
|
-
"invalid_credentials",
|
|
205
|
-
],
|
|
206
|
-
[(claims) => ({ ...claims, exp: claims.iat + 61 }), "invalid_credentials"],
|
|
207
|
-
[(claims) => ({ ...claims, aud: "dep-other" }), "invalid_credentials"],
|
|
208
|
-
[(claims) => ({ ...claims, region: "test-2" }), "invalid_credentials"],
|
|
209
|
-
[(claims) => ({ ...claims, iss: "https://edge.other.test" }), "invalid_credentials"],
|
|
210
|
-
];
|
|
211
|
-
for (const [change, code] of refused) {
|
|
212
|
-
const request = yield* command(server, "lifetime", "Whoami");
|
|
213
|
-
const assertion = yield* assertionFor({ edge, server, request, tenant, change });
|
|
214
|
-
const reply = yield* asserted(server, request, assertion);
|
|
215
|
-
expect(reply.status).toBe(401);
|
|
216
|
-
expect(reply.body).toEqual(yield* unauthorizedBody(code));
|
|
217
|
-
}
|
|
218
|
-
expect(runs.count).toBe(before);
|
|
219
|
-
expect(yield* receipts(tenant, "HttpRoom", "lifetime")).toBe(0);
|
|
220
|
-
const skewed = [
|
|
221
|
-
(claims) => ({ ...claims, iat: claims.iat - 10, exp: claims.iat - 1 }),
|
|
222
|
-
(claims) => ({ ...claims, iat: claims.iat + 4, exp: claims.iat + 14 }),
|
|
223
|
-
];
|
|
224
|
-
for (const change of skewed) {
|
|
225
|
-
const request = yield* command(server, "lifetime", "Whoami");
|
|
226
|
-
const assertion = yield* assertionFor({ edge, server, request, tenant, change });
|
|
227
|
-
expect((yield* asserted(server, request, assertion)).status).toBe(200);
|
|
228
|
-
}
|
|
229
|
-
})),
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
name: "refuses an assertion moved to another method, path, query, idempotency key, or body",
|
|
233
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
234
|
-
const edge = yield* edgeKey("edge-1");
|
|
235
|
-
const server = yield* serveAsserted(staticAuth([edge]));
|
|
236
|
-
const tenant = yield* tenantOf;
|
|
237
|
-
const before = runs.count;
|
|
238
|
-
const original = yield* command(server, "bound", "Post", '{"text":"hello"}');
|
|
239
|
-
const signed = yield* assertionFor({ edge, server, request: original, tenant });
|
|
240
|
-
const moved = [
|
|
241
|
-
{ ...original, path: "/actors/HttpRoom/other/Post" },
|
|
242
|
-
{ ...original, path: "/actors/HttpRoom/bound/Hold", body: "" },
|
|
243
|
-
{ ...original, path: `${original.path}?member=Hold` },
|
|
244
|
-
{ ...original, key: yield* server.mint },
|
|
245
|
-
{ ...original, body: '{"text":"goodbye"}' },
|
|
246
|
-
{ ...original, body: '{ "text":"hello"}' },
|
|
247
|
-
];
|
|
248
|
-
for (const request of moved) {
|
|
249
|
-
const reply = yield* asserted(server, request, signed);
|
|
250
|
-
expect(reply.status).toBe(401);
|
|
251
|
-
expect(reply.body).toEqual(yield* unauthorizedBody("invalid_credentials"));
|
|
252
|
-
}
|
|
253
|
-
const get = yield* assertionFor({
|
|
254
|
-
edge,
|
|
255
|
-
server,
|
|
256
|
-
request: { ...original, method: "GET" },
|
|
257
|
-
tenant,
|
|
258
|
-
});
|
|
259
|
-
expect((yield* asserted(server, original, get)).status).toBe(401);
|
|
260
|
-
const count = query("bound", "Count");
|
|
261
|
-
const countSigned = yield* assertionFor({ edge, server, request: count, tenant });
|
|
262
|
-
expect((yield* asserted(server, count, countSigned)).status).toBe(200);
|
|
263
|
-
expect((yield* asserted(server, query("other", "Count"), countSigned)).status).toBe(401);
|
|
264
|
-
expect(runs.count).toBe(before);
|
|
265
|
-
expect(yield* receipts(tenant, "HttpRoom", "bound")).toBe(0);
|
|
266
|
-
expect(yield* receipts(tenant, "HttpRoom", "other")).toBe(0);
|
|
267
|
-
expect(yield* asserted(server, original, signed)).toMatchObject({ status: 200, body: 1 });
|
|
268
|
-
})),
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
name: "takes the caller and tenant only from the assertion, whatever authorization the request carries",
|
|
272
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
273
|
-
const edge = yield* edgeKey("edge-1");
|
|
274
|
-
const server = yield* serveAsserted(staticAuth([edge]));
|
|
275
|
-
const tenant = yield* tenantOf;
|
|
276
|
-
const request = {
|
|
277
|
-
...(yield* command(server, "caller", "Whoami")),
|
|
278
|
-
headers: { authorization: "Bearer other-tenant:mallory", cookie: "session=mallory" },
|
|
279
|
-
};
|
|
280
|
-
const assertion = yield* assertionFor({ edge, server, request, tenant });
|
|
281
|
-
expect(yield* asserted(server, request, assertion)).toMatchObject({
|
|
282
|
-
status: 200,
|
|
283
|
-
body: `${tenant}/alice`,
|
|
284
|
-
});
|
|
285
|
-
const bare = yield* server.send({
|
|
286
|
-
...(yield* command(server, "caller", "Whoami")),
|
|
287
|
-
headers: { authorization: `Bearer ${tenant}:alice` },
|
|
288
|
-
});
|
|
289
|
-
expect(bare.status).toBe(401);
|
|
290
|
-
expect(bare.body).toEqual(yield* unauthorizedBody("missing_credentials"));
|
|
291
|
-
})),
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
name: "keeps admitted work running after its assertion expires, and replays its receipt to a newly authenticated retry",
|
|
295
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
296
|
-
const edge = yield* edgeKey("edge-1");
|
|
297
|
-
const server = yield* serveAsserted(staticAuth([edge]));
|
|
298
|
-
const tenant = yield* tenantOf;
|
|
299
|
-
const request = yield* command(server, "expiring", "Hold");
|
|
300
|
-
const iat = Math.floor((yield* Clock.currentTimeMillis) / 1000) - 10;
|
|
301
|
-
const exp = iat + 9;
|
|
302
|
-
const late = yield* assertionFor({
|
|
303
|
-
edge,
|
|
304
|
-
server,
|
|
305
|
-
request,
|
|
306
|
-
tenant,
|
|
307
|
-
change: (claims) => ({ ...claims, iat, exp }),
|
|
308
|
-
});
|
|
309
|
-
const entered = yield* Deferred.make();
|
|
310
|
-
const release = yield* Deferred.make();
|
|
311
|
-
gate.hold = Deferred.succeed(entered, undefined).pipe(Effect.andThen(Deferred.await(release)));
|
|
312
|
-
const before = runs.count;
|
|
313
|
-
const call = yield* asserted(server, request, late).pipe(Effect.forkChild);
|
|
314
|
-
const admitted = yield* Effect.raceFirst(Deferred.await(entered).pipe(Effect.as(undefined)), Fiber.join(call));
|
|
315
|
-
expect(admitted).toBe(undefined);
|
|
316
|
-
while ((yield* Clock.currentTimeMillis) <= (exp + 5) * 1000 + 200)
|
|
317
|
-
yield* Effect.sleep("100 millis");
|
|
318
|
-
gate.hold = Effect.void;
|
|
319
|
-
yield* Deferred.succeed(release, undefined);
|
|
320
|
-
expect(yield* Fiber.join(call)).toMatchObject({ status: 200, body: 1 });
|
|
321
|
-
const stale = yield* asserted(server, request, late);
|
|
322
|
-
expect(stale.status).toBe(401);
|
|
323
|
-
expect(stale.body).toEqual(yield* unauthorizedBody("expired"));
|
|
324
|
-
const fresh = yield* assertionFor({ edge, server, request, tenant });
|
|
325
|
-
expect(yield* asserted(server, request, fresh)).toMatchObject({ status: 200, body: 1 });
|
|
326
|
-
expect(runs.count).toBe(before + 1);
|
|
327
|
-
expect(yield* receipts(tenant, "HttpRoom", "expiring")).toBe(1);
|
|
328
|
-
})),
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
name: "accepts a rotated key during overlap and refuses a revoked key within the polling bound",
|
|
332
|
-
timeoutMs: 30_000,
|
|
333
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
334
|
-
const old = yield* edgeKey("edge-2026-08");
|
|
335
|
-
const rotated = yield* edgeKey("edge-2026-09");
|
|
336
|
-
const keySet = yield* keySetServer([old]);
|
|
337
|
-
const server = yield* serveAsserted(Auth.assertion({
|
|
338
|
-
issuer: ISSUER,
|
|
339
|
-
audience: DEPLOYMENT,
|
|
340
|
-
region: REGION,
|
|
341
|
-
keys: keySet.url,
|
|
342
|
-
refreshEvery: "1 second",
|
|
343
|
-
}));
|
|
344
|
-
const tenant = yield* tenantOf;
|
|
345
|
-
const status = Effect.fnUntraced(function* (key) {
|
|
346
|
-
const request = yield* command(server, "rotation", "Whoami");
|
|
347
|
-
const assertion = yield* assertionFor({ edge: key, server, request, tenant });
|
|
348
|
-
return (yield* asserted(server, request, assertion)).status;
|
|
349
|
-
});
|
|
350
|
-
expect(yield* status(old)).toBe(200);
|
|
351
|
-
yield* keySet.publish([old, rotated]);
|
|
352
|
-
yield* Effect.sleep("1200 millis");
|
|
353
|
-
expect(yield* status(rotated)).toBe(200);
|
|
354
|
-
expect(yield* status(old)).toBe(200);
|
|
355
|
-
yield* keySet.publish([rotated]);
|
|
356
|
-
yield* Effect.sleep("1200 millis");
|
|
357
|
-
expect(yield* status(old)).toBe(401);
|
|
358
|
-
expect(yield* status(rotated)).toBe(200);
|
|
359
|
-
})),
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
name: "rereads its key set at once on the edge's authenticated refresh push, and refuses any other push",
|
|
363
|
-
timeoutMs: 30_000,
|
|
364
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
365
|
-
const old = yield* edgeKey("edge-2026-08");
|
|
366
|
-
const rotated = yield* edgeKey("edge-2026-09");
|
|
367
|
-
const stranger = yield* edgeKey("edge-9");
|
|
368
|
-
const keySet = yield* keySetServer([old, rotated]);
|
|
369
|
-
const server = yield* serveAsserted(Auth.assertion({
|
|
370
|
-
issuer: ISSUER,
|
|
371
|
-
audience: DEPLOYMENT,
|
|
372
|
-
region: REGION,
|
|
373
|
-
keys: keySet.url,
|
|
374
|
-
}));
|
|
375
|
-
const tenant = yield* tenantOf;
|
|
376
|
-
const status = Effect.fnUntraced(function* (key) {
|
|
377
|
-
const request = yield* command(server, "pushed", "Whoami");
|
|
378
|
-
const assertion = yield* assertionFor({ edge: key, server, request, tenant });
|
|
379
|
-
return (yield* asserted(server, request, assertion)).status;
|
|
380
|
-
});
|
|
381
|
-
const push = (token) => server.send({
|
|
382
|
-
method: "POST",
|
|
383
|
-
path: KEY_REFRESH_PATH,
|
|
384
|
-
key: undefined,
|
|
385
|
-
body: "",
|
|
386
|
-
headers: token === undefined ? {} : { [ASSERTION_HEADER]: token },
|
|
387
|
-
});
|
|
388
|
-
expect(yield* status(old)).toBe(200);
|
|
389
|
-
yield* keySet.publish([rotated]);
|
|
390
|
-
expect(yield* status(old)).toBe(200);
|
|
391
|
-
const refused = [
|
|
392
|
-
yield* push(undefined),
|
|
393
|
-
yield* push(yield* signRefresh(stranger)),
|
|
394
|
-
yield* push(yield* signRefresh(rotated, "dep-other")),
|
|
395
|
-
yield* push(yield* assertionFor({
|
|
396
|
-
edge: rotated,
|
|
397
|
-
server,
|
|
398
|
-
request: yield* command(server, "pushed", "Whoami"),
|
|
399
|
-
tenant,
|
|
400
|
-
})),
|
|
401
|
-
];
|
|
402
|
-
expect(refused.map((reply) => reply.status)).toEqual([401, 401, 401, 401]);
|
|
403
|
-
expect(yield* status(old)).toBe(200);
|
|
404
|
-
expect((yield* push(yield* signRefresh(rotated))).status).toBe(204);
|
|
405
|
-
expect(yield* status(old)).toBe(401);
|
|
406
|
-
expect((yield* push(yield* signRefresh(rotated))).status).toBe(204);
|
|
407
|
-
expect(yield* status(rotated)).toBe(200);
|
|
408
|
-
})),
|
|
409
|
-
},
|
|
410
|
-
{
|
|
411
|
-
name: "refuses a reauthentication assertion whose sid belongs to another session",
|
|
412
|
-
timeoutMs: 30_000,
|
|
413
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
414
|
-
const edge = yield* edgeKey("edge-1");
|
|
415
|
-
const host = yield* serveSockets(environment, { auth: staticAuth([edge]) });
|
|
416
|
-
const tenant = yield* tenantOf;
|
|
417
|
-
const path = "/api/actors/SocketRoom/asserted/Chat";
|
|
418
|
-
const now = Math.floor((yield* Clock.currentTimeMillis) / 1000);
|
|
419
|
-
const upgrade = yield* requestDigest({
|
|
420
|
-
method: "GET",
|
|
421
|
-
target: path,
|
|
422
|
-
idempotencyKey: undefined,
|
|
423
|
-
body: new Uint8Array(0),
|
|
424
|
-
});
|
|
425
|
-
const bearer = (claims) => signAssertion(edge, claims).pipe(Effect.map((jws) => `Bearer ${jws}`));
|
|
426
|
-
const base = yield* claimsFor({ tenant, subject: "alice", req: upgrade });
|
|
427
|
-
const opening = yield* bearer({ ...base, sid: "session-a", cexp: now + 3600 });
|
|
428
|
-
const ws = yield* socket(host, "asserted");
|
|
429
|
-
yield* ws.send({ t: "hello", authorization: opening, params: { name: "alice" } });
|
|
430
|
-
expect((yield* opened(yield* ws.next())).reauthenticateBy).toBe((now + 3600) * 1000);
|
|
431
|
-
const renewal = Effect.fnUntraced(function* (sid) {
|
|
432
|
-
const req = yield* reauthenticationDigest({ path, session: sid });
|
|
433
|
-
return yield* bearer({ ...base, req, sid, cexp: now + 7200 });
|
|
434
|
-
});
|
|
435
|
-
yield* ws.send({ t: "reauthenticate", authorization: yield* renewal("session-a") });
|
|
436
|
-
expect((yield* ws.until("reauthenticated")).at(-1)).toEqual({
|
|
437
|
-
t: "reauthenticated",
|
|
438
|
-
by: (now + 7200) * 1000,
|
|
439
|
-
});
|
|
440
|
-
yield* ws.send({ t: "reauthenticate", authorization: yield* renewal("session-b") });
|
|
441
|
-
expect(yield* endReason((yield* ws.until("end")).at(-1))).toMatchObject({
|
|
442
|
-
tag: "Unauthorized",
|
|
443
|
-
code: "invalid_credentials",
|
|
444
|
-
});
|
|
445
|
-
expect((yield* ws.closed).code).toBe(1008);
|
|
446
|
-
const second = yield* socket(host, "asserted");
|
|
447
|
-
const secondOpening = yield* bearer({ ...base, sid: "session-c" });
|
|
448
|
-
yield* second.send({
|
|
449
|
-
t: "hello",
|
|
450
|
-
authorization: secondOpening,
|
|
451
|
-
params: { name: "alice" },
|
|
452
|
-
});
|
|
453
|
-
yield* opened(yield* second.next());
|
|
454
|
-
yield* second.send({ t: "reauthenticate", authorization: secondOpening });
|
|
455
|
-
expect(yield* endReason((yield* second.until("end")).at(-1))).toMatchObject({
|
|
456
|
-
tag: "Unauthorized",
|
|
457
|
-
code: "invalid_credentials",
|
|
458
|
-
});
|
|
459
|
-
})),
|
|
460
|
-
},
|
|
461
|
-
];
|
|
462
|
-
export const edgeOf = (edge) => edge === undefined ? Effect.die(new Error("The case needs a hosted edge")) : Effect.succeed(edge);
|
|
463
|
-
/** Sends requests to the server at `url` for the rest of the scope. */
|
|
464
|
-
export const clientFor = Effect.fnUntraced(function* (url) {
|
|
465
|
-
const client = Context.get(yield* Layer.build(FetchHttpClient.layer), HttpClient.HttpClient);
|
|
466
|
-
return sendTo(client, url);
|
|
467
|
-
});
|
|
468
|
-
/** A runner in `region` that trusts `edge`, rereading its key set every second. */
|
|
469
|
-
export const edgeRunner = Effect.fnUntraced(function* (edge, region) {
|
|
470
|
-
return yield* serveAsserted(Auth.assertion({
|
|
471
|
-
issuer: edge.issuer,
|
|
472
|
-
audience: edge.deployment,
|
|
473
|
-
region,
|
|
474
|
-
keys: edge.keys,
|
|
475
|
-
refreshEvery: "1 second",
|
|
476
|
-
}));
|
|
477
|
-
});
|
|
478
|
-
export const bearerHeaders = (key) => ({ authorization: `Bearer ${key}` });
|
|
479
|
-
/**
|
|
480
|
-
* A proxy in front of a runner that holds each request for the delay its
|
|
481
|
-
* path's actor id names, and counts the requests that reached it.
|
|
482
|
-
*/
|
|
483
|
-
export const delayingProxy = Effect.fnUntraced(function* (target) {
|
|
484
|
-
const delays = new Map();
|
|
485
|
-
const failures = new Map();
|
|
486
|
-
const arrived = [];
|
|
487
|
-
const cookies = [];
|
|
488
|
-
const client = Context.get(yield* Layer.build(FetchHttpClient.layer), HttpClient.HttpClient);
|
|
489
|
-
const context = yield* Effect.context();
|
|
490
|
-
const hold = (request) => Effect.gen(function* () {
|
|
491
|
-
const path = new URL(request.url).pathname;
|
|
492
|
-
const body = new Uint8Array(yield* Effect.promise(() => request.arrayBuffer()));
|
|
493
|
-
arrived.push(path);
|
|
494
|
-
cookies.push(request.headers.get("cookie"));
|
|
495
|
-
const failing = failures.get(path) ?? 0;
|
|
496
|
-
if (failing > 0) {
|
|
497
|
-
failures.set(path, failing - 1);
|
|
498
|
-
return new Response(null, { status: 503 });
|
|
499
|
-
}
|
|
500
|
-
yield* Effect.sleep(delays.get(path.split("/")[3] ?? "") ?? 0);
|
|
501
|
-
const forwarded = HttpClientRequest.make(request.method === "GET" ? "GET" : "POST")(`${target}${path}`, { headers: Object.fromEntries(request.headers) });
|
|
502
|
-
const response = yield* client.execute(body.byteLength === 0
|
|
503
|
-
? forwarded
|
|
504
|
-
: HttpClientRequest.bodyUint8Array(forwarded, body, request.headers.get("content-type") ?? undefined));
|
|
505
|
-
return new Response(yield* response.arrayBuffer, {
|
|
506
|
-
status: response.status,
|
|
507
|
-
headers: response.headers,
|
|
508
|
-
});
|
|
509
|
-
}).pipe(Effect.orDie);
|
|
510
|
-
const port = yield* serveFetch((request) => Effect.runPromiseWith(context)(hold(request)));
|
|
511
|
-
return {
|
|
512
|
-
url: `http://127.0.0.1:${port}`,
|
|
513
|
-
delay: (id, ms) => Effect.sync(() => delays.set(id, ms)),
|
|
514
|
-
/** Answers the next `times` requests for `path` with 503. */
|
|
515
|
-
fail: (path, times) => Effect.sync(() => failures.set(path, times)),
|
|
516
|
-
arrived: Effect.sync(() => arrived.length),
|
|
517
|
-
/** The `cookie` header of each request that reached the proxy, `null` when it had none. */
|
|
518
|
-
cookies: Effect.sync(() => [...cookies]),
|
|
519
|
-
};
|
|
520
|
-
});
|
|
521
|
-
/** Edge cases: the edge strips client-supplied assertions, signs the caller it authenticated, honors key rotation and revocation bounds, and routes across runners and regions. */
|
|
522
|
-
export const edgeConformance = [
|
|
523
|
-
{
|
|
524
|
-
name: "refuses a body over its request limit by content-length and stops reading a streamed one soon after the limit",
|
|
525
|
-
requiresEdge: true,
|
|
526
|
-
timeoutMs: 30_000,
|
|
527
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
528
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({ primaryRegion: REGION });
|
|
529
|
-
const runner = yield* edgeRunner(edge, REGION);
|
|
530
|
-
yield* edge.addRunner({ region: REGION, url: runner.url });
|
|
531
|
-
const client = Context.get(yield* Layer.build(FetchHttpClient.layer), HttpClient.HttpClient);
|
|
532
|
-
const target = `${edge.url}/actors/HttpRoom/limited/Post`;
|
|
533
|
-
const chunk = new Uint8Array(64 * 1024);
|
|
534
|
-
let produced = 0;
|
|
535
|
-
const endless = Stream.fromEffectRepeat(Effect.sync(() => {
|
|
536
|
-
produced += chunk.byteLength;
|
|
537
|
-
return chunk;
|
|
538
|
-
}));
|
|
539
|
-
const reply = (request) => client.execute(request).pipe(Effect.flatMap((response) => Effect.map(response.text, (text) => ({ status: response.status, text }))), Effect.timeout("10 seconds"), Effect.orDie);
|
|
540
|
-
const streamed = yield* reply(HttpClientRequest.post(target).pipe(HttpClientRequest.bodyStream(endless)));
|
|
541
|
-
expect(streamed.status).toBe(413);
|
|
542
|
-
expect(streamed.text.includes('"code":"too_large"')).toBe(true);
|
|
543
|
-
expect(produced < 16 * 1024 * 1024).toBe(true);
|
|
544
|
-
const declared = yield* reply(HttpClientRequest.post(target).pipe(HttpClientRequest.bodyUint8Array(new Uint8Array(2 * 1024 * 1024))));
|
|
545
|
-
expect(declared.status).toBe(413);
|
|
546
|
-
expect(declared.text.includes('"code":"too_large"')).toBe(true);
|
|
547
|
-
})),
|
|
548
|
-
},
|
|
549
|
-
{
|
|
550
|
-
name: "forwards no client cookie to a runner",
|
|
551
|
-
requiresEdge: true,
|
|
552
|
-
timeoutMs: 30_000,
|
|
553
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
554
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({ primaryRegion: REGION });
|
|
555
|
-
const runner = yield* edgeRunner(edge, REGION);
|
|
556
|
-
const door = yield* delayingProxy(runner.url);
|
|
557
|
-
yield* edge.addRunner({ region: REGION, url: door.url });
|
|
558
|
-
const send = yield* clientFor(edge.url);
|
|
559
|
-
const tenant = yield* tenantOf;
|
|
560
|
-
const key = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
561
|
-
const reply = yield* send({
|
|
562
|
-
...(yield* command(runner, "cookies", "Whoami")),
|
|
563
|
-
headers: { ...bearerHeaders(key), cookie: "session=secret-session-cookie" },
|
|
564
|
-
});
|
|
565
|
-
expect(reply).toMatchObject({ status: 200, body: `${tenant}/alice` });
|
|
566
|
-
expect(yield* door.cookies).toEqual([null]);
|
|
567
|
-
})),
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
name: "closes a client socket that sends a message over the frame limit, or floods past its buffer while no runner has accepted it",
|
|
571
|
-
requiresEdge: true,
|
|
572
|
-
timeoutMs: 30_000,
|
|
573
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
574
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({ primaryRegion: REGION });
|
|
575
|
-
const silent = yield* silentListener;
|
|
576
|
-
yield* edge.addRunner({ region: REGION, url: `http://127.0.0.1:${silent}` });
|
|
577
|
-
const host = new URL(edge.url).host;
|
|
578
|
-
const oversized = yield* socket(host, "oversized");
|
|
579
|
-
yield* oversized.send({ t: "hello", params: { name: "alice" } });
|
|
580
|
-
yield* oversized.sendRaw("x".repeat(70 * 1024));
|
|
581
|
-
expect([1006, 1009]).toContain((yield* oversized.closed).code);
|
|
582
|
-
expect(yield* oversized.poll(100)).toEqual(Option.none());
|
|
583
|
-
const flooding = yield* socket(host, "flooding");
|
|
584
|
-
yield* flooding.send({ t: "hello", params: { name: "alice" } });
|
|
585
|
-
for (let index = 0; index < 40; index++)
|
|
586
|
-
yield* flooding.sendRaw("x".repeat(60 * 1024));
|
|
587
|
-
expect((yield* flooding.closed).code).toBe(1008);
|
|
588
|
-
expect(yield* flooding.poll(100)).toEqual(Option.none());
|
|
589
|
-
})),
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
name: "strips a client-supplied durable-assertion and takes the caller only from the assertion",
|
|
593
|
-
requiresEdge: true,
|
|
594
|
-
timeoutMs: 30_000,
|
|
595
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
596
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({ primaryRegion: REGION });
|
|
597
|
-
const runner = yield* edgeRunner(edge, REGION);
|
|
598
|
-
const send = yield* clientFor(edge.url);
|
|
599
|
-
const tenant = yield* tenantOf;
|
|
600
|
-
const key = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
601
|
-
yield* edge.addRunner({ region: REGION, url: runner.url });
|
|
602
|
-
const forger = yield* edgeKey("edge-1");
|
|
603
|
-
const request = yield* command(runner, "stripped", "Whoami");
|
|
604
|
-
const forged = yield* assertionFor({
|
|
605
|
-
edge: forger,
|
|
606
|
-
server: runner,
|
|
607
|
-
request,
|
|
608
|
-
tenant: "mallory",
|
|
609
|
-
});
|
|
610
|
-
const reply = yield* send({
|
|
611
|
-
...request,
|
|
612
|
-
headers: { ...bearerHeaders(key), [ASSERTION_HEADER]: forged },
|
|
613
|
-
});
|
|
614
|
-
expect(reply).toMatchObject({ status: 200, body: `${tenant}/alice` });
|
|
615
|
-
const bare = yield* send({
|
|
616
|
-
...(yield* command(runner, "stripped", "Whoami")),
|
|
617
|
-
headers: { [ASSERTION_HEADER]: forged },
|
|
618
|
-
});
|
|
619
|
-
expect(bare.status).toBe(401);
|
|
620
|
-
expect(bare.body).toEqual(yield* unauthorizedBody("missing_credentials"));
|
|
621
|
-
})),
|
|
622
|
-
},
|
|
623
|
-
{
|
|
624
|
-
name: "refuses new requests from a revoked caller at the edge, and admits in-flight ones only within the assertion lifetime",
|
|
625
|
-
requiresEdge: true,
|
|
626
|
-
timeoutMs: 40_000,
|
|
627
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
628
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({
|
|
629
|
-
primaryRegion: REGION,
|
|
630
|
-
assertionSeconds: 1,
|
|
631
|
-
});
|
|
632
|
-
const runner = yield* edgeRunner(edge, REGION);
|
|
633
|
-
const proxy = yield* delayingProxy(runner.url);
|
|
634
|
-
const send = yield* clientFor(edge.url);
|
|
635
|
-
const tenant = yield* tenantOf;
|
|
636
|
-
const key = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
637
|
-
yield* edge.addRunner({ region: REGION, url: proxy.url });
|
|
638
|
-
yield* proxy.delay("held-long", 7_000);
|
|
639
|
-
yield* proxy.delay("held-short", 300);
|
|
640
|
-
const long = yield* command(runner, "held-long", "Whoami");
|
|
641
|
-
const short = yield* command(runner, "held-short", "Whoami");
|
|
642
|
-
const late = yield* send({ ...long, headers: bearerHeaders(key) }).pipe(Effect.forkChild);
|
|
643
|
-
const inTime = yield* send({ ...short, headers: bearerHeaders(key) }).pipe(Effect.forkChild);
|
|
644
|
-
while ((yield* proxy.arrived) < 2)
|
|
645
|
-
yield* Effect.sleep("20 millis");
|
|
646
|
-
yield* edge.revokeApiKey(key);
|
|
647
|
-
const refused = yield* send({
|
|
648
|
-
...(yield* command(runner, "after", "Whoami")),
|
|
649
|
-
headers: bearerHeaders(key),
|
|
650
|
-
});
|
|
651
|
-
expect(refused.status).toBe(401);
|
|
652
|
-
expect(refused.body).toEqual(yield* unauthorizedBody("invalid_credentials"));
|
|
653
|
-
expect(yield* proxy.arrived).toBe(2);
|
|
654
|
-
expect(yield* Fiber.join(inTime)).toMatchObject({ status: 200, body: `${tenant}/alice` });
|
|
655
|
-
const expired = yield* Fiber.join(late);
|
|
656
|
-
expect(expired.status).toBe(401);
|
|
657
|
-
expect(expired.body).toEqual(yield* unauthorizedBody("expired"));
|
|
658
|
-
expect(yield* receipts(tenant, "HttpRoom", "held-long")).toBe(0);
|
|
659
|
-
expect(yield* receipts(tenant, "HttpRoom", "after")).toBe(0);
|
|
660
|
-
})),
|
|
661
|
-
},
|
|
662
|
-
{
|
|
663
|
-
name: "reauthenticates a WebSocket session through the edge and closes it at the revocation bound",
|
|
664
|
-
requiresEdge: true,
|
|
665
|
-
timeoutMs: 40_000,
|
|
666
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
667
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({
|
|
668
|
-
primaryRegion: REGION,
|
|
669
|
-
apiKeySessionSeconds: 4,
|
|
670
|
-
});
|
|
671
|
-
const host = yield* serveSockets(environment, {
|
|
672
|
-
auth: Auth.assertion({
|
|
673
|
-
issuer: edge.issuer,
|
|
674
|
-
audience: edge.deployment,
|
|
675
|
-
region: REGION,
|
|
676
|
-
keys: edge.keys,
|
|
677
|
-
refreshEvery: "1 second",
|
|
678
|
-
}),
|
|
679
|
-
});
|
|
680
|
-
yield* edge.addRunner({ region: REGION, url: `http://${host}`, basePath: "/api/" });
|
|
681
|
-
yield* edge.addRunner({ region: REGION, url: "http://127.0.0.1:9", basePath: "/api" });
|
|
682
|
-
const tenant = yield* tenantOf;
|
|
683
|
-
const key = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
684
|
-
const probe = yield* socket(new URL(edge.url).host, "through-edge");
|
|
685
|
-
yield* probe.send({
|
|
686
|
-
t: "hello",
|
|
687
|
-
authorization: `Bearer ${key}`,
|
|
688
|
-
params: { name: "alice" },
|
|
689
|
-
});
|
|
690
|
-
yield* opened(yield* probe.next());
|
|
691
|
-
yield* probe.close;
|
|
692
|
-
const ws = yield* socket(new URL(edge.url).host, "through-edge");
|
|
693
|
-
yield* ws.send({ t: "hello", authorization: `Bearer ${key}`, params: { name: "alice" } });
|
|
694
|
-
const open = yield* opened(yield* ws.next());
|
|
695
|
-
const started = yield* Clock.currentTimeMillis;
|
|
696
|
-
const by = open.reauthenticateBy ?? 0;
|
|
697
|
-
expect(by > started + 2_000 && by <= started + 4_000).toBe(true);
|
|
698
|
-
const asked = (yield* ws.until("reauthenticate", 10_000)).at(-1);
|
|
699
|
-
expect(asked?.t).toBe("reauthenticate");
|
|
700
|
-
yield* Effect.sleep("1100 millis");
|
|
701
|
-
yield* ws.send({ t: "reauthenticate", authorization: `Bearer ${key}` });
|
|
702
|
-
const renewed = (yield* ws.until("reauthenticated", 10_000)).at(-1);
|
|
703
|
-
expect(renewed?.t === "reauthenticated" && (renewed.by ?? 0) > (open.reauthenticateBy ?? 0)).toBe(true);
|
|
704
|
-
yield* edge.revokeApiKey(key);
|
|
705
|
-
yield* ws.until("reauthenticate", 10_000);
|
|
706
|
-
yield* ws.send({ t: "reauthenticate", authorization: `Bearer ${key}` });
|
|
707
|
-
expect(yield* endReason((yield* ws.until("end", 10_000)).at(-1))).toMatchObject({
|
|
708
|
-
tag: "Unauthorized",
|
|
709
|
-
code: "invalid_credentials",
|
|
710
|
-
});
|
|
711
|
-
expect((yield* ws.closed).code).toBe(1008);
|
|
712
|
-
expect((yield* Clock.currentTimeMillis) - started < 10_000).toBe(true);
|
|
713
|
-
})),
|
|
714
|
-
},
|
|
715
|
-
{
|
|
716
|
-
name: "pushes a signing-key revocation to runners, which refuse the key well before their polling bound",
|
|
717
|
-
requiresEdge: true,
|
|
718
|
-
timeoutMs: 30_000,
|
|
719
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
720
|
-
const old = yield* edgeKey("edge-2026-08");
|
|
721
|
-
const rotated = yield* edgeKey("edge-2026-09");
|
|
722
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({
|
|
723
|
-
primaryRegion: REGION,
|
|
724
|
-
signingKeys: [old, rotated],
|
|
725
|
-
});
|
|
726
|
-
const runner = yield* serveAsserted(Auth.assertion({
|
|
727
|
-
issuer: edge.issuer,
|
|
728
|
-
audience: edge.deployment,
|
|
729
|
-
region: REGION,
|
|
730
|
-
keys: edge.keys,
|
|
731
|
-
}));
|
|
732
|
-
const door = yield* delayingProxy(runner.url);
|
|
733
|
-
yield* door.fail(KEY_REFRESH_PATH, 1);
|
|
734
|
-
yield* edge.addRunner({ region: REGION, url: door.url, basePath: "/" });
|
|
735
|
-
const send = yield* clientFor(edge.url);
|
|
736
|
-
const tenant = yield* tenantOf;
|
|
737
|
-
const apiKey = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
738
|
-
const direct = Effect.fnUntraced(function* (key) {
|
|
739
|
-
const request = yield* command(runner, "revoked-key", "Whoami");
|
|
740
|
-
const claims = yield* claimsFor({
|
|
741
|
-
tenant,
|
|
742
|
-
subject: "alice",
|
|
743
|
-
req: yield* runner.digest(request),
|
|
744
|
-
});
|
|
745
|
-
const assertion = yield* signAssertion(key, {
|
|
746
|
-
...claims,
|
|
747
|
-
iss: edge.issuer,
|
|
748
|
-
aud: edge.deployment,
|
|
749
|
-
});
|
|
750
|
-
return (yield* asserted(runner, request, assertion)).status;
|
|
751
|
-
});
|
|
752
|
-
expect(yield* direct(old)).toBe(200);
|
|
753
|
-
const started = yield* Clock.currentTimeMillis;
|
|
754
|
-
yield* edge.revokeSigningKey(old.kid);
|
|
755
|
-
const refused = yield* direct(old).pipe(Effect.repeat({
|
|
756
|
-
until: (status) => status === 401,
|
|
757
|
-
schedule: Schedule.spaced("100 millis"),
|
|
758
|
-
times: 100,
|
|
759
|
-
}));
|
|
760
|
-
const elapsed = (yield* Clock.currentTimeMillis) - started;
|
|
761
|
-
expect(refused).toBe(401);
|
|
762
|
-
expect(elapsed < 10_000).toBe(true);
|
|
763
|
-
expect(yield* direct(rotated)).toBe(200);
|
|
764
|
-
const through = yield* send({
|
|
765
|
-
...(yield* command(runner, "revoked-key", "Whoami")),
|
|
766
|
-
headers: bearerHeaders(apiKey),
|
|
767
|
-
});
|
|
768
|
-
expect(through).toMatchObject({ status: 200, body: `${tenant}/alice` });
|
|
769
|
-
})),
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
name: "fails a WebSocket over to the next runner with an assertion signed after it accepts",
|
|
773
|
-
requiresEdge: true,
|
|
774
|
-
timeoutMs: 30_000,
|
|
775
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
776
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({
|
|
777
|
-
primaryRegion: REGION,
|
|
778
|
-
assertionSeconds: 2,
|
|
779
|
-
});
|
|
780
|
-
const host = yield* serveSockets(environment, {
|
|
781
|
-
auth: Auth.assertion({
|
|
782
|
-
issuer: edge.issuer,
|
|
783
|
-
audience: edge.deployment,
|
|
784
|
-
region: REGION,
|
|
785
|
-
keys: edge.keys,
|
|
786
|
-
refreshEvery: "1 second",
|
|
787
|
-
}),
|
|
788
|
-
});
|
|
789
|
-
const hole = yield* silentListener;
|
|
790
|
-
yield* edge.addRunner({ region: REGION, url: `http://${host}`, basePath: "/api" });
|
|
791
|
-
yield* edge.addRunner({ region: REGION, url: `http://127.0.0.1:${hole}` });
|
|
792
|
-
const tenant = yield* tenantOf;
|
|
793
|
-
const key = yield* edge.issueApiKey({ tenant, subject: "alice" });
|
|
794
|
-
for (let index = 0; index < 2; index++) {
|
|
795
|
-
const ws = yield* socket(new URL(edge.url).host, "fail-over");
|
|
796
|
-
yield* ws.send({
|
|
797
|
-
t: "hello",
|
|
798
|
-
authorization: `Bearer ${key}`,
|
|
799
|
-
params: { name: "alice" },
|
|
800
|
-
});
|
|
801
|
-
expect((yield* ws.next(10_000)).t).toBe("open");
|
|
802
|
-
yield* ws.close;
|
|
803
|
-
}
|
|
804
|
-
})),
|
|
805
|
-
},
|
|
806
|
-
{
|
|
807
|
-
name: "routes a tenant with no directory row to the primary region and never writes a row",
|
|
808
|
-
requiresEdge: true,
|
|
809
|
-
timeoutMs: 30_000,
|
|
810
|
-
run: ({ expect, environment }) => environment.run(Effect.gen(function* () {
|
|
811
|
-
const edge = yield* (yield* edgeOf(environment.edge)).start({ primaryRegion: REGION });
|
|
812
|
-
const other = "test-2";
|
|
813
|
-
const primary = yield* edgeRunner(edge, REGION);
|
|
814
|
-
const secondary = yield* edgeRunner(edge, other);
|
|
815
|
-
const primaryDoor = yield* delayingProxy(primary.url);
|
|
816
|
-
const secondaryDoor = yield* delayingProxy(secondary.url);
|
|
817
|
-
const send = yield* clientFor(edge.url);
|
|
818
|
-
yield* edge.addRunner({ region: REGION, url: primaryDoor.url });
|
|
819
|
-
yield* edge.addRunner({ region: other, url: secondaryDoor.url });
|
|
820
|
-
const homeless = yield* tenantOf;
|
|
821
|
-
const moved = yield* tenantOf;
|
|
822
|
-
const homelessKey = yield* edge.issueApiKey({ tenant: homeless, subject: "alice" });
|
|
823
|
-
const movedKey = yield* edge.issueApiKey({ tenant: moved, subject: "alice" });
|
|
824
|
-
yield* edge.home({ tenant: moved, region: other });
|
|
825
|
-
const call = (key) => Effect.flatMap(command(primary, "routed", "Whoami"), (request) => send({ ...request, headers: bearerHeaders(key) }));
|
|
826
|
-
for (let index = 0; index < 3; index++)
|
|
827
|
-
expect(yield* call(homelessKey)).toMatchObject({
|
|
828
|
-
status: 200,
|
|
829
|
-
body: `${homeless}/alice`,
|
|
830
|
-
});
|
|
831
|
-
expect(yield* primaryDoor.arrived).toBe(3);
|
|
832
|
-
expect(yield* secondaryDoor.arrived).toBe(0);
|
|
833
|
-
expect(yield* call(movedKey)).toMatchObject({ status: 200, body: `${moved}/alice` });
|
|
834
|
-
expect(yield* secondaryDoor.arrived).toBe(1);
|
|
835
|
-
expect(yield* edge.directoryRows).toBe(1);
|
|
836
|
-
yield* edge.home({ tenant: homeless, region: other });
|
|
837
|
-
const reached = yield* call(homelessKey).pipe(Effect.andThen(secondaryDoor.arrived), Effect.repeat({
|
|
838
|
-
until: (arrived) => arrived > 1,
|
|
839
|
-
schedule: Schedule.spaced("200 millis"),
|
|
840
|
-
times: 100,
|
|
841
|
-
}));
|
|
842
|
-
expect(reached).toBe(2);
|
|
843
|
-
})),
|
|
844
|
-
},
|
|
845
|
-
];
|
|
846
|
-
/** Assertion and edge cases call the served HTTP actors and the socket room. */
|
|
847
|
-
export const assertionsSuite = {
|
|
848
|
-
uses: [httpSuite, transportsSuite],
|
|
849
|
-
};
|