fix(ci): authenticate releases through scoped credential helper
Release / release (push) Successful in 2m9s
CI / build (push) Successful in 51s

This commit is contained in:
dmg committed 2026-09-10 20:45:37 -04:00
1 parent 7a481f366c
commit 9d3791a9c3
4 files changed
+75 -14

No files matched your search

@@ -0,0 +1,49 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
class ReleaseCredentialTest {
@Test
void credentialHelperRefusesOtherHostsProtocolsRepositoriesAndOperations() throws Exception {
Path helper = Path.of(".gitea/scripts/git-credential-ignis.sh").toAbsolutePath();
for (String request : java.util.List.of(
"protocol=https\nhost=evil.example\npath=dmg/spigot-ignis.git\n\n",
"protocol=http\nhost=git.garvis.dev\npath=dmg/spigot-ignis.git\n\n",
"protocol=https\nhost=git.garvis.dev\npath=dmg/other.git\n\n")) {
var builder = new ProcessBuilder("sh", helper.toString(), "get");
builder.environment().put("IGNIS_RELEASE_TOKEN", "synthetic-test-token");
var process = builder.start();
try (var input = process.getOutputStream()) { input.write(request.getBytes(StandardCharsets.UTF_8)); }
assertTrue(process.waitFor(3, TimeUnit.SECONDS));
assertEquals("", new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
}
var store = new ProcessBuilder("sh", helper.toString(), "store").start();
store.getOutputStream().close();
assertTrue(store.waitFor(3, TimeUnit.SECONDS));
assertEquals("", new String(store.getInputStream().readAllBytes(), StandardCharsets.UTF_8));
}
@Test
void scopedHelperWorksEvenWhenSemanticReleaseOverridesAskpass() throws Exception {
Path helper = Path.of(".gitea/scripts/git-credential-ignis.sh").toAbsolutePath();
assertTrue(java.nio.file.Files.exists(helper), "A credential helper must survive semantic-release's askpass override");
var builder = new ProcessBuilder("git", "-c", "credential.helper=", "-c", "credential.helper=" + helper,
"-c", "credential.useHttpPath=true", "credential", "fill");
builder.environment().put("IGNIS_RELEASE_TOKEN", "synthetic-test-token");
builder.environment().put("GIT_ASKPASS", "echo");
builder.environment().put("GIT_TERMINAL_PROMPT", "0");
Process process = builder.start();
try (var input = process.getOutputStream()) {
input.write("protocol=https\nhost=git.garvis.dev\npath=dmg/spigot-ignis.git\n\n".getBytes(StandardCharsets.UTF_8));
}
assertTrue(process.waitFor(3, TimeUnit.SECONDS));
assertEquals(0, process.exitValue());
String result = new String(process.getInputStream().readAllBytes(), StandardCharsets.UTF_8);
assertTrue(result.contains("username=dmg"));
assertTrue(result.contains("password=synthetic-test-token"));
}
}
@@ -14,7 +14,8 @@ class ReleaseWorkflowTest {
String workflow = Files.readString(path);
assertTrue(workflow.contains("spigot-ignis-${VERSION}.jar"));
assertTrue(workflow.contains("--header @-"));
assertTrue(workflow.contains("GIT_ASKPASS"));
assertTrue(workflow.contains("git-credential-ignis.sh"));
assertTrue(workflow.contains("credential.useHttpPath true"));
assertTrue(workflow.contains("persist-credentials: false"));
assertFalse(workflow.contains("-H \"Authorization:"));
assertFalse(workflow.contains("GITHUB_TOKEN:"), "Do not pass a token for semantic-release to embed into git URLs");