NetworkedApplications: auth-scoped operation outcome lookup endpoint (P-NETWORKED-03)
This commit is contained in:
1 parent
50595bdabc
commit
0f1cf89cfc
10 files changed
+175
-1
No files matched your search
@@ -117,6 +117,31 @@ namespace
|
||||
assert(got.has_value() && got->has_value());
|
||||
assert((*got)->version == 5);
|
||||
}
|
||||
|
||||
void operation_lookup_reports_recorded_outcomes()
|
||||
{
|
||||
MemoryKvStore store;
|
||||
auto applied =
|
||||
store.put("k", "v", Precondition::absent(), {"op-1"});
|
||||
assert(applied.has_value());
|
||||
assert(applied->outcome == WriteOutcome::Applied);
|
||||
|
||||
// A replayed request id resolves to the original outcome.
|
||||
auto replayed = store.put("k", "ignored", Precondition::absent(),
|
||||
{"op-1"});
|
||||
assert(replayed.has_value());
|
||||
assert(replayed->version == applied->version);
|
||||
|
||||
auto known = store.lookup_operation({"op-1"});
|
||||
assert(known.has_value() && known->has_value());
|
||||
assert((*known)->outcome == WriteOutcome::Applied);
|
||||
assert((*known)->version == applied->version);
|
||||
|
||||
// Unknown ids are absent (not an error), and invalid ids are errors.
|
||||
auto absent = store.lookup_operation({"never-used"});
|
||||
assert(absent.has_value() && !absent->has_value());
|
||||
assert(!store.lookup_operation({""}).has_value());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main()
|
||||
@@ -125,6 +150,7 @@ int main()
|
||||
input_validation();
|
||||
bounded_scan();
|
||||
bounded_operation_records();
|
||||
operation_lookup_reports_recorded_outcomes();
|
||||
std::puts("networked-kv domain ok");
|
||||
return 0;
|
||||
}
|
||||
@@ -112,6 +112,35 @@ namespace
|
||||
404);
|
||||
}
|
||||
|
||||
void operation_status_endpoint()
|
||||
{
|
||||
MemoryKvStore store;
|
||||
KvApi api{store, ApiConfig{.bearer_token = "secret"}};
|
||||
|
||||
auto put = authed(make_request("PUT", "/v1/kv/a", "one"));
|
||||
put.headers["x-request-id"] = "op-1";
|
||||
put.headers["if-none-match"] = "*";
|
||||
assert(api.handle(put).status == 200);
|
||||
|
||||
auto known =
|
||||
api.handle(authed(make_request("GET", "/v1/operations/op-1")));
|
||||
assert(known.status == 200);
|
||||
assert(known.body.find("\"outcome\":\"applied\"") != std::string::npos);
|
||||
|
||||
// Absence is explicitly unknown, not a 404 claiming no commit.
|
||||
auto unknown =
|
||||
api.handle(authed(make_request("GET", "/v1/operations/missing")));
|
||||
assert(unknown.status == 200);
|
||||
assert(unknown.body.find("\"outcome\":\"unknown\"") !=
|
||||
std::string::npos);
|
||||
|
||||
// The endpoint requires authentication like the data plane.
|
||||
assert(api.handle(make_request("GET", "/v1/operations/op-1")).status ==
|
||||
401);
|
||||
assert(api.handle(authed(make_request("POST", "/v1/operations/op-1")))
|
||||
.status == 405);
|
||||
}
|
||||
|
||||
void scan_is_bounded()
|
||||
{
|
||||
MemoryKvStore store{Limits{.max_scan_page = 2}};
|
||||
@@ -169,6 +198,7 @@ int main()
|
||||
kv_lifecycle_over_http();
|
||||
request_validation();
|
||||
scan_is_bounded();
|
||||
operation_status_endpoint();
|
||||
admin_views_are_bounded();
|
||||
std::puts("networked-kv http api ok");
|
||||
return 0;
|
||||
|
||||
@@ -92,6 +92,14 @@ int main()
|
||||
assert(replay.has_value());
|
||||
assert(replay->version == 2);
|
||||
|
||||
// Idempotency outcomes survive the reopen and are queryable.
|
||||
auto known = kv.lookup_operation({"r3"});
|
||||
assert(known.has_value() && known->has_value());
|
||||
assert((*known)->outcome == WriteOutcome::Applied);
|
||||
assert((*known)->version == 2);
|
||||
auto absent = kv.lookup_operation({"never-used"});
|
||||
assert(absent.has_value() && !absent->has_value());
|
||||
|
||||
auto removed = kv.erase("a", Precondition::at_version(2), {"r4"});
|
||||
assert(removed.has_value());
|
||||
assert(removed->outcome == WriteOutcome::Applied);
|
||||
|
||||
Reference in new issue
Block a user