KEYCLOAK-12616 Vault unit test always failes on Windows

This commit is contained in:
Manfred Duchrow 2020-01-06 16:01:41 +01:00 committed by Hynek Mlnařík
parent 8e0e972957
commit f926529767

View file

@ -5,12 +5,9 @@ import org.jboss.logging.Logger;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.nio.MappedByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -58,9 +55,9 @@ public class FilesPlainTextVaultProvider extends AbstractVaultProvider {
return DefaultVaultRawSecret.forBuffer(Optional.empty()); return DefaultVaultRawSecret.forBuffer(Optional.empty());
} }
try (FileChannel fileChannel = (FileChannel) Files.newByteChannel(secretPath, EnumSet.of(StandardOpenOption.READ))) { try {
MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size()); byte[] bytes = Files.readAllBytes(secretPath);
return DefaultVaultRawSecret.forBuffer(Optional.of(mappedByteBuffer)); return DefaultVaultRawSecret.forBuffer(Optional.of(ByteBuffer.wrap(bytes)));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }