Changeset 11234

Show
Ignore:
Timestamp:
08/19/08 11:13:38 (5 months ago)
Author:
/C=ES/O=Warp Networks S.L./CN=ejhernandez@…
Message:

Added several methods to allow add/remove include directives in eBox apache main configuration refs #1103

Location:
branches/remote-services/ebox/src/EBox
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/remote-services/ebox/src/EBox/Apache.pm

    r10308 r11234  
    4444use constant RESTRICTED_PATH_TYPE_KEY => 'path_type'; 
    4545use constant RESTRICTED_RESOURCE_TYPE_KEY => 'type'; 
     46use constant INCLUDE_KEY => 'includes'; 
    4647use constant ABS_PATH => 'absolute'; 
    4748use constant REL_PATH => 'relative'; 
     
    421422} 
    422423 
     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# 
     441sub 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# 
     478sub 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 
     495sub _includes 
     496{ 
     497    my ($self) = @_; 
     498    return $self->get_list(INCLUDE_KEY); 
     499} 
     500 
    4235011; 
  • branches/remote-services/ebox/src/EBox/t/Apache.t

    r8978 r11234  
    1616# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    1717 
    18 # A module to test restricted resources methods on Apache module 
     18# A module to test restricted resources and includes methods on Apache module 
    1919 
    2020use warnings; 
    2121use strict; 
    2222 
    23 use Test::More tests => 14; 
     23use Test::More tests => 24; 
    2424use Test::Exception; 
    2525use Test::Deep; 
     
    2828 
    2929BEGIN { 
    30     diag('Starting test for restricted resources method on Apache module'); 
     30    diag('Starting test for some methods on Apache module'); 
    3131    use_ok('EBox::Apache') 
    3232      or die; 
     
    102102} 'EBox::Exceptions::DataNotFound', 'Given resource name not found'; 
    103103 
     104# Include related tests 
     105my @includes = ( '/bin/true', '/bin/false' ); 
     106my @deviantIncludes = ( '/bin/dafdfa' ); 
     107 
     108throws_ok { 
     109    $apacheMod->addInclude(); 
     110} 'EBox::Exceptions::MissingArgument', 'No file to include'; 
     111 
     112throws_ok { 
     113    $apacheMod->addInclude($deviantIncludes[0]); 
     114} 'EBox::Exceptions::Internal', 'File to include does not exits'; 
     115 
     116lives_ok { 
     117    $apacheMod->addInclude($_) foreach (@includes); 
     118} 'Adding some includes'; 
     119 
     120cmp_deeply($apacheMod->_includes(), \@includes, 
     121       'The two includes added'); 
     122 
     123lives_ok { 
     124    $apacheMod->addInclude($_) foreach (@includes); 
     125} 'Trying to add the same again'; 
     126 
     127cmp_deeply($apacheMod->_includes(), \@includes, 
     128           'Only the two includes are there'); 
     129 
     130throws_ok { 
     131    $apacheMod->removeInclude(); 
     132} 'EBox::Exceptions::MissingArgument', 'No file to exclude'; 
     133 
     134throws_ok { 
     135    $apacheMod->removeInclude($deviantIncludes[0]); 
     136} 'EBox::Exceptions::Internal', 'No file to remove'; 
     137 
     138lives_ok { 
     139    $apacheMod->removeInclude($_) foreach (@includes); 
     140} 'Removing all the include files'; 
     141 
     142cmp_ok(@{$apacheMod->_includes()}, '==', 0, 
     143       'Nothing has been left'); 
     144 
    1041451;