Alt-NewRelic-Agent-FFI-Empty

 view release on metacpan or  search on metacpan

lib/NewRelic/Agent/FFI/Procedural.pm  view on Meta::CPAN

 my $address = newrelic_basic_literal_replacement_obfuscator;

Returns the address of the C function that does the basic/default obfuscator contained within the
NewRelic agent library.  Normally you wouldn't call this from Perl, so it is the address of the
function, not the function itself.  You can, however, call it via L<FFI::Platypus>:

 use FFI::Platypus;

 my $ffi = FFI::Platypus->new;
 $new->attach( newrelic_basic_literal_replacement_obfuscator, ['string'] => 'string');
 my $save = newrelic_basic_literal_replacement_obfuscator("SELECT * FROM user WHERE password = 'secret'");

=head2 newrelic_request_shutdown

 my $rc = newrelic_request_shutdown $reason;

Tell the Collector Client to shutdown and stop reporting application performance data to New Relic.

=head2 newrelic_enable_instrumentation

 newrelic_enable_instrumentation $set_enabled;

t/newrelic_agent_ffi_procedural.t  view on Meta::CPAN


};

subtest 'newrelic_basic_literal_replacement_obfuscator' => sub {

  skip_all 'not works';

  my $ffi = FFI::Platypus->new;
  my $f = $ffi->function( newrelic_basic_literal_replacement_obfuscator, ['string'] => 'string' );
  
  my $hidden = $f->("SELECT * FROM user WHERE password = 'secret'");
  pass "didn't crash";
  note $hidden;

};

subtest 'init' => sub {

  newrelic_init;
  
  pass "didn't crash";

t/newrelic_agent_ffi_procedural.t  view on Meta::CPAN

subtest 'newrelic_segment_datastore_begin' => sub {

  my $tx = newrelic_transaction_begin;
  ok $tx, 'newrelic_transaction_begin';

  our $sql_in;
  sub myobfuscator
  {
    ($sql_in) = @_;
    note "myobfuscator($sql_in)";
    my $sql_out = 'select * from users where password = ?';
    state $ptr = 0;
    free($ptr) if $ptr;
    $ptr = strdup $sql_out;
  }
  
  my $ffi = FFI::Platypus->new;
  $ffi->type('(string)->opaque' => 'ob');
  my $myobfuscator_closure = $ffi->closure(\&myobfuscator);
  my $myobfuscator_ptr = $ffi->cast(ob => opaque => $myobfuscator_closure);
  note "\$myobfuscator_ptr = $myobfuscator_ptr";
  
  my $seg = newrelic_segment_datastore_begin $tx, NEWRELIC_ROOT_SEGMENT, 'mytable', 'select', "select * from users where password = 'secret'", 'get_user_pw', $myobfuscator_ptr;
  ok $seg, 'newrelic_segment_datastore_begin';

  #is $sql_in, "select * from users where password = 'secret'", 'myobfuscator called';
  
  sleep rand .5;
  
  my $rc = newrelic_segment_end $tx, $seg;
  is $rc, 0, 'newrelic_segment_end';
  
  newrelic_transaction_end $tx;
  ok 1, 'newrelic_transaction_end';
};



( run in 0.517 second using v1.01-cache-2.11-cpan-49f99fa48dc )