From c65b2859b56408dfd45e58b1d4e5609a762eeba5 Mon Sep 17 00:00:00 2001 From: Jesse Schmidt Date: Thu, 12 Oct 2023 17:53:10 -0400 Subject: [PATCH] fix: TOOLS-2693 add ldap return codes --- lib/live_cluster/client/types.py | 19 +++++++++++++++++++ test/unit/live_cluster/client/test_types.py | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/live_cluster/client/types.py b/lib/live_cluster/client/types.py index 2ebadedb..55a1b894 100644 --- a/lib/live_cluster/client/types.py +++ b/lib/live_cluster/client/types.py @@ -113,6 +113,8 @@ def __str__(self): @unique class ASResponse(IntEnum): + _return_code_value: int | None + ERROR_RESPONSE_CODE = -1 OK = 0 UNKNOWN_SERVER_ERROR = 1 QUERY_END = 50 # Signal end of a query response. Is OK @@ -138,11 +140,28 @@ class ASResponse(IntEnum): ROLE_OR_PRIVILEGE_VIOLATION = 81 NOT_WHITELISTED = 82 RATE_QUOTA_EXCEEDED = 83 + ERROR_IN_LDAP_SETUP = 91 # Error in LDAP setup. EE 4.1.0.1 + ERROR_IN_LDAP_TLS_SETUP = 92 # Error in LDAP TLS setup. EE 4.1.0.1 + UNABLE_TO_AUTHENTICATE_LDAP_USER = 93 # Error authenticating LDAP user. EE 4.1.0.1 + ERROR_QUERYING_LDAP_SERVER = 94 # Error querying LDAP server. + + @classmethod + def _missing_(cls, value): + if isinstance(value, int): + asr = cls.ERROR_RESPONSE_CODE + asr._return_code_value = value + return asr + + return super()._missing_(value) def __str__(self): lower = self.name.lower().split("_") lower = " ".join(lower) lower = lower[0].upper() + lower[1:] + + if self.value == ASResponse.ERROR_RESPONSE_CODE: + lower += " ({})".format(self._return_code_value) + return lower diff --git a/test/unit/live_cluster/client/test_types.py b/test/unit/live_cluster/client/test_types.py index 1fb1743e..46f80b13 100644 --- a/test/unit/live_cluster/client/test_types.py +++ b/test/unit/live_cluster/client/test_types.py @@ -15,10 +15,13 @@ from mock import MagicMock import unittest +from parameterized import parameterized + from test.unit import util from lib.live_cluster.client.node import ( ASInfoConfigError, ASInfoResponseError, + ASResponse, ) @@ -233,3 +236,19 @@ def test_error_with_message(self): ) self.assertEqual(str(actual), expected) + + +class ASResponseTest(unittest.TestCase): + @parameterized.expand( + [ + (0, "Ok"), + (94, "Error querying ldap server"), + (99999, "Error response code (99999)"), + ("Error response code (99999)"), + ] + ) + def test_success(self, code, expected): + self.assertEqual(str(ASResponse(code)), expected) + + def test_fail(self): + self.assertRaises(ValueError, ASResponse, "wrong")