Add Current-Version Deserialization Test

We should test that serialized files from the current minor version
can be deserialized. This ensures that serializations remain
deserializable in patch releases.

Issue gh-3737
This commit is contained in:
Josh Cummings 2025-05-05 11:19:30 -06:00
parent b5e1c3770b
commit 34afa64c0c
No known key found for this signature in database
GPG Key ID: 869B37A20E876129

View File

@ -690,7 +690,34 @@ class SpringSecurityCoreVersionSerializableTests {
}
@ParameterizedTest
@MethodSource("getFilesToDeserialize")
@MethodSource("getCurrentSerializedFiles")
void shouldBeAbleToDeserializeClassFromCurrentVersion(Path filePath) {
try (FileInputStream fileInputStream = new FileInputStream(filePath.toFile());
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
Object obj = objectInputStream.readObject();
Class<?> clazz = Class.forName(filePath.getFileName().toString().replace(".serialized", ""));
assertThat(obj).isInstanceOf(clazz);
}
catch (IOException | ClassNotFoundException ex) {
fail("Could not deserialize " + filePath, ex);
}
}
static Stream<Path> getCurrentSerializedFiles() throws IOException {
assertThat(currentVersionFolder.toFile().exists())
.as("Make sure that the " + currentVersionFolder + " exists and is not empty")
.isTrue();
try (Stream<Path> files = Files.list(currentVersionFolder)) {
if (files.findFirst().isEmpty()) {
fail("Please make sure to run SpringSecurityCoreVersionSerializableTests#serializeCurrentVersionClasses for the "
+ getPreviousVersion() + " version");
}
}
return Files.list(currentVersionFolder);
}
@ParameterizedTest
@MethodSource("getPreviousSerializedFiles")
void shouldBeAbleToDeserializeClassFromPreviousVersion(Path filePath) {
try (FileInputStream fileInputStream = new FileInputStream(filePath.toFile());
ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
@ -703,7 +730,7 @@ class SpringSecurityCoreVersionSerializableTests {
}
}
static Stream<Path> getFilesToDeserialize() throws IOException {
static Stream<Path> getPreviousSerializedFiles() throws IOException {
assertThat(previousVersionFolder.toFile().exists())
.as("Make sure that the " + previousVersionFolder + " exists and is not empty")
.isTrue();