Skip to content

Commit

Permalink
Merge pull request #27683 (add test for ACME)
Browse files Browse the repository at this point in the history
This is a rebased version of the pull request with small fixes due to
changes in recent master.

Original description from the pull request:

  Currently this is only a very basic test which gets certificates via
  the enableACME option of the nginx module.

  However the main reason why I'm not directly merging and putting this
  up for review is that the complexity here lies in the support-modules
  needed for the test. The support modules are for running a Boulder
  instance along with a DNS resolver (as a separate module).

  For details about the implementation, see the commit messages and the
  comments at the start of the respective support modules.

I'm merging this first of all because other than @abbradar, none of the
other requested reviewers did comment on the changes and second because
the change here is adding a test, so even if the implementation would be
so disgusting and crappy it's better than having no test at all.

The comment of @abbradar was:

  Can't we factor Boulder into a proper package and a NixOS service?
  Maybe not very general purpose for now but still -- putting everything
  into one test seems painful to me.

My objection to this is that the components are heavily patched and some
of them don't even have a release, so I'm not sure whether infesting
pkgs/ with them is really a good idea.

Nevertheless, we can still do that later.

Cc: @fpletz, @domenkozar, @bjornfor
  • Loading branch information
aszlig committed Sep 13, 2017
2 parents 50cf2a7 + 01fffd9 commit 62711f4
Show file tree
Hide file tree
Showing 4 changed files with 650 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ in rec {
# Run the tests for each platform. You can run a test by doing
# e.g. ‘nix-build -A tests.login.x86_64-linux’, or equivalently,
# ‘nix-build tests/login.nix -A result’.
tests.acme = callTest tests/acme.nix {};
tests.avahi = callTest tests/avahi.nix {};
tests.bittorrent = callTest tests/bittorrent.nix {};
tests.blivet = callTest tests/blivet.nix {};
Expand Down
62 changes: 62 additions & 0 deletions nixos/tests/acme.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
let
commonConfig = { config, lib, pkgs, nodes, ... }: {
networking.nameservers = [
nodes.letsencrypt.config.networking.primaryIPAddress
];

nixpkgs.overlays = lib.singleton (self: super: {
cacert = super.cacert.overrideDerivation (drv: {
installPhase = (drv.installPhase or "") + ''
cat "${nodes.letsencrypt.config.test-support.letsencrypt.caCert}" \
>> "$out/etc/ssl/certs/ca-bundle.crt"
'';
});

pythonPackages = (super.python.override {
packageOverrides = lib.const (pysuper: {
certifi = pysuper.certifi.overrideDerivation (drv: {
postPatch = (drv.postPatch or "") + ''
cat "${self.cacert}/etc/ssl/certs/ca-bundle.crt" \
> certifi/cacert.pem
'';
});
});
}).pkgs;
});
};

in import ./make-test.nix {
name = "acme";

nodes = {
letsencrypt = ./common/letsencrypt.nix;

webserver = { config, pkgs, ... }: {
imports = [ commonConfig ];
networking.firewall.allowedTCPPorts = [ 80 443 ];

networking.extraHosts = ''
${config.networking.primaryIPAddress} example.com
'';

services.nginx.enable = true;
services.nginx.virtualHosts."example.com" = {
enableACME = true;
forceSSL = true;
locations."/".root = pkgs.runCommand "docroot" {} ''
mkdir -p "$out"
echo hello world > "$out/index.html"
'';
};
};

client = commonConfig;
};

testScript = ''
$letsencrypt->waitForUnit("boulder.service");
startAll;
$webserver->waitForUnit("acme-certificates.target");
$client->succeed('curl https://example.com/ | grep -qF "hello world"');
'';
}

0 comments on commit 62711f4

Please sign in to comment.