Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TOOLS-2693 add ldap return codes #216

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 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,18 @@ 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)"),
]
)
def test_success(self, code, expected):
self.assertEqual(str(ASResponse(code)), expected)

def test_fail(self):
self.assertRaises(ValueError, ASResponse, "wrong")
Loading