feat(workflow): example covers security, platform, enterprise and resilience features
105 route tests, matrix crawl, spec and README updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
// Route: /crypto/hash (real SHA-256 and HMAC-SHA256)
|
||||
#include "support/Assert.hpp"
|
||||
using namespace molo::example::test;
|
||||
static const char* kForm = "application/x-www-form-urlencoded";
|
||||
int main() {
|
||||
Fixture f;
|
||||
check(contains(f.client->get("/crypto/hash").body, "<form"), "form renders");
|
||||
auto r = f.client->post("/crypto/hash", "text=abc", kForm);
|
||||
check(r.status == 200, "status 200");
|
||||
check(contains(r.body, "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"), "sha256(abc) vector");
|
||||
auto m = f.client->post("/crypto/hash", "text=what+do+ya+want+for+nothing%3F&key=Jefe", kForm);
|
||||
check(contains(m.body, "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"), "RFC 4231 hmac vector");
|
||||
auto bad = f.client->post("/crypto/hash", "text=", kForm);
|
||||
check(bad.status == 422 && contains(bad.body, "form-errors"), "empty text inline 422");
|
||||
auto big = f.client->post("/crypto/hash", "text=" + std::string(5000, 'a'), kForm);
|
||||
check(big.status == 422, "over cap 422");
|
||||
check(f.client->request(molo::example::fw::Method::Put, "/crypto/hash").status == 405, "PUT is 405");
|
||||
return finish("crypto/hash");
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Route: /crypto/password (salted PBKDF2, demo rounds)
|
||||
#include "support/Assert.hpp"
|
||||
using namespace molo::example::test;
|
||||
static const char* kForm = "application/x-www-form-urlencoded";
|
||||
int main() {
|
||||
Fixture f;
|
||||
check(contains(f.client->get("/crypto/password").body, "DEMO"), "labelled demo");
|
||||
auto a = f.client->post("/crypto/password", "password=correct-horse", kForm);
|
||||
auto b = f.client->post("/crypto/password", "password=correct-horse", kForm);
|
||||
check(a.status == 200 && contains(a.body, "pbkdf2-demo$2000$"), "hash format");
|
||||
check(contains(a.body, "verify ok: yes") && contains(a.body, "wrong password: rejected"), "verify works");
|
||||
auto salt = [](const std::string& s) { std::size_t p = s.find("pbkdf2-demo$2000$"); return s.substr(p + 17, 32); };
|
||||
check(salt(a.body) != salt(b.body), "salt differs per hash");
|
||||
auto bad = f.client->post("/crypto/password", "password=short", kForm);
|
||||
check(bad.status == 422 && contains(bad.body, "must be 8 to 128"), "short password inline 422");
|
||||
check(f.client->post("/crypto/password", "password=" + std::string(129, 'a'), kForm).status == 422, "over cap 422");
|
||||
return finish("crypto/password");
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Route: GET /crypto/random (urandom token, 1 to 64 bytes)
|
||||
#include "support/Assert.hpp"
|
||||
using namespace molo::example::test;
|
||||
int main() {
|
||||
Fixture f;
|
||||
auto a = f.client->get("/crypto/random?bytes=8");
|
||||
auto b = f.client->get("/crypto/random?bytes=8");
|
||||
check(a.status == 200 && contains(a.body, "\"bytes\":8"), "8 bytes ok");
|
||||
check(a.body != b.body, "tokens differ");
|
||||
check(f.client->get("/crypto/random").status == 200, "default ok");
|
||||
check(f.client->get("/crypto/random?bytes=65").status == 400, "over cap 400");
|
||||
check(f.client->get("/crypto/random?bytes=abc").status == 400, "non numeric 400");
|
||||
check(f.client->post("/crypto/random", "x").status == 405, "POST 405");
|
||||
return finish("crypto/random");
|
||||
}
|
||||
Reference in New Issue
Block a user