body common control
{
  inputs => { "../default.sub.cf" };
  bundlesequence => { default("$(this.promise_filename)") };
  version => "1.0";
}

bundle agent init
{
  methods:
    "any" usebundle => dcs_fini("$(G.testfile).plain");
    "any" usebundle => dcs_fini("$(G.testfile).encrypted");
    "any" usebundle => dcs_fini("$(G.testfile).decrypted");
    "any" usebundle => generate_key;
    "any" usebundle => trust_key;
}

bundle agent test
{
  meta:
    "description"
      string => "Test that cf-secret basic key based encryption and decryption work";

    "test_soft_fail"
      string => "windows",
      meta => { "ENT-10405" };

  vars:
    "text" string => "This secret sauce should be encrypted and decrypted.";

  files:
    "$(G.testfile).plain"
      create => "true",
      edit_defaults => empty,
      edit_line => insert_lines("$(text)");

  commands:
    "$(sys.cf_secret)"
      args => "encrypt -k $(sys.workdir)/ppkeys/localhost.pub -o $(G.testfile).encrypted $(G.testfile).plain";

    "$(sys.cf_secret)"
      args => "decrypt -k $(sys.workdir)/ppkeys/localhost.priv -o $(G.testfile).decrypted $(G.testfile).encrypted";

  reports:
    "Binaries/folders:";
    "$(sys.cf_secret)";
    "$(sys.cf_agent)";
    "$(sys.workdir)";
}

bundle agent check
{
  methods:
    "any"
      usebundle => dcs_check_diff(
        "$(G.testfile).plain",
        "$(G.testfile).decrypted",
        "$(this.promise_filename)"
      );
}
