[Rt-commit] rt branch, 4.2/shredder-web-username, created. rt-4.2.13-121-ge8945f0
Jim Brandt
jbrandt at bestpractical.com
Thu May 4 11:41:25 EDT 2017
The branch, 4.2/shredder-web-username has been created
at e8945f09dcf7c2c60eab6e0ca09866d4a393f297 (commit)
- Log -----------------------------------------------------------------
commit 86bcd0b16285fb8d5449c988ae3243694dd9e916
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu May 4 10:08:24 2017 -0400
Add user shredder tests with same method order as web interface
The web interface for shredder calls a sequence of shredder
methods to load user objects slightly different than the
command-line and tests. Add tests that match the web interface
and show a failure when passing a username to load a user object.
diff --git a/t/shredder/03plugin_users.t b/t/shredder/03plugin_users.t
index 8f0fc2c..75a9201 100644
--- a/t/shredder/03plugin_users.t
+++ b/t/shredder/03plugin_users.t
@@ -3,7 +3,7 @@ use strict;
use warnings;
use Test::Deep;
-use RT::Test::Shredder tests => 21;
+use RT::Test::Shredder tests => undef;
my $test = "RT::Test::Shredder";
my @ARGS = sort qw(limit status name member_of not_member_of email replace_relations no_tickets no_ticket_transactions);
@@ -87,3 +87,57 @@ $test->create_savepoint('clean');
$shredder->Wipeout( Object => $userA );
}
cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
+
+{ # Same as previous test, but pass Objects to PutObjects in the same form as the web interface
+ my ($uidA, $uidB, $msg);
+ my $userA = RT::User->new( RT->SystemUser );
+ ($uidA, $msg) = $userA->Create( Name => 'userA', Privileged => 1, Disabled => 0 );
+ ok( $uidA, "created user A" ) or diag "error: $msg";
+
+ my $userB = RT::User->new( RT->SystemUser );
+ ($uidB, $msg) = $userB->Create( Name => 'userB', Privileged => 1, Disabled => 0 );
+ ok( $uidB, "created user B" ) or diag "error: $msg";
+
+ my ($tid, $trid);
+ my $ticket = RT::Ticket->new( RT::CurrentUser->new($userB) );
+ ($tid, $trid, $msg) = $ticket->Create( Subject => 'UserB Ticket', Queue => 1 );
+ ok( $tid, "created new ticket") or diag "error: $msg";
+ $ticket->ApplyTransactionBatch;
+
+ my $transaction = RT::Transaction->new( RT->SystemUser );
+ $transaction->Load($trid);
+ is ( $transaction->Creator, $uidB, "ticket creator is user B" );
+
+ my $plugin = RT::Shredder::Plugin::Users->new;
+ isa_ok($plugin, 'RT::Shredder::Plugin::Users');
+
+ my $status;
+ ($status, $msg) = $plugin->TestArgs( status => 'any', name => 'userB', replace_relations => $uidA );
+ ok($status, "plugin arguments are ok") or diag "error: $msg";
+
+ my $shredder = $test->shredder_new();
+
+ my @objs;
+ ($status, @objs) = $plugin->Run;
+ ok($status, "executed plugin successfully") or diag "error: @objs";
+
+ # Same form as param coming in via the web interface
+ $shredder->PutObjects( Objects => ['RT::User-userB'] );
+
+ ($status, $msg) = $plugin->SetResolvers( Shredder => $shredder );
+ ok($status, "set conflicts resolver") or diag "error: $msg";
+
+ $shredder->WipeoutAll;
+
+ $ticket->Load( $tid );
+ is($ticket->id, $tid, 'loaded ticket');
+
+ $transaction->Load($trid);
+ is ( $transaction->Creator, $uidA, "ticket creator is now user A" );
+
+ $shredder->Wipeout( Object => $ticket );
+ $shredder->Wipeout( Object => $userA );
+}
+cmp_deeply( $test->dump_current_and_savepoint('clean'), "current DB equal to savepoint");
+
+done_testing();
commit e8945f09dcf7c2c60eab6e0ca09866d4a393f297
Author: Jim Brandt <jbrandt at bestpractical.com>
Date: Thu May 4 10:11:59 2017 -0400
Check for both id and name mismatches when loading objects
The shredder web interface accepts a name to search for
user objects and up to 4.2.10 this was converted to an ID
in the WipeoutObject list displayed after a search.
f363a0bd changed _AsString to UID for populating these values
which for a user search resulted in usernames being submitted
rather than user ids. Usernames passed to CastObjectsToRecords
loaded properly, but then hit an error check that expected only ids.
Update the check to handle name or id based on the passed value.
diff --git a/lib/RT/Shredder.pm b/lib/RT/Shredder.pm
index 108164d..0d09666 100644
--- a/lib/RT/Shredder.pm
+++ b/lib/RT/Shredder.pm
@@ -363,7 +363,13 @@ sub CastObjectsToRecords
$RT::Logger->error( "Couldn't load '$class' object with id '$id'" );
RT::Shredder::Exception::Info->throw( 'CouldntLoadObject' );
}
- die "Loaded object has different id" unless( $id eq $obj->id );
+
+ if ( $id =~ /^\d+$/ && $id ne $obj->Id ){
+ die 'Loaded object id ' . $obj->Id . " is different from passed id $id";
+ }
+ elsif ( $id ne $obj->Name ){
+ die 'Loaded object name ' . $obj->Name . " is different from passed name $id";
+ }
push @res, $obj;
} else {
RT::Shredder::Exception->throw( "Unsupported type ". ref $targets );
-----------------------------------------------------------------------
More information about the rt-commit
mailing list