tests dont work. need to debug kernel panic
Some checks failed
Run tests / run_tests (push) Failing after 1h1m10s
Some checks failed
Run tests / run_tests (push) Failing after 1h1m10s
This commit is contained in:
parent
ed13c22b64
commit
0241d4d590
|
@ -84,6 +84,69 @@ in {
|
||||||
${commands}
|
${commands}
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
|
||||||
|
create-db = lib.stringAfter ["var"] (
|
||||||
|
let
|
||||||
|
dbname = "jellyfin.db";
|
||||||
|
defaultDB = ./default.db;
|
||||||
|
sq = "${pkgs.sqlite}/bin/sqlite3 \"${path}/${dbname}\" --";
|
||||||
|
path = "/var/lib/jellyfin/data";
|
||||||
|
|
||||||
|
# ${sq} "INSERT INTO Users (Id, AudioLanguagePreference, AuthenticationProviderId, DisplayCollectionsView, DisplayMissingEpisodes, EnableAutoLogin, EnableLocalPassword, EnableNextEpisodeAutoPlay, EnableUserPreferenceAccess, HidePlayedInLatest, InternalId, LoginAttemptsBeforeLockout, MaxActiveSessions, MaxParentalAgeRating, Password, HashedPasswordFile, PasswordResetProviderId, PlayDefaultAudioTrack, RememberAudioSelections, RememberSubtitleSelections, RemoteClientBitrateLimit, SubtitleLanguagePreference, SubtitleMode, SyncPlayAccess, Username, CastReceiverId) \
|
||||||
|
# VALUES(${user.})"
|
||||||
|
genUser = index: user: let
|
||||||
|
values =
|
||||||
|
builtins.mapAttrs (name: value:
|
||||||
|
if (isBool value)
|
||||||
|
then
|
||||||
|
if value
|
||||||
|
then "1"
|
||||||
|
else "0"
|
||||||
|
else value)
|
||||||
|
(cfg.Users
|
||||||
|
// {
|
||||||
|
Id =
|
||||||
|
if (builtins.hasAttr "Id" cfg.Users)
|
||||||
|
then cfg.Users.Id
|
||||||
|
else "$(${pkgs.libuuid}/bin/uuidgen | ${pkgs.coreutils}/bin/tr '[:lower:]' '[:upper:]')";
|
||||||
|
InternalId =
|
||||||
|
if (builtins.hasAttr "InternalId" cfg.Users)
|
||||||
|
then cfg.Users.InternalId
|
||||||
|
else "$(($maxIndex+${index + 1}))";
|
||||||
|
Password =
|
||||||
|
if (hasAttr "HashedPasswordFile" cfg.Users)
|
||||||
|
then "$(${pkgs.coreutils}/bin/cat \"${cfg.Users.HashedPasswordFile}\")"
|
||||||
|
else "$(${self.packages.${pkgs.system}.genhash}/bin/genhash -k \"${cfg.Users.Password}\" -i 210000 -l 128 -u)";
|
||||||
|
});
|
||||||
|
in
|
||||||
|
/*
|
||||||
|
bash
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
if [ -n $(${sq} "SELECT 1 FROM Users WHERE Username = '${user.Username}'") ]; then
|
||||||
|
# Create user
|
||||||
|
${sq} "INSERT INTO Users (${concatStringsSep ","
|
||||||
|
(builtins.filter (x: x != "HashedPasswordFile")
|
||||||
|
(lib.attrsets.mapAttrsToList (name: value: "${name}")
|
||||||
|
options.services.declarative-jellyfin.Users.options))}) \\
|
||||||
|
VALUES(${builtins.attrValues values})"
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
/*
|
||||||
|
bash
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
mkdir -p ${path}
|
||||||
|
# Make sure there is a database
|
||||||
|
if [ -z "${path}/${dbname}" ] && cp ${defaultDB} "${path}/${dbname}"
|
||||||
|
|
||||||
|
maxIndex=$(${sq} 'SELECT InternalId FROM Users ORDER BY InternalId DESC LIMIT 1')
|
||||||
|
if [ -n "$maxIndex" ] && maxIndex="1"
|
||||||
|
|
||||||
|
|
||||||
|
''
|
||||||
|
);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
BIN
modules/default.db
Executable file
BIN
modules/default.db
Executable file
Binary file not shown.
|
@ -5,6 +5,7 @@ with lib; {
|
||||||
./encoding.nix
|
./encoding.nix
|
||||||
./network.nix
|
./network.nix
|
||||||
./branding.nix
|
./branding.nix
|
||||||
|
./users.nix
|
||||||
];
|
];
|
||||||
options.services.declarative-jellyfin = {
|
options.services.declarative-jellyfin = {
|
||||||
enable = mkEnableOption "Jellyfin Service";
|
enable = mkEnableOption "Jellyfin Service";
|
||||||
|
|
|
@ -9,7 +9,6 @@ with lib; {
|
||||||
Id = mkOption {
|
Id = mkOption {
|
||||||
type = types.str; # TODO: Limit the id to the pattern: "18B51E25-33FD-46B6-BBF8-DB4DD77D0679"
|
type = types.str; # TODO: Limit the id to the pattern: "18B51E25-33FD-46B6-BBF8-DB4DD77D0679"
|
||||||
description = "The ID of the user";
|
description = "The ID of the user";
|
||||||
default = "autogenerate";
|
|
||||||
example = "18B51E25-33FD-46B6-BBF8-DB4DD77D0679";
|
example = "18B51E25-33FD-46B6-BBF8-DB4DD77D0679";
|
||||||
};
|
};
|
||||||
AudioLanguagePreference = mkOption {
|
AudioLanguagePreference = mkOption {
|
||||||
|
@ -64,10 +63,9 @@ with lib; {
|
||||||
example = false;
|
example = false;
|
||||||
};
|
};
|
||||||
InternalId = mkOption {
|
InternalId = mkOption {
|
||||||
type = with types; either int str; # TODO: Limit string to "autogenerate"
|
type = types.int;
|
||||||
# NOTE: index is 1-indexed! NOT 0-indexed.
|
# NOTE: index is 1-indexed! NOT 0-indexed.
|
||||||
description = "The index of the user in the database. Be careful setting this option. 1 indexed.";
|
description = "The index of the user in the database. Be careful setting this option. 1 indexed.";
|
||||||
default = "autogenerate";
|
|
||||||
example = 69;
|
example = 69;
|
||||||
};
|
};
|
||||||
LoginAttemptsBeforeLockout = mkOption {
|
LoginAttemptsBeforeLockout = mkOption {
|
||||||
|
|
49
tests/create_users.nix
Normal file
49
tests/create_users.nix
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
{pkgs ? import <nixpkgs> {}, ...}: let
|
||||||
|
name = "minimal";
|
||||||
|
in {
|
||||||
|
inherit name;
|
||||||
|
test = pkgs.nixosTest {
|
||||||
|
inherit name;
|
||||||
|
nodes = {
|
||||||
|
machine = {
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
imports = [
|
||||||
|
../modules/default.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
virtualisation.memorySize = 1024;
|
||||||
|
|
||||||
|
environment.systemPackages = [
|
||||||
|
pkgs.sqlite
|
||||||
|
];
|
||||||
|
|
||||||
|
services.declarative-jellyfin = {
|
||||||
|
enable = true;
|
||||||
|
Users = [
|
||||||
|
{
|
||||||
|
Username = "admin";
|
||||||
|
Password = "123";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript =
|
||||||
|
/*
|
||||||
|
py
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
machine.start()
|
||||||
|
machine.wait_for_unit("multi-user.target");
|
||||||
|
machine.succeed("file /var/lib/jellyfin/data/jellyfin.db")
|
||||||
|
users = machine.succeed("sqlite3 /var/lib/jellyfin/data/jellyfin.db -- \"SELECT * FROM Users WHERE Username = 'admin'\"")
|
||||||
|
print(users)
|
||||||
|
if users == "":
|
||||||
|
assert False, "User not in db"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
39
tests/defaultdb.nix
Normal file
39
tests/defaultdb.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{pkgs ? import <nixpkgs> {}, ...}: let
|
||||||
|
name = "minimal";
|
||||||
|
in {
|
||||||
|
inherit name;
|
||||||
|
test = pkgs.nixosTest {
|
||||||
|
inherit name;
|
||||||
|
nodes = {
|
||||||
|
machine = {
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
imports = [
|
||||||
|
../modules/default.nix
|
||||||
|
];
|
||||||
|
|
||||||
|
services.jellyfin.enable = true;
|
||||||
|
|
||||||
|
virtualisation.memorySize = 1024;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
testScript =
|
||||||
|
/*
|
||||||
|
py
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
machine.start()
|
||||||
|
machine.wait_for_unit("multi-user.target");
|
||||||
|
machine.wait_for_unit("jellyfin.service");
|
||||||
|
machine.wait_for_file("/var/lib/jellyfin/data/jellyfin.db", 60)
|
||||||
|
machine.succeed("sleep 10")
|
||||||
|
machine.systemctl("stop jellyfin.service")
|
||||||
|
machine.wait_until_fails("pgrep jellyfin")
|
||||||
|
machine.copy_from_vm("/var/lib/jellyfin/data/jellyfin.db", "jellyfin.db")
|
||||||
|
assert False
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
|
@ -154,47 +154,51 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = ''
|
testScript =
|
||||||
import xml.etree.ElementTree as ET
|
/*
|
||||||
|
py
|
||||||
|
*/
|
||||||
|
''
|
||||||
|
import xml.etree.ElementTree as ET
|
||||||
|
|
||||||
machine.wait_for_unit("multi-user.target");
|
machine.wait_for_unit("multi-user.target");
|
||||||
|
|
||||||
with subtest("network.xml"):
|
with subtest("network.xml"):
|
||||||
# stupid fucking hack because you cant open files in python for some reason
|
# stupid fucking hack because you cant open files in python for some reason
|
||||||
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
xml = machine.succeed("cat /var/lib/jellyfin/config/network.xml")
|
||||||
tree = ET.ElementTree(ET.fromstring(xml))
|
tree = ET.ElementTree(ET.fromstring(xml))
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
|
||||||
with subtest("PublishedServerUriBySubnet"):
|
with subtest("PublishedServerUriBySubnet"):
|
||||||
for child in root:
|
for child in root:
|
||||||
if child.tag == "PublishedServerUriBySubnet":
|
if child.tag == "PublishedServerUriBySubnet":
|
||||||
try:
|
try:
|
||||||
if child[0].text == "all=https://test.test.test":
|
if child[0].text == "all=https://test.test.test":
|
||||||
|
break
|
||||||
|
except:
|
||||||
|
print("An error occured when trying to parse xml")
|
||||||
|
print(xml)
|
||||||
|
assert False, "Exception occured, check output above"
|
||||||
|
else:
|
||||||
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
|
|
||||||
|
with subtest("EnableHttps"):
|
||||||
|
for child in root:
|
||||||
|
if child.tag == "EnableHttps":
|
||||||
|
if child.text == "true":
|
||||||
break
|
break
|
||||||
except:
|
else:
|
||||||
print("An error occured when trying to parse xml")
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
print(xml)
|
|
||||||
assert False, "Exception occured, check output above"
|
|
||||||
else:
|
|
||||||
assert False, "The shit was not found. Full XML: " + xml
|
|
||||||
|
|
||||||
with subtest("EnableHttps"):
|
with subtest("RequireHttps"):
|
||||||
for child in root:
|
for child in root:
|
||||||
if child.tag == "EnableHttps":
|
if child.tag == "RequireHttps":
|
||||||
if child.text == "true":
|
if child.text == "true":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
assert False, "The shit was not found. Full XML: " + xml
|
assert False, "The shit was not found. Full XML: " + xml
|
||||||
|
|
||||||
with subtest("RequireHttps"):
|
machine.shutdown()
|
||||||
for child in root:
|
'';
|
||||||
if child.tag == "RequireHttps":
|
|
||||||
if child.text == "true":
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
assert False, "The shit was not found. Full XML: " + xml
|
|
||||||
|
|
||||||
machine.shutdown()
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue