Skip to content

Fix test helper validation to match VoteReceiver implementation#144

Merged
BenCodez merged 6 commits intomasterfrom
copilot/improve-invalid-vote-error-handling
Feb 1, 2026
Merged

Fix test helper validation to match VoteReceiver implementation#144
BenCodez merged 6 commits intomasterfrom
copilot/improve-invalid-vote-error-handling

Conversation

Copy link
Contributor

Copilot AI commented Feb 1, 2026

Two test failures in VoteReceiverTest were caused by the test helper method processV2Vote() not implementing the same validation logic as the production VoteReceiver class.

Changes

Added missing validation steps:

  • Validate outer JSON fields (payload, signature) before parsing inner payload
  • Decode Base64 signature to catch malformed signatures early

Before:

public Vote processV2Vote(String jsonPayload) throws Exception {
    JsonObject outer = gson.fromJson(jsonPayload, JsonObject.class);
    String payload = outer.get("payload").getAsString();  // No validation
    JsonObject inner = gson.fromJson(payload, JsonObject.class);
    if (!inner.has("challenge")) {  // Checks inner field first
        throw new Exception("Vote payload missing challenge field.");
    }
    // ...
}

After:

public Vote processV2Vote(String jsonPayload) throws Exception {
    JsonObject outer = gson.fromJson(jsonPayload, JsonObject.class);
    
    if (!outer.has("payload")) {
        throw new Exception("Invalid vote format: Missing required 'payload' field...");
    }
    if (!outer.has("signature")) {
        throw new Exception("Invalid vote format: Missing required 'signature' field...");
    }
    
    String sigHash = outer.get("signature").getAsString();
    try {
        Base64.getDecoder().decode(sigHash);
    } catch (IllegalArgumentException e) {
        throw new Exception("Invalid vote format: Signature is not valid Base64...");
    }
    
    JsonObject inner = gson.fromJson(payload, JsonObject.class);
    // ... validate inner fields
}

This ensures test validation logic matches production behavior and error messages match test assertions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • hub.spigotmc.org
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/VotifierPlus/VotifierPlus/VotifierPlus org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=VoteReceiverTest#testV2VoteInvalidBase64Signature -B (dns block)
  • libraries.minecraft.net
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/VotifierPlus/VotifierPlus/VotifierPlus org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=VoteReceiverTest#testV2VoteInvalidBase64Signature -B (dns block)
  • nexus.bencodez.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/VotifierPlus/VotifierPlus/VotifierPlus org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=VoteReceiverTest#testV2VoteInvalidBase64Signature -B (dns block)
  • nexus.velocitypowered.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/VotifierPlus/VotifierPlus/VotifierPlus org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=VoteReceiverTest#testV2VoteInvalidBase64Signature -B (dns block)
  • repo.papermc.io
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --enable-native-access=ALL-UNNAMED -classpath /usr/share/apache-maven-3.9.12/boot/plexus-classworlds-2.9.0.jar -Dclassworlds.conf=/usr/share/apache-maven-3.9.12/bin/m2.conf -Dmaven.home=/usr/share/apache-maven-3.9.12 -Dlibrary.jansi.path=/usr/share/apache-maven-3.9.12/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/home/REDACTED/work/VotifierPlus/VotifierPlus/VotifierPlus org.codehaus.plexus.classworlds.launcher.Launcher test -Dtest=VoteReceiverTest#testV2VoteInvalidBase64Signature -B (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 1, 2026 19:53
Co-authored-by: BenCodez <17074231+BenCodez@users.noreply.github.com>
Co-authored-by: BenCodez <17074231+BenCodez@users.noreply.github.com>
Co-authored-by: BenCodez <17074231+BenCodez@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve invalid vote error handling in vote receiver Improve vote receiver error handling with field validation and categorized messages Feb 1, 2026
Copilot AI requested a review from BenCodez February 1, 2026 19:58
Co-authored-by: BenCodez <17074231+BenCodez@users.noreply.github.com>
Copilot AI changed the title Improve vote receiver error handling with field validation and categorized messages Fix test helper validation order in VoteReceiverTest Feb 1, 2026
Co-authored-by: BenCodez <17074231+BenCodez@users.noreply.github.com>
Copilot AI changed the title Fix test helper validation order in VoteReceiverTest Fix test helper validation to match VoteReceiver implementation Feb 1, 2026
@BenCodez BenCodez marked this pull request as ready for review February 1, 2026 21:32
@BenCodez BenCodez merged commit 532ecc0 into master Feb 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants