Skip to content

Commit

Permalink
test: unit test autofirma-truststore. Closes #110
Browse files Browse the repository at this point in the history
  • Loading branch information
nilp0inter committed Feb 4, 2025
1 parent d6d17ae commit e0d6bb0
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 13 deletions.
84 changes: 71 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
python-updates.url = "github:NixOS/nixpkgs/python-updates"; # Until #376856 get's into nixos-unstable
home-manager.url = "github:nix-community/home-manager";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nix-unit.url = "github:nix-community/nix-unit";
nix-unit.inputs.nixpkgs.follows = "nixpkgs";
nix-unit.inputs.flake-parts.follows = "flake-parts";
};

# Autofirma sources
Expand Down Expand Up @@ -45,6 +49,7 @@
jmulticard-src,
clienteafirma-external-src,
autofirma-src,
nix-unit
}:
flake-parts.lib.mkFlake {inherit inputs;} {
flake = {
Expand Down Expand Up @@ -81,6 +86,7 @@
dnieremote = pkgs.callPackage ./nix/dnieremote/default.nix {openssl_1_1 = ignoreVulnerable_openssl_1_1;};
configuradorfnmt = pkgs.callPackage ./nix/configuradorfnmt/default.nix {};
};
tests = import ./nix/tests/unit { inherit self; };
checks.x86_64-linux = let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
Expand Down Expand Up @@ -117,6 +123,7 @@
];
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.nix-unit.modules.flake.default
];
perSystem = {
config,
Expand Down Expand Up @@ -163,6 +170,7 @@
update-fixed-output-derivations
download-autofirma-trusted-providers
download-url-linked-CAs
nix-unit.packages.${system}.default
];
};
packages = let
Expand Down
29 changes: 29 additions & 0 deletions nix/tests/unit/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{ self }:
with builtins;
let
ascendingOrder = sort lessThan;
truststorePath = "${self}/nix/autofirma/truststore";
providers = fromJSON (readFile "${truststorePath}/prestadores/providers.json");
allCAFiles = attrNames (readDir "${truststorePath}/prestadores/CAs-by-provider");
CAFetchLinks = fromJSON (readFile "${truststorePath}/prestadores/CAs_fetch_links.json");
in
{
testProviderListIsNotEmpty = {
expr = length providers > 0;
expected = true;
};
testCAFilesAndTrustedProvidersMatch = let
trimJsonExt = s: substring 0 ((stringLength s) - (stringLength ".json")) s;
in {
expr = ascendingOrder (map trimJsonExt allCAFiles);
expected = ascendingOrder (map (p: p.cif) providers);
};
testAllCAFilesHaveFetchLinkEntry = {
expr = ascendingOrder (map (p: p.cif) CAFetchLinks);
expected = ascendingOrder (map (p: p.cif) providers);
};
testAllFetchLinksHaveURLField = {
expr = all (link: hasAttr "url" link) CAFetchLinks;
expected = true;
};
}

0 comments on commit e0d6bb0

Please sign in to comment.