Public Access
test: generate the JWT test keys, drop application-dev.yml
The dev config held real keys. Local dev config now lives outside the repo; integration tests create a fresh Ed25519 keypair per run.
This commit is contained in:
1 parent
9df7389fab
commit
c63b7e6aaa
2 files changed
+29
No files matched your search
@@ -35,3 +35,7 @@ build/
|
|||||||
### Local secrets and generated files ###
|
### Local secrets and generated files ###
|
||||||
.env
|
.env
|
||||||
effective-pom
|
effective-pom
|
||||||
|
|
||||||
|
### Local dev config, never committed ###
|
||||||
|
application-dev.yml
|
||||||
|
application-dev.yaml
|
||||||
@@ -4,8 +4,15 @@ import org.junit.jupiter.api.Tag;
|
|||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||||
|
import org.springframework.test.context.DynamicPropertyRegistry;
|
||||||
|
import org.springframework.test.context.DynamicPropertySource;
|
||||||
import org.testcontainers.containers.PostgreSQLContainer;
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
|
|
||||||
|
import java.security.KeyPair;
|
||||||
|
import java.security.KeyPairGenerator;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for integration tests.
|
* Base class for integration tests.
|
||||||
* Full Spring context with Testcontainers.
|
* Full Spring context with Testcontainers.
|
||||||
@@ -23,5 +30,23 @@ public abstract class AbstractIntegrationTest {
|
|||||||
static {
|
static {
|
||||||
postgres.start();
|
postgres.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No key is committed: a fresh one per JVM.
|
||||||
|
private static final KeyPair KEYS = generateKeys();
|
||||||
|
|
||||||
|
@DynamicPropertySource
|
||||||
|
static void secrets(DynamicPropertyRegistry registry) {
|
||||||
|
registry.add("security.jwt.private-key", () -> Base64.getEncoder().encodeToString(KEYS.getPrivate().getEncoded()));
|
||||||
|
registry.add("security.jwt.public-key", () -> Base64.getEncoder().encodeToString(KEYS.getPublic().getEncoded()));
|
||||||
|
registry.add("auth.registration.invitation-code", () -> "test-invite-code");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static KeyPair generateKeys() {
|
||||||
|
try {
|
||||||
|
return KeyPairGenerator.getInstance("Ed25519").generateKeyPair();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user