1import ./make-test-python.nix (
2 { pkgs, ... }:
3 rec {
4 name = "tracee-integration";
5 meta.maintainers = pkgs.tracee.meta.maintainers;
6
7 passthru.hello-world-builder =
8 pkgs:
9 pkgs.dockerTools.buildImage {
10 name = "hello-world";
11 tag = "latest";
12 config.Cmd = [ "${pkgs.hello}/bin/hello" ];
13 };
14
15 nodes = {
16 machine =
17 { config, pkgs, ... }:
18 {
19 # EventFilters/trace_only_events_from_new_containers and
20 # Test_EventFilters/trace_only_events_from_"dockerd"_binary_and_contain_it's_pid
21 # require docker/dockerd
22 virtualisation.docker.enable = true;
23
24 environment.systemPackages = with pkgs; [
25 # required by Test_EventFilters/trace_events_from_ls_and_which_binary_in_separate_scopes
26 which
27 # the go integration tests as a binary
28 tracee.passthru.tests.integration-test-cli
29 ];
30 };
31 };
32
33 testScript =
34 let
35 skippedTests = [
36 # these comm tests for some reason do not resolve.
37 # something about the test is different as it works fine if I replicate
38 # the policies and run tracee myself but doesn't work in the integration
39 # test either with the automatic run or running the commands by hand
40 # while it's searching.
41 "Test_EventFilters/comm:_event:_args:_trace_event_set_in_a_specific_policy_with_args_from_ls_command"
42 "Test_EventFilters/comm:_event:_trace_events_set_in_two_specific_policies_from_ls_and_uname_commands"
43
44 # worked at some point, seems to be flakey
45 "Test_EventFilters/pid:_event:_args:_trace_event_sched_switch_with_args_from_pid_0"
46 ];
47 in
48 ''
49 with subtest("prepare for integration tests"):
50 machine.wait_for_unit("docker.service")
51 machine.succeed('which bash')
52
53 # EventFilters/trace_only_events_from_new_containers also requires a container called "hello-world"
54 machine.succeed('docker load < ${passthru.hello-world-builder pkgs}')
55
56 # exec= needs fully resolved paths
57 machine.succeed(
58 'mkdir /tmp/testdir',
59 'cp $(which who) /tmp/testdir/who',
60 'cp $(which uname) /tmp/testdir/uname',
61 )
62
63 with subtest("run integration tests"):
64 # Test_EventFilters/trace_event_set_in_a_specific_scope expects to be in a dir that includes "integration"
65 # tests must be ran with 1 process
66 print(machine.succeed(
67 'mkdir /tmp/integration',
68 'cd /tmp/integration && export PATH="/tmp/testdir:$PATH" && integration.test -test.v -test.parallel 1 -test.skip="^${builtins.concatStringsSep "$|^" skippedTests}$"'
69 ))
70 '';
71 }
72)