Exemple #1
0
#  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, see <http://www.gnu.org/licenses/>.
#

import pytest
import sys

from mock import patch

# Our test utilities
import unittest_utils as utils

sys.path.insert(0, utils.get_code_path())

from serviceAccessConfig.accessrulegenerator import ServiceAccessGenerator
from serviceAccessConfig.generatorexceptions import \
    ServiceAccessGeneratorConfigError, \
    ServiceAccessGeneratorServiceRestartError


# ======================================================================
def test_allowed_client_ip_addrs():
    """Test that we get the expected cidr blocks from a valid config
       file."""

    gen = ServiceAccessGenerator('%s/ip_data.cfg' % utils.get_data_path())
    cidr_blocks = gen._get_allowed_client_ip_addrs()
    expected = '8.0.0.0/24,132.168.2.0/8,154.12.0.0/16,18.168.1.1/32'
Exemple #2
0
#  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, see <http://www.gnu.org/licenses/>.
#

import ConfigParser
import pytest
import sys

from mock import patch

# Our test utilities
import unittest_utils as utils

sys.path.insert(0, utils.get_code_path())

from serviceAccessConfig.haproxy import ServiceAccessGeneratorHaproxy
from serviceAccessConfig.generatorexceptions import *


# ======================================================================
def test_generate_acl_entry():
    """Test the generation of an acl entry"""

    gen = ServiceAccessGeneratorHaproxy(
        '%s/ip_data.cfg' % utils.get_data_path()
    )
    cidr_blocks = ['8.0.0.0/24', '132.168.2.0/8', '154.12.0.0/16']
    acl_entry = gen._generate_acl_entry('network', 10, cidr_blocks)