Kelsidavis-WoWee/tests/test_srp.cpp
Paul e58f9b4b40 feat(animation): 452 named constants, 30-phase character animation state machine
Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND,
anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1)
lookup, and flyVariant() compact 218-element ground→FLY_* resolver.

Expand AnimationController into a full state machine with 20+ named states:
spell cast (directed→omni→cast fallback chain, instant one-shot release),
hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle,
stealth animation substitution, loot, fishing channel, sit/sleep/kneel
down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons
(BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY,
vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS),
emote state variants, off-hand/pierce/dual-wield alternation, NPC
birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell.

Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo
(12 constants) namespaces; replace all magic numbers in spell_handler.cpp.

Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire
GameObjectStateCallback. Add DBC cross-validation on world entry.

Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and
asset_pipeline_gui.py. Add tests/test_animation_ids.cpp.

Bug fixes included:
- Stand state 1 was animating READY_2H(27) — fixed to SITTING(97)
- Spell casts ended freeze-frame — add one-shot release animation
- NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff)
- Chair sits (states 2/4/5/6) incorrectly played floor-sit transition
- STOP(3) used for all spell casts — replaced with model-aware chain
2026-04-04 23:02:53 +03:00

127 lines
3.6 KiB
C++

// SRP6a challenge/proof smoke tests
#include <catch_amalgamated.hpp>
#include "auth/srp.hpp"
#include "auth/crypto.hpp"
using wowee::auth::SRP;
using wowee::auth::Crypto;
// WoW 3.3.5a uses well-known SRP6a parameters.
// Generator g = 7, N = a large 32-byte safe prime.
// We use the canonical WoW values for integration-level tests.
static const std::vector<uint8_t> kWoWGenerator = { 7 };
// WoW's 32-byte large safe prime (little-endian)
static const std::vector<uint8_t> kWoWPrime = {
0xB7, 0x9B, 0x3E, 0x2A, 0x87, 0x82, 0x3C, 0xAB,
0x8F, 0x5E, 0xBF, 0xBF, 0x8E, 0xB1, 0x01, 0x08,
0x53, 0x50, 0x06, 0x29, 0x8B, 0x5B, 0xAD, 0xBD,
0x5B, 0x53, 0xE1, 0x89, 0x5E, 0x64, 0x4B, 0x89
};
TEST_CASE("SRP initialize stores credentials", "[srp]") {
SRP srp;
// Should not throw
REQUIRE_NOTHROW(srp.initialize("TEST", "PASSWORD"));
}
TEST_CASE("SRP initializeWithHash accepts pre-computed hash", "[srp]") {
// Pre-compute SHA1("TEST:PASSWORD")
auto hash = Crypto::sha1(std::string("TEST:PASSWORD"));
REQUIRE(hash.size() == 20);
SRP srp;
REQUIRE_NOTHROW(srp.initializeWithHash("TEST", hash));
}
TEST_CASE("SRP feed produces A and M1 of correct sizes", "[srp]") {
SRP srp;
srp.initialize("TEST", "PASSWORD");
// Fabricate a server B (32 bytes, non-zero to avoid SRP abort)
std::vector<uint8_t> B(32, 0);
B[0] = 0x42; // Non-zero
std::vector<uint8_t> salt(32, 0xAA);
srp.feed(B, kWoWGenerator, kWoWPrime, salt);
auto A = srp.getA();
auto M1 = srp.getM1();
auto K = srp.getSessionKey();
// A should be 32 bytes (same size as N)
REQUIRE(A.size() == 32);
// M1 is SHA1 → 20 bytes
REQUIRE(M1.size() == 20);
// K is the interleaved session key → 40 bytes
REQUIRE(K.size() == 40);
}
TEST_CASE("SRP A is non-zero", "[srp]") {
SRP srp;
srp.initialize("PLAYER", "SECRET");
std::vector<uint8_t> B(32, 0);
B[3] = 0x01;
std::vector<uint8_t> salt(32, 0xBB);
srp.feed(B, kWoWGenerator, kWoWPrime, salt);
auto A = srp.getA();
bool allZero = true;
for (auto b : A) {
if (b != 0) { allZero = false; break; }
}
REQUIRE_FALSE(allZero);
}
TEST_CASE("SRP different passwords produce different M1", "[srp]") {
auto runSrp = [](const std::string& pass) {
SRP srp;
srp.initialize("TESTUSER", pass);
std::vector<uint8_t> B(32, 0);
B[0] = 0x11;
std::vector<uint8_t> salt(32, 0xCC);
srp.feed(B, kWoWGenerator, kWoWPrime, salt);
return srp.getM1();
};
auto m1a = runSrp("PASSWORD1");
auto m1b = runSrp("PASSWORD2");
REQUIRE(m1a != m1b);
}
TEST_CASE("SRP verifyServerProof rejects wrong proof", "[srp]") {
SRP srp;
srp.initialize("TEST", "PASSWORD");
std::vector<uint8_t> B(32, 0);
B[0] = 0x55;
std::vector<uint8_t> salt(32, 0xDD);
srp.feed(B, kWoWGenerator, kWoWPrime, salt);
// Random 20 bytes should not match the expected M2
std::vector<uint8_t> fakeM2(20, 0xFF);
REQUIRE_FALSE(srp.verifyServerProof(fakeM2));
}
TEST_CASE("SRP setUseHashedK changes behavior", "[srp]") {
auto runWithHashedK = [](bool useHashed) {
SRP srp;
srp.setUseHashedK(useHashed);
srp.initialize("TEST", "PASSWORD");
std::vector<uint8_t> B(32, 0);
B[0] = 0x22;
std::vector<uint8_t> salt(32, 0xEE);
srp.feed(B, kWoWGenerator, kWoWPrime, salt);
return srp.getM1();
};
auto m1_default = runWithHashedK(false);
auto m1_hashed = runWithHashedK(true);
// Different k derivation → different M1
REQUIRE(m1_default != m1_hashed);
}