Skip to content

Commit

Permalink
fix: TOOLS-2693 add ldap return codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesse Schmidt committed Oct 12, 2023
1 parent 938caae commit c65b285
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/live_cluster/client/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
19 changes: 19 additions & 0 deletions test/unit/live_cluster/client/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down Expand Up @@ -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")

0 comments on commit c65b285

Please sign in to comment.