Esempio n. 1
0
    def test_bind_with_failover(self):
        """
        test the failover in the bind handling
        """

        # ------------------------------------------------------------------ --

        # setup the ldap fake resolver, which requires:
        # - an mocked connect
        # - an mocked bindpw, which in normal case would contain the
        #   crypted data
        # the mocked resolver loads the derived mocked ResouceSchduler with
        # the mocked Registry so that we can access the calling data

        myldap = LDAPResolver()
        myldap.ldapuri = ("ldap://fail_bind1.psw.de, "
                          "ldap://fail_bind2.psw.de, "
                          "ldap://ok_bind3.psw.de, "
                          "ldap://ok_bind4.psw.de, ")

        myldap.bindpw = MockedBindPW("geheim1")

        # ------------------------------------------------------------------ --

        # run the bind test

        myldap.bind()

        # ------------------------------------------------------------------ --

        # evaluate the result: how often called

        called = FakeLdapResolver.called

        assert len(called) == 2 * TRIES + 1
        assert "ldap://ok_bind4.psw.de" not in called

        # ------------------------------------------------------------------ --

        # evaluate the result: failed should be blocked, other not

        registry = MockedResourceRegistry.registry

        for key, val in list(registry.items()):
            value, _b_ind, _b_count = val

            if "fail" in key:
                assert value is not None
            else:
                assert value is None

        # ------------------------------------------------------------------ --

        # verify that the 4th entry was never evaluated

        assert "ldap://ok_bind4.psw.de" not in registry

        return
Esempio n. 2
0
    def test_bind_with_fail(self):
        """
        test the failover in the bind handling
        """

        # ------------------------------------------------------------------ --

        # setup the ldap fake resolver, which requires:
        # - an mocked connect
        # - an mocked bindpw, which in normal case would contain the
        #   crypted data
        # the mocked resolver loads the derived mocked ResouceSchduler with
        # the mocked Registry so that we can access the calling data

        myldap = LDAPResolver()
        myldap.ldapuri = ("ldap://fail_bind1.psw.de, "
                          "ldap://fail_bind2.psw.de, "
                          "ldap://fail_bind3.psw.de, "
                          "ldap://fail_bind4.psw.de, ")

        myldap.binddn = "Heinz"
        myldap.bindpw = MockedBindPW("geheim1")

        # ------------------------------------------------------------------ --

        # run the bin test
        with freeze_time("2012-01-14 12:00:00"):

            with pytest.raises(ResolverNotAvailable):
                myldap.bind()

            # -------------------------------------------------------------- --

            # evaluate the result: how often called

            called = FakeLdapResolver.called

            assert len(called) == 4 * TRIES
            assert "ldap://fail_bind4.psw.de" in called

            # -------------------------------------------------------------- --

            # evaluate the result: failed should be blocked, other not

            registry = MockedResourceRegistry.registry

            for key, value in list(registry.items()):
                assert value is not None

            # -------------------------------------------------------------- --

            # verify that the 4th entry was evaluated

            assert "ldap://fail_bind4.psw.de" in registry

            # -------------------------------------------------------------- --

            # now reset the calle registration

            FakeLdapResolver.called = []

            #           # -------------------------------------------------------------- --

            # and re-run the bind

            with pytest.raises(ResolverNotAvailable):
                myldap.bind()

            # -------------------------------------------------------------- --

            # now all resources are marked as blocked and
            # none will be called

            called = FakeLdapResolver.called

            assert len(called) == 0
            assert "ldap://fail_bind1.psw.de" not in called

        with freeze_time("2012-01-14 12:01:00"):

            # -------------------------------------------------------------- --

            # one minute later re-run the bind

            myldap.ldapuri = ("ldap://fail_bind1.psw.de, "
                              "ldap://fail_bind2.psw.de, "
                              "ldap://go_bind3.psw.de, "
                              "ldap://go_bind4.psw.de, ")

            myldap.bind()

            # -------------------------------------------------------------- --

            # evaluate the result: how often called

            called = FakeLdapResolver.called

            assert len(called) == 2 * TRIES + 1
            assert "ldap://go_bind4.psw.de" not in called

            # -------------------------------------------------------------- --

            # evaluate the result: failed should be blocked, other not

            registry = MockedResourceRegistry.registry

            for key, val in list(registry.items()):
                value, _b_ind, _b_count = val

                if "fail" in key:
                    assert value is not None
                else:
                    assert value is None

            # -------------------------------------------------------------- --

            # verify that the 4th entry was never evaluated

            assert "ldap://go_bind4.psw.de" not in registry

        return