mirror of
https://github.com/akuker/RASCSI.git
synced 2026-10-25 12:02:59 +00:00
Introduce a server-rendered Go control panel for managing PiSCSI devices, disk images, saved configurations, archives, uploads, system settings, embedded themes and translations, PWA assets, a mock daemon, installation and systemd support, generated protobuf bindings, tests, and CI builds for supported Raspberry Pi targets. This is built for feature parity with the Python Web UI, with a few notable differences: piscsi-web runs as a non-privileged user, there is no user authentication, the upload form uses a plain stream with no Javascript, the ability to set 'pretty hostname' is removed, and reserved ID memos are removed too. Update piscsi core to use /var/lib/piscsi/images as its default and resolve relative image folders from the server working directory. Allow valid folders outside the user's home directory, and align the tests, protocol comments, service example, and man pages with the new behavior. Ship a script and makefile target for migrating user data from old to new file system locations.
165 lines
4.8 KiB
C++
165 lines
4.8 KiB
C++
//---------------------------------------------------------------------------
|
|
//
|
|
// SCSI Target Emulator PiSCSI
|
|
// for Raspberry Pi
|
|
//
|
|
// Copyright (C) 2022-2023 Uwe Seimet
|
|
//
|
|
//---------------------------------------------------------------------------
|
|
|
|
#include "mocks.h"
|
|
#include "shared/protobuf_util.h"
|
|
#include "generated/piscsi_interface.pb.h"
|
|
#include "piscsi/piscsi_image.h"
|
|
|
|
using namespace piscsi_interface;
|
|
using namespace protobuf_util;
|
|
|
|
TEST(PiscsiImageTest, SetGetDepth)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
image.SetDepth(1);
|
|
EXPECT_EQ(1, image.GetDepth());
|
|
}
|
|
|
|
TEST(PiscsiImageTest, SetGetDefaultFolder)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
EXPECT_EQ(PiscsiImage::DEFAULT_IMAGE_FOLDER, image.GetDefaultFolder());
|
|
|
|
EXPECT_TRUE(!image.SetDefaultFolder("").empty());
|
|
EXPECT_TRUE(image.SetDefaultFolder(temp_directory_path().string()).empty());
|
|
EXPECT_EQ(temp_directory_path(), path(image.GetDefaultFolder()));
|
|
}
|
|
|
|
TEST(PiscsiImageTest, CreateImage)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
PbCommand command1;
|
|
CommandContext context1(command1, "", "");
|
|
EXPECT_FALSE(image.CreateImage(context1)) << "Filename must be reported as missing";
|
|
|
|
PbCommand command2;
|
|
SetParam(command2, "file", "/a/b/c/filename");
|
|
CommandContext context2(command2, "", "");
|
|
EXPECT_FALSE(image.CreateImage(context2)) << "Depth must be reported as invalid";
|
|
|
|
PbCommand command3;
|
|
SetParam(command3, "file", "filename");
|
|
SetParam(command3, "size", "-1");
|
|
CommandContext context3(command3, "", "");
|
|
EXPECT_FALSE(image.CreateImage(context3)) << "Size must be reported as invalid";
|
|
|
|
PbCommand command4;
|
|
SetParam(command4, "size", "1");
|
|
CommandContext context4(command4, "", "");
|
|
EXPECT_FALSE(image.CreateImage(context4)) << "Size must be reported as invalid";
|
|
|
|
PbCommand command5;
|
|
SetParam(command5, "size", "513");
|
|
CommandContext context5(command5, "", "");
|
|
EXPECT_FALSE(image.CreateImage(context4)) << "Size must be reported as not a multiple of 512";
|
|
|
|
// Further tests would modify the filesystem
|
|
}
|
|
|
|
TEST(PiscsiImageTest, DeleteImage)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
PbCommand command1;
|
|
CommandContext context1(command1, "", "");
|
|
EXPECT_FALSE(image.DeleteImage(context1)) << "Filename must be reported as missing";
|
|
|
|
PbCommand command2;
|
|
SetParam(command2, "file", "/a/b/c/filename");
|
|
CommandContext context2(command2, "", "");
|
|
EXPECT_FALSE(image.DeleteImage(context2)) << "Depth must be reported as invalid";
|
|
|
|
MockStorageDevice device;
|
|
device.SetFilename("filename");
|
|
device.ReserveFile();
|
|
PbCommand command3;
|
|
SetParam(command3, "file", "filename");
|
|
CommandContext context3(command3, "", "");
|
|
EXPECT_FALSE(image.DeleteImage(context3)) << "File must be reported as in use";
|
|
|
|
// Further testing would modify the filesystem
|
|
}
|
|
|
|
TEST(PiscsiImageTest, RenameImage)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
PbCommand command1;
|
|
CommandContext context1(command1, "", "");
|
|
EXPECT_FALSE(image.RenameImage(context1)) << "Source filename must be reported as missing";
|
|
|
|
PbCommand command2;
|
|
SetParam(command2, "from", "/a/b/c/filename_from");
|
|
CommandContext context2(command2, "", "");
|
|
EXPECT_FALSE(image.RenameImage(context2)) << "Depth must be reported as invalid";
|
|
|
|
PbCommand command3;
|
|
SetParam(command3, "from", "filename_from");
|
|
CommandContext context3(command3, "", "");
|
|
EXPECT_FALSE(image.RenameImage(context3)) << "Source file must be reported as missing";
|
|
|
|
// Further testing would modify the filesystem
|
|
}
|
|
|
|
TEST(PiscsiImageTest, CopyImage)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
PbCommand command1;
|
|
CommandContext context1(command1, "", "");
|
|
EXPECT_FALSE(image.CopyImage(context1)) << "Source filename must be reported as missing";
|
|
|
|
PbCommand command2;
|
|
SetParam(command2, "from", "/a/b/c/filename_from");
|
|
CommandContext context2(command2, "", "");
|
|
EXPECT_FALSE(image.CopyImage(context2)) << "Depth must be reported as invalid";
|
|
|
|
PbCommand command3;
|
|
SetParam(command3, "from", "filename_from");
|
|
CommandContext context3(command3, "", "");
|
|
EXPECT_FALSE(image.CopyImage(context3)) << "Source file must be reported as missing";
|
|
|
|
// Further testing would modify the filesystem
|
|
}
|
|
|
|
TEST(PiscsiImageTest, SetImagePermissions)
|
|
{
|
|
PiscsiImage image;
|
|
|
|
StorageDevice::UnreserveAll();
|
|
|
|
PbCommand command1;
|
|
CommandContext context1(command1, "", "");
|
|
EXPECT_FALSE(image.SetImagePermissions(context1)) << "Filename must be reported as missing";
|
|
|
|
PbCommand command2;
|
|
SetParam(command2, "file", "/a/b/c/filename");
|
|
CommandContext context2(command2, "", "");
|
|
EXPECT_FALSE(image.SetImagePermissions(context2)) << "Depth must be reported as invalid";
|
|
|
|
PbCommand command3;
|
|
SetParam(command3, "file", "filename");
|
|
CommandContext context3(command3, "", "");
|
|
EXPECT_FALSE(image.CopyImage(context3)) << "Source file must be reported as missing";
|
|
|
|
// Further testing would modify the filesystem
|
|
}
|