diff --git a/contracts/cultnet/governance/fork-card-vectors.json b/contracts/cultnet/governance/fork-card-vectors.json index bce0278a..38fcfee5 100644 --- a/contracts/cultnet/governance/fork-card-vectors.json +++ b/contracts/cultnet/governance/fork-card-vectors.json @@ -1898,6 +1898,16 @@ }, "messagePackHex": "83AD736368656D6156657273696F6EB867616D6563756C742E666F726B2E7265667573616C2E7630A4636F6465B2696E73756666696369656E745F73636F7065A56572726F72D93E696E73756666696369656E745F73636F70653A2074686520746F6B656E206C61636B73207468652073636F7065207468697320726F757465206E65656473" }, + { + "name": "forbidden", + "httpStatus": 403, + "message": { + "schemaVersion": "gamecult.fork.refusal.v0", + "code": "forbidden", + "error": "forbidden: only Active members may use the desk" + }, + "messagePackHex": "83AD736368656D6156657273696F6EB867616D6563756C742E666F726B2E7265667573616C2E7630A4636F6465A9666F7262696464656EA56572726F72D92F666F7262696464656E3A206F6E6C7920416374697665206D656D62657273206D61792075736520746865206465736B" + }, { "name": "request_invalid", "httpStatus": 400, @@ -4991,9 +5001,11 @@ "audience": "bifrost-desk", "scopes": [ "desk.read" - ] + ], + "active": true }, - "expect": "ok" + "expect": "ok", + "huginn_down": false }, { "name": "read_with_desk_read", @@ -5002,9 +5014,11 @@ "audience": "bifrost-desk", "scopes": [ "desk.read" - ] + ], + "active": true }, - "expect": "ok" + "expect": "ok", + "huginn_down": false }, { "name": "answer_with_desk_answer", @@ -5013,9 +5027,11 @@ "audience": "bifrost-desk", "scopes": [ "desk.answer" - ] + ], + "active": true }, - "expect": "ok" + "expect": "ok", + "huginn_down": false }, { "name": "answer_with_both_scopes", @@ -5025,21 +5041,25 @@ "scopes": [ "desk.read", "desk.answer" - ] + ], + "active": true }, - "expect": "ok" + "expect": "ok", + "huginn_down": false }, { "name": "no_bearer_list", "route": "list", "token": null, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "no_bearer_answer", "route": "answer", "token": null, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "the_MAS_token_is_refused", @@ -5049,9 +5069,11 @@ "scopes": [ "openid", "profile" - ] + ], + "active": true }, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "a_votes_token_cannot_list", @@ -5060,9 +5082,11 @@ "audience": "bifrost-votes", "scopes": [ "votes.read" - ] + ], + "active": true }, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "a_votes_token_cannot_read", @@ -5071,9 +5095,11 @@ "audience": "bifrost-votes", "scopes": [ "votes.read" - ] + ], + "active": true }, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "a_votes_token_cannot_answer", @@ -5082,9 +5108,11 @@ "audience": "bifrost-votes", "scopes": [ "votes.cast" - ] + ], + "active": true }, - "expect": "unauthenticated" + "expect": "unauthenticated", + "huginn_down": false }, { "name": "desk_audience_with_a_votes_scope_only", @@ -5093,9 +5121,11 @@ "audience": "bifrost-desk", "scopes": [ "votes.cast" - ] + ], + "active": true }, - "expect": "insufficient_scope" + "expect": "insufficient_scope", + "huginn_down": false }, { "name": "desk_read_cannot_answer", @@ -5104,9 +5134,11 @@ "audience": "bifrost-desk", "scopes": [ "desk.read" - ] + ], + "active": true }, - "expect": "insufficient_scope" + "expect": "insufficient_scope", + "huginn_down": false }, { "name": "desk_answer_cannot_list", @@ -5115,9 +5147,122 @@ "audience": "bifrost-desk", "scopes": [ "desk.answer" - ] + ], + "active": true }, - "expect": "insufficient_scope" + "expect": "insufficient_scope", + "huginn_down": false + }, + { + "name": "a_non_active_member_cannot_list", + "route": "list", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": false + }, + "expect": "forbidden", + "huginn_down": false + }, + { + "name": "a_non_active_member_cannot_read", + "route": "read", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": false + }, + "expect": "forbidden", + "huginn_down": false + }, + { + "name": "a_non_active_member_cannot_answer", + "route": "answer", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.answer" + ], + "active": false + }, + "expect": "forbidden", + "huginn_down": false + }, + { + "name": "scope_is_judged_before_membership", + "route": "answer", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": false + }, + "expect": "insufficient_scope", + "huginn_down": false + }, + { + "name": "huginn_down_list", + "route": "list", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": true + }, + "expect": "unavailable", + "huginn_down": true + }, + { + "name": "huginn_down_read", + "route": "read", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": true + }, + "expect": "unavailable", + "huginn_down": true + }, + { + "name": "huginn_down_answer", + "route": "answer", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.answer" + ], + "active": true + }, + "expect": "unavailable", + "huginn_down": true + }, + { + "name": "auth_is_judged_before_huginn_is_asked", + "route": "list", + "token": null, + "expect": "unauthenticated", + "huginn_down": true + }, + { + "name": "membership_is_judged_before_huginn_is_asked", + "route": "read", + "token": { + "audience": "bifrost-desk", + "scopes": [ + "desk.read" + ], + "active": false + }, + "expect": "forbidden", + "huginn_down": true } ] }, diff --git a/contracts/cultnet/governance/fork-card.md b/contracts/cultnet/governance/fork-card.md index f7599d6c..d300941d 100644 --- a/contracts/cultnet/governance/fork-card.md +++ b/contracts/cultnet/governance/fork-card.md @@ -63,7 +63,7 @@ The stamped `authority` field of a stored answer is an **attribution**: the role - `Retraction`: the stored form of `retracted: true` plus `retracts`. `retracts` names the answer retracted; `choice` and `note` nil. The illegal pair (a retraction with no target, or a target with no retraction) cannot be written. - `Refused`: any refusal from steps 4 to 7 or R1 and R2, with its `code`, stored too. `choice` and `note` keep what the body carried. -`received_at` is Huginn's admission time; "first" means first by admission order (the `n` ordinal), never by `answered_at`. `claim_in_future` is true when `answered_at` is more than five minutes after `received_at`: accepted but flagged. **Not stored, and no answer id:** a body refused at step 1 or 2 (Bifrost; it never reaches Huginn), and a body naming an unknown fork (step 3; Huginn answers it from its stored forks, but with no question there is nothing to key a record under). Each gets a `refusal` and is dropped. A malformed body is therefore never stored, and neither is an unknown fork. Every refusal from step 4 on is stored. **`unavailable`** (503) is not a refusal and not in the refusal set: Bifrost answers it when the second door or Huginn cannot be reached after steps 1 and 2 passed (a bad body is still refused first). It carries no answer id, stores nothing, and tells the desk to try the same request again (`retryAfterSeconds`, nil when Bifrost has no hint). +`received_at` is Huginn's admission time; "first" means first by admission order (the `n` ordinal), never by `answered_at`. `claim_in_future` is true when `answered_at` is more than five minutes after `received_at`: accepted but flagged. **Not stored, and no answer id:** a body refused at step 1 or 2 (Bifrost; it never reaches Huginn), and a body naming an unknown fork (step 3; Huginn answers it from its stored forks, but with no question there is nothing to key a record under). Each gets a `refusal` and is dropped. A malformed body is therefore never stored, and neither is an unknown fork. Every refusal from step 4 on is stored. **`unavailable`** (503) is not a refusal and not in the refusal set: Bifrost answers it when the second door or Huginn cannot be reached after steps 1 and 2 passed (a bad body is still refused first). It carries no answer id, stores nothing, and covers **calls 1 and 2 as well as the answer POST** when Huginn cannot be reached (Transport), and tells the desk to try the same request again (`retryAfterSeconds`, nil when Bifrost has no hint). ### Counting rules (in order; the first failure refuses with that code) @@ -106,7 +106,7 @@ Source: the desk's client needs (Ratatoskr PR #24 section 12, `ratatoskr-desk-sp Calls 1 and 2 are enough for a read-only desk. Every response is the pinned MessagePack document or its JSON form with the same keys (open choice 1 of `vote-api.md`: the media type is unsettled). -**Auth, in order, per route.** (1) A bearer, else `unauthenticated` (401). (2) The token's audience is `bifrost-desk`: **the Matrix Authentication Service token chat holds today is refused, and so is any `votes.*` token** (audience `bifrost-votes`), both as `unauthenticated`. (3) The scope the route needs, else `insufficient_scope` (403): `desk.read` for calls 1 and 2, `desk.answer` for call 3, and neither implies the other. A `votes.*` token therefore touches none of the three. For call 3 the body is then shaped (steps 1 and 2 above) and a body naming `answerer` or `authority` at any depth is `body_forbidden_field`. Heimdall's file leaves the audience and the claims check open; `insufficient_scope` and `request_invalid` (400, a list or read request that fails its document) are added to the door refusals. +**Auth, in order, per route.** (1) A bearer, else `unauthenticated` (401). (2) The token's audience is `bifrost-desk`: **the Matrix Authentication Service token chat holds today is refused, and so is any `votes.*` token** (audience `bifrost-votes`), both as `unauthenticated`. (3) The scope the route needs, else `insufficient_scope` (403): `desk.read` for calls 1 and 2, `desk.answer` for call 3, and neither implies the other. (4) The account behind `sub` is an Active member, else `forbidden` (403), as in the vote API; scope is judged first. (5) Only then is Huginn asked, so `unavailable` never hides an auth refusal. A `votes.*` token therefore touches none of the three. For call 3 the body is then shaped (steps 1 and 2 above) and a body naming `answerer` or `authority` at any depth is `body_forbidden_field`. Heimdall's file leaves the audience and the claims check open; `insufficient_scope`, `forbidden` and `request_invalid` (400, a list or read request that fails its document) are added to the door refusals. **List.** `list_request`: `{mind, status, cursor, limit}`. `mind` is the Mind's instance slug. `status` is `open`, `recorded` or nil for both; `recorded` means a closed card. Cards come **newest first by `order`** (the admission ordinal). `limit` is 0 to 50; **`limit` 0 returns no entries, only the counts and the stamp**, which is what "N open" on the Mind's header needs. `cursor` is nil or `c`: the cards whose `order` is below N; a client treats it as opaque and sends back the `next_cursor` it was given. `list`: `{mind, stamp, open_count, recorded_count, forks[entry], next_cursor}`. The counts cover every card the viewer may see, whatever `status` and `cursor` asked for. `stamp` is `s`, N the receiver's last-seen Huginn admission ordinal for the Mind's desk documents: the same stamp means the same state, so a desk polls `limit` 0 and fetches bodies only when the stamp moves. `next_cursor` is nil on the last page. An `entry` is `{card, record}`: the card and its `record` (the answers with their outcomes and the derived `counted_answer_id`). @@ -114,7 +114,7 @@ Calls 1 and 2 are enough for a read-only desk. Every response is the pinned Mess **Answer.** The body is the `answer_request` and nothing else a client may set: `fork_id`, `options_hash`, `answer`, `answered_at` (plus `retracted` and `retracts`, written `false` and nil unless the call retracts). The response is the stored outcome: `Counted`, `Revision`, `Retraction`, or `Refused` with its code. **A `stale_fork` refusal carries the current card** in `answer_result.card`, so the desk can show the new fork without another read. Nothing is stored for a step 1 or 2 refusal or an unknown fork, and nothing for `unavailable`. -**Vectors (`transport` in `fork-card-vectors.json`).** `listRequest`, `readRequest` and `entry` (valid and invalid, with bytes); `listInvalid`; `listScenarios` (five scenarios over one Mind's five cards: paged open-only, recorded-only, all, `limit` 0, an empty Mind, each response with its bytes, the cursor of page two being page one's `next_cursor`); `authCases` (thirteen token and route pairs, among them the MAS token, three `votes.*` tokens, a desk token with the other route's scope). Both suites replay the list requests through a reference judge and the auth cases through another. Top-level `unavailable` pins the 503 document, and two scenarios pin that an unreachable door stores nothing and that a bad body is refused before the door is asked. +**Vectors (`transport` in `fork-card-vectors.json`).** `listRequest`, `readRequest` and `entry` (valid and invalid, with bytes); `listInvalid`; `listScenarios` (five scenarios over one Mind's five cards: paged open-only, recorded-only, all, `limit` 0, an empty Mind, each response with its bytes, the cursor of page two being page one's `next_cursor`); `authCases` (twenty-two cases: the MAS token, three `votes.*` tokens, a desk token with the other route's scope, a non-Active member on each route, and Huginn down on each route, with auth and membership judged first). Both suites replay the list requests through a reference judge and the auth cases through another. Top-level `unavailable` pins the 503 document, and two scenarios pin that an unreachable door stores nothing and that a bad body is refused before the door is asked. **Bifrost must still build:** all three routes; the `bifrost-desk` audience and the `desk.read` and `desk.answer` scopes on the OIDC token it issues to chat; the projection of cards and records from Huginn, the stamp, the cursor and the counts; the `DeskAnswer` call on the second door and the pass-through of its outcome; the `unavailable` answer. **Huginn must still build** the second door's wire and the read side the projection uses (Eureka's cut spec, after her record PR). **The desk may build today** against the vectors: nothing in them needs a live service. @@ -177,4 +177,4 @@ Option B, **Bifrost receives the answer and Huginn stores it** (the design in th 7. `received_at` is not in the binding file's stored fields; it is kept for `claim_in_future` and could be dropped if the ordinal alone decides order. 8. The stamped `authority` field is an attribution, not an authority (above); renaming it `attribution` would say so, at the price of a new key the door must also refuse in a body. 9. The audience name `bifrost-desk` and the three routes are this page's proposal beside Heimdall's scope names; his file will rule them. The claims Bifrost verifies are PR #24's open item 5. -10. The second door's wire between Bifrost and Huginn (pending Eureka's cut spec). `unavailable` is a document of its own, outside the refusal set, so a desk can retry it; whether the same document also covers calls 1 and 2 when Huginn is down is assumed here and is Bifrost's to confirm. +10. The second door's wire between Bifrost and Huginn (pending Eureka's cut spec). `unavailable` is a document of its own, outside the refusal set, so a desk can retry it; calls 1 and 2 use it too when Huginn is down (vectors `huginn_down_*`). diff --git a/contracts/cultnet/governance/fork-card.schema.json b/contracts/cultnet/governance/fork-card.schema.json index 5521364c..356e7f74 100644 --- a/contracts/cultnet/governance/fork-card.schema.json +++ b/contracts/cultnet/governance/fork-card.schema.json @@ -674,6 +674,7 @@ "body_invalid", "fork_unknown", "insufficient_scope", + "forbidden", "request_invalid" ] }, diff --git a/packages/cultnet-ts/test/governance-vectors.test.ts b/packages/cultnet-ts/test/governance-vectors.test.ts index f1e1092f..ec8f6d4a 100644 --- a/packages/cultnet-ts/test/governance-vectors.test.ts +++ b/packages/cultnet-ts/test/governance-vectors.test.ts @@ -336,9 +336,11 @@ const judgeList = (entries: { card: Card }[], ordinal: number, rq: { mind: strin }; // Bearer, audience, scope, in that order: a votes.* token fails at the audience and a desk token without the route's scope fails at the scope. -const authJudge = (route: string, token: { audience: string; scopes: string[] } | null): string => { +const authJudge = (route: string, token: { audience: string; scopes: string[]; active: boolean } | null, huginnDown: boolean): string => { if (token === null || token.audience !== "bifrost-desk") return "unauthenticated"; - return token.scopes.includes(route === "answer" ? "desk.answer" : "desk.read") ? "ok" : "insufficient_scope"; + if (!token.scopes.includes(route === "answer" ? "desk.answer" : "desk.read")) return "insufficient_scope"; + if (!token.active) return "forbidden"; + return huginnDown ? "unavailable" : "ok"; }; test("fork transport: requests and entries validate and encode to the vector bytes, and every negative is refused", () => { @@ -381,10 +383,10 @@ test("fork transport: auth is bearer, then audience, then scope, and a votes tok const codes = (forkSchema.$defs.refusal.properties.code as { enum: string[] }).enum; const seen = new Set(); for (const c of fork.transport.authCases) { - const got = authJudge(c.route, c.token); + const got = authJudge(c.route, c.token, c.huginn_down); assert.equal(got, c.expect, c.name); - if (got !== "ok") assert.ok(codes.includes(got), c.name); + if (got !== "ok" && got !== "unavailable") assert.ok(codes.includes(got), c.name); seen.add(`${c.route}:${got}`); } - for (const want of ["list:insufficient_scope", "answer:insufficient_scope", "read:unauthenticated", "answer:ok"]) assert.ok(seen.has(want), want); + for (const want of ["list:insufficient_scope", "answer:insufficient_scope", "read:forbidden", "list:unavailable", "read:unavailable", "answer:unavailable", "read:unauthenticated", "answer:ok"]) assert.ok(seen.has(want), want); }); diff --git a/scripts/gen-governance-vectors.py b/scripts/gen-governance-vectors.py index dfd444a9..0ccc2c0f 100644 --- a/scripts/gen-governance-vectors.py +++ b/scripts/gen-governance-vectors.py @@ -218,7 +218,7 @@ NOTE = "Keep it local: a slot mark is the author's call, and sharing it is a sep def srv(aid, who, at, auth="Operator"): return {"answer_id": aid, "answerer": who, "authority": auth, "received_at": at} TAIL = {"unauthenticated": "a verified session is required", "body_forbidden_field": "answerer and authority are set by the receiver", "body_unknown_field": "the body is a closed shape", "body_invalid": "the body does not satisfy gamecult.fork.answer_request.v0", "fork_unknown": "no such fork", - "insufficient_scope": "the token lacks the scope this route needs", "request_invalid": "the request does not satisfy its document"} + "insufficient_scope": "the token lacks the scope this route needs", "forbidden": "only Active members may use the desk", "request_invalid": "the request does not satisfy its document"} DOOR = set(TAIL) def refusal_doc(code): return {"schemaVersion": "gamecult.fork.refusal.v0", "code": code, "error": f"{code}: {TAIL[code]}"} def unavailable_doc(retry=30): return {"schemaVersion": "gamecult.fork.unavailable.v0", "code": "unavailable", "error": "unavailable: the answer path is down, try again", "retryAfterSeconds": retry} @@ -306,7 +306,7 @@ scen = [ sc("after_every_answer_is_retracted_a_fresh_answer_is_Counted_again", CARD, [X1, ok(RET("n1"), sr("n8"), "Retraction", "n1"), ok(x2, sx2, "Counted", None)], "n2"), ] REASON_CODES = ["stale_fork", "not_a_decider", "fork_closed", "choice_invalid", "bad_retraction", "already_retracted"] -HTTP = {"unauthenticated": 401, "body_forbidden_field": 400, "body_unknown_field": 400, "body_invalid": 400, "fork_unknown": 404, "insufficient_scope": 403, "request_invalid": 400, +HTTP = {"unauthenticated": 401, "body_forbidden_field": 400, "body_unknown_field": 400, "body_invalid": 400, "fork_unknown": 404, "insufficient_scope": 403, "forbidden": 403, "request_invalid": 400, "stale_fork": 409, "not_a_decider": 403, "fork_closed": 409, "choice_invalid": 400, "bad_retraction": 400, "already_retracted": 409} STORED_REFUSALS = [] for reason in REASON_CODES: @@ -359,7 +359,7 @@ LISTS = [ {"name": "limit_zero_is_the_count_and_stamp_only", "ordinal": 412, "entries": ENTRIES, "steps": [lstep(ENTRIES, 412, lreq(limit=0))]}, {"name": "a_mind_with_no_forks", "ordinal": 7, "entries": [], "steps": [lstep([], 7, lreq(mind="nibu", limit=10))]}, ] -TOK = lambda aud, *sc: {"audience": aud, "scopes": list(sc)} +TOK = lambda aud, *sc, active=True: {"audience": aud, "scopes": list(sc), "active": active} AUTH = [ ("list_with_desk_read", "list", TOK("bifrost-desk", "desk.read"), "ok"), ("read_with_desk_read", "read", TOK("bifrost-desk", "desk.read"), "ok"), ("answer_with_desk_answer", "answer", TOK("bifrost-desk", "desk.answer"), "ok"), ("answer_with_both_scopes", "answer", TOK("bifrost-desk", "desk.read", "desk.answer"), "ok"), @@ -371,6 +371,15 @@ AUTH = [ ("desk_audience_with_a_votes_scope_only", "answer", TOK("bifrost-desk", "votes.cast"), "insufficient_scope"), ("desk_read_cannot_answer", "answer", TOK("bifrost-desk", "desk.read"), "insufficient_scope"), ("desk_answer_cannot_list", "list", TOK("bifrost-desk", "desk.answer"), "insufficient_scope"), + ("a_non_active_member_cannot_list", "list", TOK("bifrost-desk", "desk.read", active=False), "forbidden"), + ("a_non_active_member_cannot_read", "read", TOK("bifrost-desk", "desk.read", active=False), "forbidden"), + ("a_non_active_member_cannot_answer", "answer", TOK("bifrost-desk", "desk.answer", active=False), "forbidden"), + ("scope_is_judged_before_membership", "answer", TOK("bifrost-desk", "desk.read", active=False), "insufficient_scope"), + ("huginn_down_list", "list", TOK("bifrost-desk", "desk.read"), "unavailable", True), + ("huginn_down_read", "read", TOK("bifrost-desk", "desk.read"), "unavailable", True), + ("huginn_down_answer", "answer", TOK("bifrost-desk", "desk.answer"), "unavailable", True), + ("auth_is_judged_before_huginn_is_asked", "list", None, "unauthenticated", True), + ("membership_is_judged_before_huginn_is_asked", "read", TOK("bifrost-desk", "desk.read", active=False), "forbidden", True), ] def bad(name, why, m, **kw): return dict({"name": name, "why": why, "message": m}, **kw) fork = { @@ -460,7 +469,7 @@ fork = { ("stamp_malformed", "a stamp is s", dict(LISTS[0]["steps"][0]["response"], stamp="412")), ("count_negative", "counts are not negative", dict(LISTS[0]["steps"][0]["response"], open_count=-1))]], "listScenarios": [{"name": l["name"], "ordinal": l["ordinal"], "entries": l["entries"], "steps": l["steps"]} for l in LISTS], - "authCases": [{"name": n, "route": r, "token": t, "expect": x} for n, r, t, x in AUTH], + "authCases": [{"name": a[0], "route": a[1], "token": a[2], "expect": a[3], "huginn_down": len(a) > 4} for a in AUTH], }, "scenarios": [{"name": n, "card": c, "optionsHash": c["options_hash"], "steps": steps, "record": r, "recordHex": hx(r)} for n, c, steps, r in scen], } diff --git a/tests/GameCult.Networking.Tests/GovernanceVectorTests.cs b/tests/GameCult.Networking.Tests/GovernanceVectorTests.cs index 51af26d8..01eda748 100644 --- a/tests/GameCult.Networking.Tests/GovernanceVectorTests.cs +++ b/tests/GameCult.Networking.Tests/GovernanceVectorTests.cs @@ -475,11 +475,13 @@ namespace GameCult.Networking.Tests } // Bearer, audience, scope, in that order: a votes.* token fails at the audience and a desk token without the route's scope fails at the scope. - private static string AuthJudge(string route, JsonNode? token) + private static string AuthJudge(string route, JsonNode? token, bool huginnDown) { if (token is null || S(token["audience"]) != "bifrost-desk") return "unauthenticated"; var need = route == "answer" ? "desk.answer" : "desk.read"; - return token["scopes"]!.AsArray().Any(x => S(x) == need) ? "ok" : "insufficient_scope"; + if (!token["scopes"]!.AsArray().Any(x => S(x) == need)) return "insufficient_scope"; + if (!token["active"]!.GetValue()) return "forbidden"; + return huginnDown ? "unavailable" : "ok"; } [Test] @@ -538,12 +540,12 @@ namespace GameCult.Networking.Tests var seen = new HashSet(); foreach (var c in Fork["transport"]!["authCases"]!.AsArray()) { - var got = AuthJudge(S(c!["route"]), c["token"]); + var got = AuthJudge(S(c!["route"]), c["token"], c["huginn_down"]!.GetValue()); Assert.That(got, Is.EqualTo(S(c["expect"])), S(c["name"])); - if (got != "ok") Assert.That(codes, Does.Contain(got), S(c["name"])); + if (got is not ("ok" or "unavailable")) Assert.That(codes, Does.Contain(got), S(c["name"])); seen.Add(S(c["route"]) + ":" + got); } - Assert.That(seen, Does.Contain("list:insufficient_scope").And.Contain("answer:insufficient_scope").And.Contain("read:unauthenticated").And.Contain("answer:ok")); + Assert.That(seen, Does.Contain("list:insufficient_scope").And.Contain("answer:insufficient_scope").And.Contain("read:forbidden").And.Contain("list:unavailable").And.Contain("read:unavailable").And.Contain("answer:unavailable").And.Contain("read:unauthenticated").And.Contain("answer:ok")); } } }