App-Spoor

 view release on metacpan or  search on metacpan

lib/App/Spoor/Installer.pm  view on Meta::CPAN

          api_secret => $install_parameters->{'api_secret'},
        },
        host => 'https://spoor.capefox.co',
        endpoints => {
          report => '/api/reports',
        }
      }
    });

  $config->write("$root_path/etc/spoor/spoor.yml");
  chmod(0600, "$root_path/etc/spoor/spoor.yml");

  mkdir("$root_path/var/lib/spoor", 0700);
  mkdir("$root_path/var/lib/spoor/parsed", 0700);
  mkdir("$root_path/var/lib/spoor/transmitted", 0700);
  mkdir("$root_path/var/lib/spoor/transmission_failed", 0700);

  open(my $login_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-login-follower.service") or die("Could not open: $!");
  print $login_handle App::Spoor::LoginUnitFile::contents();
  close $login_handle;
  chmod(0644, "$root_path/etc/systemd/system/spoor-login-follower.service");

  open(my $access_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-access-follower.service") or die("Could not open: $!");
  print $access_handle App::Spoor::AccessUnitFile::contents();
  close $access_handle;
  chmod(0644, "$root_path/etc/systemd/system/spoor-access-follower.service");

  open(my $error_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-error-follower.service") or die("Could not open: $!");
  print $error_handle App::Spoor::ErrorUnitFile::contents();
  close $error_handle;
  chmod(0644, "$root_path/etc/systemd/system/spoor-error-follower.service");

  open(my $transmitter_handle, '>:encoding(UTF-8)', "$root_path/etc/systemd/system/spoor-transmitter.service") or die("Could not open: $!");
  print $transmitter_handle App::Spoor::TransmitterUnitFile::contents();
  close $transmitter_handle;
  chmod(0644, "$root_path/etc/systemd/system/spoor-transmitter.service");

  mkdir("$root_path/var/cpanel/perl5", 0755);
  mkdir("$root_path/var/cpanel/perl5/lib", 0755);
  open(my $hook_file_handle, '>:encoding(UTF-8)', "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm") or die("Could not open; $!");
  print $hook_file_handle App::Spoor::CpanelHookFile::contents();
  close $hook_file_handle;
  chmod(0644,  "$root_path/var/cpanel/perl5/lib/SpoorForwardHook.pm");
}

=head1 AUTHOR

Rory McKinley, C<< <rorymckinley at capefox.co> >>

=head1 BUGS

Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>.  I will be notified, and then you'll

lib/App/Spoor/ParsedEntryWriter.pm  view on Meta::CPAN

    (
      $event eq 'forward_added_partial_recipient' && $status eq 'success' && $forward_type eq 'email' &&
      $context eq 'mailbox'
    ) ||
    ($event eq 'forward_removed' && $status eq 'success' && $context eq 'mailbox') 
  ) {
    my $timestamp = time();
    my $random_element = int(rand(1000000)) + 1000000;
    my $filepath = File::Spec->catdir($path, "$type.$timestamp.$random_element.json");
    touch($filepath);
    chmod(0600, $filepath);

    open(my $file_handle, '>', $filepath) or die "Couldn't open: $!";
    print $file_handle JSON->new->encode($contents_ref);
    close $file_handle;

    return $filepath;
  } else {
    return;
  }
}

t/Config.t  view on Meta::CPAN

      partial_report_log => '/api/partial_reports/log',
    }
  }
);

sub populate_config_file {
  my $config = YAML::Tiny->new(shift @_);
  my $root_path = shift @_;

  $config->write("$root_path/etc/spoor/spoor.yml");
  chmod(0600,  "$root_path/etc/spoor/spoor.yml");
}

sub setup {
  mkdir($root_path, 0744);
  mkdir("$root_path/etc", 0744);
  mkdir("$root_path/etc/spoor", 0744);
  &populate_config_file(\%config_contents, $root_path);
}

sub teardown {

t/Security.t  view on Meta::CPAN

      !App::Spoor::Security::check_config_directory($real_user_id, $root_path),
      'Config directory has incorrect permissions'
    );
  });

ok(defined(&App::Spoor::Security::check_config_file), 'App::Spoor::Security::check_config_file is not defined');

$environment->run_test('Spoor config file has correct permissions and ownership', sub {
    mkdir("$root_path/etc/spoor", 0755);
    touch("$root_path/etc/spoor/spoor.yml");
    chmod(0600, "$root_path/etc/spoor/spoor.yml");
    ok(
      App::Spoor::Security::check_config_file($real_user_id, $root_path),
      'Config file has correct permissions and ownership'
    );
  });

$environment->run_test('Config file has incorrect ownership',sub {
    mkdir("$root_path/etc/spoor", 0755);
    touch("$root_path/etc/spoor/spoor.yml");
    chmod(0600, "$root_path/etc/spoor/spoor.yml");
    ok(
      !App::Spoor::Security::check_config_file($real_user_id + 1, $root_path),
      'Config file has incorrect ownership'
    );
  });

$environment->run_test('Config file has incorrect permissions',sub {
    mkdir("$root_path/etc/spoor", 0755);
    touch("$root_path/etc/spoor/spoor.yml");
    chmod(0500, "$root_path/etc/spoor/spoor.yml");
    ok(
      !App::Spoor::Security::check_config_file($real_user_id, $root_path),
      'Config file has incorrect permissions'
    );
  });

ok(
  defined(&App::Spoor::Security::check_persistence_directory),
  'App::Spoor::Security::check_persistence_directory is not defined'
);

t/Security.t  view on Meta::CPAN

      'Parsed persistence directory has incorrect permissions'
    );
  });

ok(defined(&App::Spoor::Security::check_file), 'App::Spoor::Security::check_file is not defined');

$environment->run_test('File with correct ownership and permissions', sub {
    mkdir("$root_path/var/lib/spoor", 0700);
    mkdir("$root_path/var/lib/spoor/parsed", 0700);
    touch("$root_path/var/lib/spoor/parsed/foo");
    chmod(0600, "$root_path/var/lib/spoor/parsed/foo");
    ok(
      App::Spoor::Security::check_file("$root_path/var/lib/spoor/parsed/foo", $real_user_id, 0600),
      'File has correct permissions and ownership'
    );
  });

$environment->run_test('File with incorrect ownership', sub {
    mkdir("$root_path/var/lib/spoor", 0700);
    mkdir("$root_path/var/lib/spoor/parsed", 0700);
    touch("$root_path/var/lib/spoor/parsed/foo");
    chmod(0600, "$root_path/var/lib/spoor/parsed/foo");
    ok(
      !App::Spoor::Security::check_file("$root_path/var/lib/spoor/parsed/foo", $real_user_id + 1, 0600),
      'File has incorrect ownership'
    );
  });

$environment->run_test('File with incorrect permissions', sub {
    mkdir("$root_path/var/lib/spoor", 0700);
    mkdir("$root_path/var/lib/spoor/parsed", 0700);
    touch("$root_path/var/lib/spoor/parsed/foo");
    chmod(0600, "$root_path/var/lib/spoor/parsed/foo");
    ok(
      !App::Spoor::Security::check_file("$root_path/var/lib/spoor/parsed/foo", $real_user_id, 0500),
      'File has incorrect permissions'
    );
  });

done_testing();



( run in 0.378 second using v1.01-cache-2.11-cpan-496ff517765 )