示例#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)
示例#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()
示例#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()
示例#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)
示例#5
0
 def test_init(self):
     """Validate a basic run with required arguments set."""
     self._set_args(log_path=None)
     ldap = Ldap()
示例#6
0
 def _make_ldap_instance(self):
     self._set_args()
     ldap = Ldap()
     ldap.base_path = '/'
     return ldap