def test_login_failed_keep_next_url(self):
        """
        LDAP: Keeping next url after failed login attempt
        """
        self.app.config["AUTH_LDAP_SEARCH"] = "ou=users,dc=example,dc=org"
        self.app.config[
            "AUTH_LDAP_USERNAME_FORMAT"
        ] = "cn=%s,ou=users,dc=example,dc=org"
        self.app.config["AUTH_USER_REGISTRATION"] = True
        self.app.config["AUTH_USER_REGISTRATION_ROLE"] = "Public"
        self.app.config["WTF_CSRF_ENABLED"] = False
        self.app.config["SECRET_KEY"] = "thisismyscretkey"

        self.appbuilder = AppBuilder(self.app, self.db.session)
        client = self.app.test_client()
        client.get("/logout/")

        response = client.post(
            "/login/?next=/users/userinfo/",
            data=dict(username="natalie", password="wrong_natalie_password"),
            follow_redirects=False,
        )
        response = client.post(
            response.location,
            data=dict(username="natalie", password="natalie_password"),
            follow_redirects=False,
        )
        assert response.location == "/users/userinfo/"

        LDAP: Keeping next url after failed login attempt
        
tests/security/test_auth_ldap.py