1#######################################################
2#
3# Check if the lines in a file get truncated after 4096
4# chars during file editing.
5#
6# Ticket: https://cfengine.com/dev/issues/3882
7#
8#######################################################
9
10body common control
11{
12      inputs => { "../../default.cf.sub" };
13      bundlesequence  => { default("${this.promise_filename}") };
14      version => "1.0";
15      cache_system_functions => "off";
16}
17
18#######################################################
19
20bundle agent init
21{
22  vars:
23    any::
24      "file_mode"              int => "0644";
25      "char_number"            int => "6144";
26      "line_to_add"         string => "This is a nice short line.";
27
28  files:
29      "${G.testfile}"
30        create => "true",
31        perms  => m("${file_mode}");
32
33  # Using system command instead of CFEngine itself to
34  # prevent the bug to be here at file creation too.
35  # It would create a false negative.
36  commands:
37      "${G.perl}"
38        args    => "-e 'print \"#\" x ${char_number}; print \"ENDMARK\n\"' > ${G.testfile}",
39        contain => in_shell;
40}
41
42#######################################################
43
44bundle agent test
45{
46  meta:
47      "test_skip_unsupported" string => "windows";
48
49  files:
50      "${G.testfile}"
51        create    => "false",
52        edit_line => insert_lines("${init.line_to_add}");
53}
54
55#######################################################
56
57bundle agent check
58{
59
60  classes:
61    !solaris::
62      # ok is defined if the file still contains ENDMARK, meaning the end of the sample very
63      # long line did not get truncated during file editing
64      "ok" expression => returnszero("${G.grep} ENDMARK ${G.testfile}", "noshell");
65    solaris::
66      # Bug in xpg4 version of Solaris. grep internally has a limit of 4096 chars per line,
67      # which is the very thing we're testing. Use /bin/grep.
68      "ok" expression => returnszero("/bin/grep ENDMARK ${G.testfile}", "noshell");
69
70  reports:
71    DEBUG.!ok::
72      "${this.promise_filename} FAILed as the generated file got at least a line truncated to 4096 characters";
73    ok::
74      "${this.promise_filename} Pass";
75    !ok::
76      "${this.promise_filename} FAIL";
77}
78
79#######################################################
80
81bundle agent fini
82{
83  methods:
84      "any" usebundle => dcs_fini("${G.testfile}");
85}
86
87### PROJECT_ID: core
88### CATEGORY_ID: 27
89