|
@@ -2056,3 +2056,79 @@ TEST(HostContextMail, AnUndecodableSubjectComesBackAsItArrivedRatherThanFailing)
|
|
|
out.result.value.at("value").at("messages").front().at("subject").get<std::string>();
|
|
out.result.value.at("value").at("messages").front().at("subject").get<std::string>();
|
|
|
EXPECT_FALSE(subject.empty()) << "an undecodable subject must not vanish";
|
|
EXPECT_FALSE(subject.empty()) << "an undecodable subject must not vanish";
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// WHAT AN ERROR CARRIES INTO JS, PINNED PER CHANNEL AND ACROSS THREE REAL
|
|
|
|
|
+// SHAPES. A consumer's fault classifier reads `code`, `status`, `String(e)` and
|
|
|
|
|
+// `details` one arm at a time, and three round trips in one evening went on
|
|
|
|
|
+// establishing which of them was populated - twice settled by a guess that was
|
|
|
|
|
+// wrong. Every value asserted here was OBSERVED first and then written down,
|
|
|
|
|
+// which is the opposite order from the test this replaces: that one asserted a
|
|
|
|
|
+// `details` payload on a path that cannot produce one, and named itself after a
|
|
|
|
|
+// live incident it could not reproduce.
|
|
|
|
|
+//
|
|
|
|
|
+// The three shapes are deliberately contrasted rather than tested separately,
|
|
|
|
|
+// because the only interesting claim is which channel DIFFERS between them.
|
|
|
|
|
+TEST(HostContext, EveryErrorChannelIsPinnedAcrossTheThreeShapesAnErrorCanHave) {
|
|
|
|
|
+ auto out = runScript(
|
|
|
|
|
+ httpTrigger({}),
|
|
|
|
|
+ "export default async function (ctx) {"
|
|
|
|
|
+ " const r = {};"
|
|
|
|
|
+ " const grab = (e) => ({ code: e.code, status: e.status, str: String(e),"
|
|
|
|
|
+ " hasDetails: e.details !== undefined,"
|
|
|
|
|
+ " hasStatus: e.status !== undefined });"
|
|
|
|
|
+ // (1) a host ApiError that DOES carry details: the scope refusal names
|
|
|
|
|
+ // the collection, the operation and what the key is granted.
|
|
|
|
|
+ " try { ctx.files.get('logo.png'); r.scope = { reached: true }; }"
|
|
|
|
|
+ " catch (e) { r.scope = grab(e); }"
|
|
|
|
|
+ // (2) a host ApiError that carries NONE.
|
|
|
|
|
+ " try { await ctx.fetch('http://127.0.0.1:9/x'); r.egress = { reached: true }; }"
|
|
|
|
|
+ " catch (e) { r.egress = grab(e); }"
|
|
|
|
|
+ // (3) a refusal raised by the PRELUDE rather than by the host.
|
|
|
|
|
+ " try { ctx.collections('nope').get({}); r.prelude = { reached: true }; }"
|
|
|
|
|
+ " catch (e) { r.prelude = grab(e); }"
|
|
|
|
|
+ " return r;"
|
|
|
|
|
+ "}");
|
|
|
|
|
+ ASSERT_TRUE(out.result.ok) << out.result.error;
|
|
|
|
|
+ const auto& v = out.result.value;
|
|
|
|
|
+ for (const char* k : {"scope", "egress", "prelude"})
|
|
|
|
|
+ ASSERT_FALSE(v.at(k).contains("reached")) << k << " was not refused at all";
|
|
|
|
|
+
|
|
|
|
|
+ // `code` is a FIELD on all three, which is why digging a slug out of the
|
|
|
|
|
+ // message is a branch that can never fire for an error raised here.
|
|
|
|
|
+ EXPECT_EQ(v.at("scope").at("code").get<std::string>(), "forbidden");
|
|
|
|
|
+ EXPECT_EQ(v.at("egress").at("code").get<std::string>(), "egress_blocked");
|
|
|
|
|
+ EXPECT_EQ(v.at("prelude").at("code").get<std::string>(), "validation");
|
|
|
|
|
+
|
|
|
|
|
+ // `status` is a NUMBER on a HOST error and ABSENT on a prelude one. A
|
|
|
|
|
+ // classifier that keys on status alone is therefore blind to every prelude
|
|
|
|
|
+ // refusal, and one that treats a missing status as 0 or as a 5xx is worse
|
|
|
|
|
+ // than blind. This asymmetry was not documented anywhere before tonight.
|
|
|
|
|
+ ASSERT_TRUE(v.at("scope").at("status").is_number_integer());
|
|
|
|
|
+ EXPECT_EQ(v.at("scope").at("status").get<int>(), 403);
|
|
|
|
|
+ EXPECT_EQ(v.at("egress").at("status").get<int>(), 403);
|
|
|
|
|
+ EXPECT_TRUE(v.at("scope").at("hasStatus").get<bool>());
|
|
|
|
|
+ EXPECT_TRUE(v.at("egress").at("hasStatus").get<bool>());
|
|
|
|
|
+ EXPECT_FALSE(v.at("prelude").at("hasStatus").get<bool>())
|
|
|
|
|
+ << "a prelude refusal gained a status; a consumer may be keying on its absence";
|
|
|
|
|
+
|
|
|
|
|
+ // `String(e)` carries the MESSAGE on all three, because throwApiError sets
|
|
|
|
|
+ // `message` on a JS Error and Error.prototype.toString() is name + ": " +
|
|
|
|
|
+ // message. This was an open question between two sessions, and it decides
|
|
|
|
|
+ // whether a classifier scanning the stringified error can still see a cause
|
|
|
|
|
+ // that reached only the message - which is every error built by guarded()'s
|
|
|
|
|
+ // generic arm, where the slug is the literal "internal" and the real cause
|
|
|
|
|
+ // is the underlying what() text.
|
|
|
|
|
+ EXPECT_NE(v.at("scope").at("str").get<std::string>().find("_files"), std::string::npos);
|
|
|
|
|
+ EXPECT_NE(v.at("egress").at("str").get<std::string>().find("Error"), std::string::npos);
|
|
|
|
|
+ EXPECT_NE(v.at("prelude").at("str").get<std::string>().find("Error"), std::string::npos);
|
|
|
|
|
+
|
|
|
|
|
+ // `details` is present ONLY where the ApiError actually carried some. THIS
|
|
|
|
|
+ // is the assertion that kills the fiction: a classifier cannot scan
|
|
|
|
|
+ // `details` for a cause on an error that has none, and guarded()'s generic
|
|
|
|
|
+ // arm constructs its ApiError with no details argument at all - so on the
|
|
|
|
|
+ // path that mis-tagged a database deadline, `details` was never a channel.
|
|
|
|
|
+ EXPECT_TRUE(v.at("scope").at("hasDetails").get<bool>())
|
|
|
|
|
+ << "the scope refusal stopped carrying collection/operation/granted";
|
|
|
|
|
+ EXPECT_FALSE(v.at("egress").at("hasDetails").get<bool>());
|
|
|
|
|
+ EXPECT_FALSE(v.at("prelude").at("hasDetails").get<bool>());
|
|
|
|
|
+}
|