This file is indexed.

/usr/share/perl5/EBox/Config/TestStub.pm is in zentyal-common 2.3.3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright (C) 2008-2012 eBox Technologies S.L.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package EBox::Config::TestStub;
# Description:
#
use strict;
use warnings;

use Test::MockObject;
use Perl6::Junction qw(all);
use EBox::Config;
use Error qw(:try);

# XXX: Derivated paths are ttoally decoupled from their base path (datadir, sysconfdir, localstatedir, libdir)
# possible solution 1:  rewrite EBox::Config so the derivated elements use a sub to get the needed element
# possible solution 2: rewrite this package to have specialized fakes for those subs


my %config       = _defaultConfig();    # this hash hold the configuration items

sub _defaultConfig
{
    my @defaultConfig;

    my @configKeys = qw(prefix etc var user group share libexec locale conf tmp passwd sessionid log logfile stubs cgi templates schemas www css images version lang );
    foreach my $key (@configKeys) {
	my $configKeySub_r = EBox::Config->can($key);
	defined $configKeySub_r or die "Can not find $key sub in EBox::Config module";
	my $value;

	try {
	  $value = $configKeySub_r->();
	}
	otherwise {
	  # ignore systems where configuration files are  not installed
	  $value = undef;
	  print "\n\nFailed: $key \n";;
	};

	push @defaultConfig, ($key => $value );
    }

    return @defaultConfig;
}



sub fake
{
  my @fakedConfig = @_;

  if ( @fakedConfig > 0)  {
    setConfigKeys(@fakedConfig);
  }

}


sub _checkFakeParams
{
    my %params = @_;


}

sub unfake
{
  delete $INC{'EBox/Config.pm'};
  eval 'use EBox::Config';

  $@ and die "Error reloading EBox::Config: $@";
}



sub _checkConfigKeysParameters
{
    my %params = @_;

   # check parameters...
    if (@_ == 0) {
	die "setConfigKeys called without parameters";
    }
    my $allCorrectParam = all (keys %config);
    my @incorrectParams = grep { $_ ne $allCorrectParam } keys %params;

    if (@incorrectParams) {
	die "called with the following incorrect config key names: @incorrectParams";
    }
}

sub setConfigKeys
{
    my %fakedConfig = @_;

    print "checkConfigKey\n\n";
    _checkConfigKeysParameters(@_);

    my @fakeSubs;;
    while ( my ($configKey, $fakedResult) = each %fakedConfig ) {
      push @fakeSubs, ($configKey => sub { return $fakedResult });
    }

    Test::MockObject->fake_module('EBox::Config', @fakeSubs );
}




1;