Changeset 11234
- Timestamp:
- 08/19/08 11:13:38 (5 months ago)
- Location:
- branches/remote-services/ebox/src/EBox
- Files:
-
- 2 modified
-
Apache.pm (modified) (2 diffs)
-
t/Apache.t (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/remote-services/ebox/src/EBox/Apache.pm
r10308 r11234 44 44 use constant RESTRICTED_PATH_TYPE_KEY => 'path_type'; 45 45 use constant RESTRICTED_RESOURCE_TYPE_KEY => 'type'; 46 use constant INCLUDE_KEY => 'includes'; 46 47 use constant ABS_PATH => 'absolute'; 47 48 use constant REL_PATH => 'relative'; … … 421 422 } 422 423 424 # Method: addInclude 425 # 426 # Add an "include" directive to the apache configuration 427 # 428 # Parameters: 429 # 430 # includeFilePath - String the configuration file path to include 431 # in apache configuration 432 # 433 # Exceptions: 434 # 435 # <EBox::Exceptions::MissingArgument> - thrown if any compulsory 436 # argument is missing 437 # 438 # <EBox::Exceptions::Internal> - thrown if the given file does 439 # not exists 440 # 441 sub addInclude 442 { 443 my ($self, $includeFilePath) = @_; 444 445 unless(defined($includeFilePath)) { 446 throw EBox::Exceptions::MissingArgument('includeFilePath'); 447 } 448 unless(-f $includeFilePath and -r $includeFilePath) { 449 throw EBox::Exceptions::Internal( 450 "File $includeFilePath cannot be read or it is not a file" 451 ); 452 } 453 my @includes = @{$self->_includes()}; 454 unless ( grep { $_ eq $includeFilePath } @includes) { 455 push(@includes, $includeFilePath); 456 $self->set_list(INCLUDE_KEY, 'string', \@includes); 457 } 458 459 } 460 461 # Method: removeInclude 462 # 463 # Remove an "include" directive to the apache configuration 464 # 465 # Parameters: 466 # 467 # includeFilePath - String the configuration file path to remove 468 # from apache configuration 469 # 470 # Exceptions: 471 # 472 # <EBox::Exceptions::MissingArgument> - thrown if any compulsory 473 # argument is missing 474 # 475 # <EBox::Exceptions::Internal> - thrown if the given file has not 476 # been included previously 477 # 478 sub removeInclude 479 { 480 my ($self, $includeFilePath) = @_; 481 482 unless(defined($includeFilePath)) { 483 throw EBox::Exceptions::MissingArgument('includeFilePath'); 484 } 485 my @includes = @{$self->_includes()}; 486 my @newIncludes = grep { $_ ne $includeFilePath } @includes; 487 if ( @newIncludes eq @includes ) { 488 throw EBox::Exceptions::Internal("$includeFilePath has not been included previously"); 489 } 490 $self->set_list(INCLUDE_KEY, 'string', \@newIncludes); 491 492 } 493 494 # Return those include files that has been added 495 sub _includes 496 { 497 my ($self) = @_; 498 return $self->get_list(INCLUDE_KEY); 499 } 500 423 501 1; -
branches/remote-services/ebox/src/EBox/t/Apache.t
r8978 r11234 16 16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 17 18 # A module to test restricted resources methods on Apache module18 # A module to test restricted resources and includes methods on Apache module 19 19 20 20 use warnings; 21 21 use strict; 22 22 23 use Test::More tests => 14;23 use Test::More tests => 24; 24 24 use Test::Exception; 25 25 use Test::Deep; … … 28 28 29 29 BEGIN { 30 diag('Starting test for restricted resources methodon Apache module');30 diag('Starting test for some methods on Apache module'); 31 31 use_ok('EBox::Apache') 32 32 or die; … … 102 102 } 'EBox::Exceptions::DataNotFound', 'Given resource name not found'; 103 103 104 # Include related tests 105 my @includes = ( '/bin/true', '/bin/false' ); 106 my @deviantIncludes = ( '/bin/dafdfa' ); 107 108 throws_ok { 109 $apacheMod->addInclude(); 110 } 'EBox::Exceptions::MissingArgument', 'No file to include'; 111 112 throws_ok { 113 $apacheMod->addInclude($deviantIncludes[0]); 114 } 'EBox::Exceptions::Internal', 'File to include does not exits'; 115 116 lives_ok { 117 $apacheMod->addInclude($_) foreach (@includes); 118 } 'Adding some includes'; 119 120 cmp_deeply($apacheMod->_includes(), \@includes, 121 'The two includes added'); 122 123 lives_ok { 124 $apacheMod->addInclude($_) foreach (@includes); 125 } 'Trying to add the same again'; 126 127 cmp_deeply($apacheMod->_includes(), \@includes, 128 'Only the two includes are there'); 129 130 throws_ok { 131 $apacheMod->removeInclude(); 132 } 'EBox::Exceptions::MissingArgument', 'No file to exclude'; 133 134 throws_ok { 135 $apacheMod->removeInclude($deviantIncludes[0]); 136 } 'EBox::Exceptions::Internal', 'No file to remove'; 137 138 lives_ok { 139 $apacheMod->removeInclude($_) foreach (@includes); 140 } 'Removing all the include files'; 141 142 cmp_ok(@{$apacheMod->_includes()}, '==', 0, 143 'Nothing has been left'); 144 104 145 1;
