"Fossies" - the Fresh Open Source Software Archive

Member "RT-Extension-Assets-1.05/xt/rights.t" (15 Oct 2014, 3872 Bytes) of package /linux/misc/RT-Extension-Assets-1.05.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 use strict;
    2 use warnings;
    3 
    4 use lib 'xt/lib';
    5 use RT::Extension::Assets::Test tests => undef;
    6 
    7 my $user = RT::Test->load_or_create_user( Name => 'testuser' );
    8 ok $user->id, "Created user";
    9 
   10 my $ticket = RT::Test->create_ticket(
   11     Queue   => 1,
   12     Subject => 'a test ticket',
   13 );
   14 ok $ticket->id, "Created ticket";
   15 
   16 my $catalog_one = create_catalog( Name => "One" );
   17 ok $catalog_one && $catalog_one->id, "Created catalog one";
   18 
   19 my $catalog_two = create_catalog( Name => "Two" );
   20 ok $catalog_two && $catalog_two->id, "Created catalog two";
   21 
   22 ok(RT::Test->add_rights({
   23     Principal   => 'Privileged',
   24     Right       => 'ShowCatalog',
   25     Object      => $catalog_one,
   26 }), "Granted ShowCatalog");
   27 
   28 my $asset = RT::Asset->new( RT::CurrentUser->new($user) );
   29 
   30 diag "CreateAsset";
   31 {
   32     my %create = (
   33         Name    => 'Thinkpad T420s',
   34         Contact => 'trs@example.com',
   35         Catalog => $catalog_one->id,
   36     );
   37     my ($id, $msg) = $asset->Create(%create);
   38     ok !$id, "Create denied: $msg";
   39 
   40     ok(RT::Test->add_rights({
   41         Principal   => 'Privileged',
   42         Right       => 'CreateAsset',
   43         Object      => $catalog_one,
   44     }), "Granted CreateAsset");
   45 
   46     ($id, $msg) = $asset->Create(%create);
   47     ok $id, "Created: $msg";
   48     is $asset->id, $id, "id matches";
   49     is $asset->CatalogObj->Name, $catalog_one->Name, "Catalog matches";
   50 };
   51 
   52 diag "ShowAsset";
   53 {
   54     is $asset->Name, undef, "Can't see Name without ShowAsset";
   55     ok !$asset->Contacts->id, "Can't see Contacts role group";
   56 
   57     ok(RT::Test->add_rights({
   58         Principal   => 'Privileged',
   59         Right       => 'ShowAsset',
   60         Object      => $catalog_one,
   61     }), "Granted ShowAsset");
   62 
   63     is $asset->Name, "Thinkpad T420s", "Got Name";
   64     is $asset->Contacts->UserMembersObj->First->EmailAddress, 'trs@example.com', "Got Contact";
   65 }
   66 
   67 diag "ModifyAsset";
   68 {
   69     my ($txnid, $txnmsg) = $asset->SetName("Lenovo Thinkpad T420s");
   70     ok !$txnid, "Update failed: $txnmsg";
   71     is $asset->Name, "Thinkpad T420s", "Name didn't change";
   72 
   73     my ($ok, $msg) = $asset->AddLink( Type => 'RefersTo', Target => 't:1' );
   74     ok !$ok, "No rights to AddLink: $msg";
   75 
   76     ($ok, $msg) = $asset->DeleteLink( Type => 'RefersTo', Target => 't:1' );
   77     ok !$ok, "No rights to DeleteLink: $msg";
   78 
   79     ok(RT::Test->add_rights({
   80         Principal   => 'Privileged',
   81         Right       => 'ModifyAsset',
   82         Object      => $catalog_one,
   83     }), "Granted ModifyAsset");
   84     
   85     ($txnid, $txnmsg) = $asset->SetName("Lenovo Thinkpad T420s");
   86     ok $txnid, "Updated Name: $txnmsg";
   87     is $asset->Name, "Lenovo Thinkpad T420s", "Name changed";
   88 }
   89 
   90 diag "Catalogs";
   91 {
   92     my ($txnid, $txnmsg) = $asset->SetCatalog($catalog_two->id);
   93     ok !$txnid, "Failed to update Catalog: $txnmsg";
   94     is $asset->CatalogObj->Name, $catalog_one->Name, "Catalog unchanged";
   95 
   96     ok(RT::Test->add_rights({
   97         Principal   => 'Privileged',
   98         Right       => 'CreateAsset',
   99         Object      => $catalog_two,
  100     }), "Granted CreateAsset in second catalog");
  101 
  102     ($txnid, $txnmsg) = $asset->SetCatalog($catalog_two->id);
  103     ok $txnid, "Updated Catalog: $txnmsg";
  104     unlike $txnmsg, qr/Permission Denied/i, "Transaction message isn't Permission Denied";
  105     ok !$asset->CurrentUserCanSee, "Can no longer see the asset";
  106 
  107     ok(RT::Test->add_rights({
  108         Principal   => 'Privileged',
  109         Right       => 'ShowAsset',
  110         Object      => $catalog_two,
  111     }), "Granted ShowAsset");
  112 
  113     ok $asset->CurrentUserCanSee, "Can see the asset now";
  114     is $asset->CatalogObj->Name, undef, "Can't see the catalog name still";
  115 
  116     ok(RT::Test->add_rights({
  117         Principal   => 'Privileged',
  118         Right       => 'ShowCatalog',
  119         Object      => $catalog_two,
  120     }), "Granted ShowCatalog");
  121 
  122     is $asset->CatalogObj->Name, $catalog_two->Name, "Now we can see the catalog name";
  123 }
  124 
  125 done_testing;