Ejemplo n.º 1
0
    def test_make_configuration(self):
        """Validate the make_configuration method that translates Ansible params to the input body"""
        data = dict(
            log_path=None,
            state='present',
            username='******',
            password='******',
            server='ldap://example.com:384',
            search_base='OU=Users,DC=example,DC=com',
            role_mappings={'.*': ['storage.monitor']},
        )

        self._set_args(**data)
        ldap = Ldap()
        expected = dict(id='default',
                        bindLookupUser=dict(
                            user=data['username'],
                            password=data['password'],
                        ),
                        groupAttributes=['memberOf'],
                        ldapUrl=data['server'],
                        names=['example.com'],
                        searchBase=data['search_base'],
                        roleMapCollection=[{
                            "groupRegex": ".*",
                            "ignoreCase": True,
                            "name": "storage.monitor"
                        }],
                        userAttribute='sAMAccountName')

        actual = ldap.make_configuration()
        self.maxDiff = None
        self.assertEqual(expected, actual)
Ejemplo n.º 2
0
    def test_is_embedded_fail(self):
        """Ensure we fail gracefully when fetching the About data."""

        self._set_args()
        with self.assertRaises(AnsibleFailJson):
            with mock.patch(self.REQ_FUNC, side_effect=Exception):
                ldap = Ldap()
                ldap.is_embedded()
Ejemplo n.º 3
0
    def test_init_defaults(self):
        """Validate a basic run with required arguments set."""
        self._set_args(
            log_path=None,
            state='present',
            username='******',
            password='******',
            server='ldap://example.com:384',
            search_base='OU=Users,DC=example,DC=com',
            role_mappings={'.*': ['storage.monitor']},
        )

        ldap = Ldap()
Ejemplo n.º 4
0
    def test_is_embedded(self):
        """Ensure we can properly detect the type of Web Services instance we're utilizing."""
        self._set_args()

        result = dict(runningAsProxy=False)

        with mock.patch(self.REQ_FUNC, return_value=(200, result)):
            ldap = Ldap()
            embedded = ldap.is_embedded()
            self.assertTrue(embedded)

        result = dict(runningAsProxy=True)

        with mock.patch(self.REQ_FUNC, return_value=(200, result)):
            ldap = Ldap()
            embedded = ldap.is_embedded()
            self.assertFalse(embedded)
Ejemplo n.º 5
0
 def test_init(self):
     """Validate a basic run with required arguments set."""
     self._set_args(log_path=None)
     ldap = Ldap()
Ejemplo n.º 6
0
 def _make_ldap_instance(self):
     self._set_args()
     ldap = Ldap()
     ldap.base_path = '/'
     return ldap