322 lignes
16 KiB
Java
322 lignes
16 KiB
Java
package com.gastinelgarde.core;
|
||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||
|
||
import java.nio.file.Files;
|
||
import java.nio.file.Path;
|
||
import java.time.LocalDate;
|
||
import java.time.ZoneOffset;
|
||
import java.util.List;
|
||
import java.util.UUID;
|
||
import org.junit.jupiter.api.Test;
|
||
|
||
/**
|
||
* Preuves de l'audit 2026-10-14. NE PAS copier dans src/test : à lancer dans une copie jetable.
|
||
* Chaque test porte l'identifiant de la faille (voir audit/02-failles-detection.md).
|
||
* Convention : un test « BYPASS » ou « FAUX_POSITIF » est vert tant que la faille existe ; il passera au rouge
|
||
* quand la correction sera appliquée (alors, inverser l'assertion).
|
||
*/
|
||
class AuditFaillesTest {
|
||
|
||
private final GardeConfig cfg = new GardeConfig();
|
||
private final Moteur moteur = new Moteur(cfg);
|
||
private final UUID j = UUID.randomUUID();
|
||
|
||
private static EtatMouvement mv(double dxz, double dy, int ticks, boolean solServeur, boolean sprint) {
|
||
return new EtatMouvement(dxz, dy, ticks, solServeur, solServeur, sprint, false, false, 0, 0, false, false);
|
||
}
|
||
|
||
private static boolean contient(List<Verdict> v, Controle c) {
|
||
return v.stream().anyMatch(x -> x.controle() == c);
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F01
|
||
/** Le HEAD du mixin tourne aussi sur le thread réseau : chaque paquet est compté deux fois. */
|
||
@Test
|
||
void F01_timer_paquet_compte_deux_fois_faux_positif() {
|
||
boolean simple = false;
|
||
UUID a = UUID.randomUUID();
|
||
for (long t = 0; t < 10_000; t += 50) {
|
||
if (contient(moteur.paquetMouvement(a, t, EtatJoueur.normal()), Controle.TIMER)) simple = true;
|
||
}
|
||
assertFalse(simple, "20 paquets/s comptés une fois : aucune infraction");
|
||
|
||
boolean double_ = false;
|
||
UUID b = UUID.randomUUID();
|
||
for (long t = 0; t < 10_000; t += 50) {
|
||
moteur.paquetMouvement(b, t, EtatJoueur.normal()); // thread réseau
|
||
if (contient(moteur.paquetMouvement(b, t + 1, EtatJoueur.normal()), Controle.TIMER)) double_ = true; // thread serveur
|
||
}
|
||
assertTrue(double_, "20 paquets/s comptés deux fois = 40/s : infraction pour un joueur honnête");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F02
|
||
/** Au-delà de ~512 paquets/s la fenêtre circulaire ne couvre plus 2 s : le timer ne voit plus rien. */
|
||
@Test
|
||
void F02_timer_inondation_BYPASS() {
|
||
UUID flood = UUID.randomUUID();
|
||
boolean vu = false;
|
||
for (long t = 0; t < 8000; t++) { // 1 paquet par ms = 1000/s
|
||
if (contient(moteur.paquetMouvement(flood, t, EtatJoueur.normal()), Controle.TIMER)) vu = true;
|
||
}
|
||
assertFalse(vu, "1000 paquets/s ne lèvent AUCUNE infraction (fenêtre de 512)");
|
||
|
||
UUID modere = UUID.randomUUID();
|
||
boolean vuModere = false;
|
||
for (long t = 0; t < 8000; t += 10) { // 100 paquets/s
|
||
if (contient(moteur.paquetMouvement(modere, t, EtatJoueur.normal()), Controle.TIMER)) vuModere = true;
|
||
}
|
||
assertTrue(vuModere, "100 paquets/s sont bien vus (témoin)");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F03
|
||
/** Timer 1,1x (22 paquets/s) et rafales de type blink : invisibles. */
|
||
@Test
|
||
void F03_timer_faible_et_blink_BYPASS() {
|
||
UUID a = UUID.randomUUID();
|
||
boolean vu = false;
|
||
for (long t = 0; t < 60_000; t += 1000.0 / 22) {
|
||
if (contient(moteur.paquetMouvement(a, t, EtatJoueur.normal()), Controle.TIMER)) vu = true;
|
||
}
|
||
assertFalse(vu, "22 paquets/s soutenus pendant 60 s : jamais vu (+10 % de vitesse permanent)");
|
||
|
||
UUID b = UUID.randomUUID();
|
||
boolean vuBlink = false;
|
||
for (long t = 0; t < 5000; t += 50) moteur.paquetMouvement(b, t, EtatJoueur.normal()); // 20/s normal
|
||
// 5 s retenues puis libérées : 100 paquets en 1 s
|
||
for (int i = 0; i < 100; i++) {
|
||
if (contient(moteur.paquetMouvement(b, 10_000 + i * 10L, EtatJoueur.normal()), Controle.TIMER)) vuBlink = true;
|
||
}
|
||
assertFalse(vuBlink, "une rafale de 100 paquets après 5 s de silence passe (pas de balance cumulée)");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F04
|
||
/** Tenir un trident Impulsion relève le seuil vanilla de 100 à 10000 (carré) : 99 blocs par paquet passent. */
|
||
@Test
|
||
void F04_riptide_tenu_seuil_vanilla_neutralise_BYPASS() {
|
||
float vanilla = RiptideTolerance.seuil(100f, false, -1);
|
||
float tenu = RiptideTolerance.seuil(100f, true, -1); // le mixin passe riptide=true si le trident est en main
|
||
assertEquals(100f, vanilla);
|
||
assertEquals(10_000f, tenu);
|
||
double distance = 99.0; // un « TP » de 99 blocs en un paquet
|
||
assertTrue(distance * distance > vanilla, "refusé par vanilla (moved too quickly)");
|
||
assertFalse(distance * distance > tenu, "accepté dès qu'un trident Impulsion est en main");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F05
|
||
/** Tout teleport() vanilla (dont le setback du mod et un « moved too quickly » provoqué) ouvre 2 s d'exemption. */
|
||
@Test
|
||
void F05_grace_teleportation_rechargee_en_boucle_BYPASS() {
|
||
long now = 0;
|
||
boolean vu = false;
|
||
// vitesse folle de 1,0 bloc/tick ; un faux paquet « trop rapide » toutes les 30 ticks rechargerait la grâce
|
||
for (int tick = 0; tick < 600; tick++) {
|
||
int depuisTp = tick % 30;
|
||
EtatJoueur etat = EtatJoueur.builder().ticksDepuisTeleport(depuisTp).build();
|
||
if (!moteur.mouvement(j, now, etat, mv(1.0, 0, 1, true, true)).isEmpty()) vu = true;
|
||
now += 50;
|
||
}
|
||
assertFalse(vu, "30 s à 20 blocs/s : aucune infraction tant que la grâce est rechargée");
|
||
|
||
UUID t = UUID.randomUUID();
|
||
boolean vuSansTp = false;
|
||
now = 0;
|
||
for (int tick = 0; tick < 600; tick++) {
|
||
if (!moteur.mouvement(t, now, EtatJoueur.normal(), mv(1.0, 0, 1, true, true)).isEmpty()) vuSansTp = true;
|
||
now += 50;
|
||
}
|
||
assertTrue(vuSansTp, "témoin : sans grâce, la vitesse est vue");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F06
|
||
/** Tout dégât (feu, cactus, wither…) exempte le mouvement 20 ticks : se blesser toutes les secondes suffit. */
|
||
@Test
|
||
void F06_grace_degats_BYPASS() {
|
||
long now = 0;
|
||
boolean vu = false;
|
||
for (int tick = 0; tick < 600; tick++) {
|
||
EtatJoueur etat = EtatJoueur.builder().ticksDepuisRecul(tick % 20).build();
|
||
if (!moteur.mouvement(j, now, etat, mv(0.9, 0, 1, true, true)).isEmpty()) vu = true;
|
||
now += 50;
|
||
}
|
||
assertFalse(vu, "un dégât par seconde (<= 20 ticks, borne incluse) : exemption permanente");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F07
|
||
/** Un ping falsifié (PingSpoof) à plus de 250 ms multiplie tous les seuils par 1,5. */
|
||
@Test
|
||
void F07_ping_spoof_elargit_les_seuils_BYPASS() {
|
||
UUID honnete = UUID.randomUUID();
|
||
UUID spoof = UUID.randomUUID();
|
||
boolean vuNormal = false, vuSpoof = false;
|
||
long now = 0;
|
||
for (int tick = 0; tick < 200; tick++) {
|
||
EtatMouvement m = mv(0.40, 0, 1, true, true); // 0,40 bloc/tick au sol en sprint (vanilla : ~0,28)
|
||
if (!moteur.mouvement(honnete, now, EtatJoueur.builder().pingMs(30).build(), m).isEmpty()) vuNormal = true;
|
||
if (!moteur.mouvement(spoof, now, EtatJoueur.builder().pingMs(300).build(), m).isEmpty()) vuSpoof = true;
|
||
now += 50;
|
||
}
|
||
assertTrue(vuNormal, "ping 30 ms : vu");
|
||
assertFalse(vuSpoof, "ping 300 ms : la même vitesse n'est plus vue");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F08
|
||
/** Le contrôle de vol ne s'évalue que si exactement 1 tick sépare deux paquets. */
|
||
@Test
|
||
void F08_vol_aveugle_si_ticks_different_de_1_BYPASS() {
|
||
boolean vu1 = false, vu2 = false;
|
||
UUID a = UUID.randomUUID();
|
||
UUID b = UUID.randomUUID();
|
||
long now = 0;
|
||
for (int tick = 0; tick < 60; tick++) {
|
||
EtatMouvement hover1 = mv(0, 0, 1, false, false);
|
||
EtatMouvement hover2 = mv(0, 0, 2, false, false);
|
||
if (contient(moteur.mouvement(a, now, EtatJoueur.normal(), hover1), Controle.VOL)) vu1 = true;
|
||
if (contient(moteur.mouvement(b, now, EtatJoueur.normal(), hover2), Controle.VOL)) vu2 = true;
|
||
now += 50;
|
||
}
|
||
assertTrue(vu1, "hover à 1 paquet par tick : vu");
|
||
assertFalse(vu2, "hover avec un paquet tous les 2 ticks : jamais vu");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F09
|
||
/** Rester sous le tampon : +33 % au sol et +18 % en l'air, soutenus. */
|
||
@Test
|
||
void F09_vitesse_sous_le_tampon_BYPASS() {
|
||
UUID sol = UUID.randomUUID();
|
||
UUID air = UUID.randomUUID();
|
||
boolean vuSol = false, vuAir = false;
|
||
long now = 0;
|
||
for (int tick = 0; tick < 1200; tick++) {
|
||
if (contient(moteur.mouvement(sol, now, EtatJoueur.normal(), mv(0.37, 0, 1, true, true)), Controle.VITESSE)) vuSol = true;
|
||
if (contient(moteur.mouvement(air, now, EtatJoueur.normal(), mv(0.49, 0, 1, false, true)), Controle.VITESSE)) vuAir = true;
|
||
now += 50;
|
||
}
|
||
// vanilla : sprint au sol ~0,28 bloc/tick (5,6 b/s), saut en courant ~0,36
|
||
assertFalse(vuSol, "0,37 bloc/tick au sol (7,4 b/s, +32 %) soutenu 60 s : jamais vu");
|
||
assertFalse(vuAir, "0,49 bloc/tick en l'air (9,8 b/s) soutenu 60 s : jamais vu");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F10
|
||
/** Glace, âmes, eau, slime : le tick est ignoré, quelle que soit la vitesse. */
|
||
@Test
|
||
void F10_milieux_exemptes_totalement_BYPASS() {
|
||
boolean vu = false;
|
||
long now = 0;
|
||
for (int tick = 0; tick < 200; tick++) {
|
||
EtatMouvement glace = new EtatMouvement(3.0, 0, 1, true, true, true, false, false, 0, 0, false, true);
|
||
EtatMouvement eau = new EtatMouvement(3.0, 0, 1, false, false, true, false, false, 0, 0, true, false);
|
||
if (!moteur.mouvement(j, now, EtatJoueur.normal(), glace).isEmpty()) vu = true;
|
||
if (!moteur.mouvement(j, now, EtatJoueur.normal(), eau).isEmpty()) vu = true;
|
||
now += 50;
|
||
}
|
||
assertFalse(vu, "3 blocs/tick sur glace ou dans l'eau : aucune infraction (60 blocs/s)");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F11
|
||
/** Killaura à rotation silencieuse : l'excédent d'angle est 0 ; 3 cibles par seconde : toléré. */
|
||
@Test
|
||
void F11_killaura_rotation_silencieuse_BYPASS() {
|
||
boolean vu = false;
|
||
long now = 0;
|
||
for (int i = 0; i < 100; i++) {
|
||
int cible = 100 + (i % 3); // 3 cibles qui tournent
|
||
vu |= !moteur.attaque(j, now, EtatJoueur.normal(), 0.0, cible, true).isEmpty();
|
||
now += 330; // ~3 coups par seconde
|
||
}
|
||
assertFalse(vu, "regard parfait + 3 cibles/s : jamais vu");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F12
|
||
/** Au-delà de 128 coups/s la fenêtre ne contient plus « la seconde précédente » : cadence muette. */
|
||
@Test
|
||
void F12_cadence_saturation_BYPASS() {
|
||
UUID spam = UUID.randomUUID();
|
||
UUID rapide = UUID.randomUUID();
|
||
boolean vuSpam = false, vuRapide = false;
|
||
for (int tick = 0; tick < 100; tick++) {
|
||
for (int k = 0; k < 10; k++) { // 10 coups par tick = 200/s
|
||
if (contient(moteur.attaque(spam, tick * 50L, EtatJoueur.normal(), 0, 7, true), Controle.CADENCE)) vuSpam = true;
|
||
}
|
||
for (int k = 0; k < 2; k++) { // 2 coups par tick = 40/s
|
||
if (contient(moteur.attaque(rapide, tick * 50L, EtatJoueur.normal(), 0, 7, true), Controle.CADENCE)) vuRapide = true;
|
||
}
|
||
}
|
||
assertTrue(vuRapide, "40 coups/s : vu (témoin)");
|
||
assertFalse(vuSpam, "200 coups/s : jamais vu (fenêtre de 128)");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F13
|
||
/** 5 cibles par seconde passent si 8 coups par tick sur une 6e entité chassent les autres de la fenêtre (32). */
|
||
@Test
|
||
void F13_cibles_multiples_fenetre_saturable_BYPASS() {
|
||
boolean vu = false;
|
||
for (int tick = 0; tick < 200; tick++) {
|
||
long now = tick * 50L;
|
||
for (int k = 0; k < 8; k++) vu |= contient(moteur.attaque(j, now, EtatJoueur.normal(), 0, 1, true), Controle.KILLAURA_CIBLES);
|
||
if (tick % 5 == 0) {
|
||
int autre = 10 + (tick / 5) % 4;
|
||
vu |= contient(moteur.attaque(j, now, EtatJoueur.normal(), 0, autre, true), Controle.KILLAURA_CIBLES);
|
||
}
|
||
}
|
||
assertFalse(vu, "5 entités touchées par seconde : jamais vu (fenêtre de 32 entrées)");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F14
|
||
/** Atterrissage après élytres rapides : aucune grâce, le surplus de vitesse dépasse le tampon. */
|
||
@Test
|
||
void F14_atterrissage_elytres_faux_positif() {
|
||
boolean vu = false;
|
||
long now = 0;
|
||
double v = 1.7; // blocs/tick, plané avec fusée
|
||
for (int tick = 0; tick < 12; tick++) {
|
||
// au sol, friction 0,6 × 0,91 = 0,546 par tick, joueur plus en élytres (isFallFlying=false)
|
||
if (!moteur.mouvement(j, now, EtatJoueur.normal(), mv(v, 0, 1, true, true)).isEmpty()) vu = true;
|
||
v *= 0.546;
|
||
now += 50;
|
||
}
|
||
assertTrue(vu, "un atterrissage à 1,7 bloc/tick lève une infraction vitesse : faux positif");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F15
|
||
/** Le fichier du jour n'est jamais purgé : le plafond de taille ne s'applique pas pendant la journée. */
|
||
@Test
|
||
void F15_traces_plafond_non_applique_dans_la_journee() throws Exception {
|
||
Path dossier = Files.createTempDirectory("garde-traces");
|
||
try (TraceFichier t = new TraceFichier(dossier, 7, 1024)) {
|
||
long epoch = LocalDate.of(2026, 10, 14).atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
|
||
String ligne = "x".repeat(1000);
|
||
for (int i = 0; i < 2000; i++) t.ecrire(epoch + i, ligne);
|
||
t.flush();
|
||
long taille = Files.size(t.fichierDuJour(LocalDate.of(2026, 10, 14)));
|
||
assertTrue(taille > 1_000_000, "plafond de 1 Ko demandé, fichier de " + taille + " octets");
|
||
}
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F16
|
||
/** La décroissance est figée à la création du suivi : /garde reload ne change rien pour les joueurs connectés. */
|
||
@Test
|
||
void F16_decroissance_figee_a_la_creation() {
|
||
Suivi s = moteur.suivi(j);
|
||
cfg.vlDecroissanceParSeconde = 0.0; // l'op « gèle » les VL dans la config
|
||
s.vl.ajouter(Controle.VITESSE, 10, 0);
|
||
assertEquals(5.0, s.vl.valeur(Controle.VITESSE, 10_000), 1e-9, "décroît encore de 0,5/s malgré la config à 0");
|
||
}
|
||
|
||
// ---------------------------------------------------------------- F17
|
||
/** Le tampon 20 ticks est un total : en alternant 19 ticks légaux et 1 tick « téléporté », jamais d'infraction. */
|
||
@Test
|
||
void F17_tampon_vitesse_rafale_isolee_BYPASS() {
|
||
boolean vu = false;
|
||
long now = 0;
|
||
for (int tick = 0; tick < 400; tick++) {
|
||
double d = (tick % 20 == 0) ? 1.7 : 0.28; // un « bond » de 1,7 bloc toutes les secondes
|
||
vu |= !moteur.mouvement(j, now, EtatJoueur.normal(), mv(d, 0, 1, true, true)).isEmpty();
|
||
now += 50;
|
||
}
|
||
assertFalse(vu, "1,4 bloc d'excès par seconde (+25 blocs/min) : sous le tampon de 1,5 bloc");
|
||
}
|
||
}
|