1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-02-15 05:57:38 +03:00

Updating user interface and making tests

This commit is contained in:
Adolfo Gómez García 2022-10-31 01:47:55 +01:00
parent adb4b5326a
commit 15576fdc22
No known key found for this signature in database
GPG Key ID: DD1ABF20724CDA23
8 changed files with 31 additions and 29 deletions

View File

@ -81,4 +81,8 @@ class GuiTest(UDSTestCase):
# id, text, and base64 image
self.assertEqual(gui.choiceImage('id', 'text', 'image'), {'id': 'id', 'text': 'text', 'img': 'image'})
def test_to_bool(self) -> None:
for val in ('true', 'True', 'TRUE', 'yes', 'Yes', 'YES', '1'):
self.assertTrue(gui.toBool(val), 'Failed to convert {} to True'.format(val))
for val in ('false', 'False', 'FALSE', 'no', 'No', 'NO', '0'):
self.assertFalse(gui.toBool(val), 'Failed to convert {} to False'.format(val))

View File

@ -230,7 +230,7 @@ class RegexLdap(auths.Authenticator):
self._host = values['host']
self._port = values['port']
self._ssl = gui.strToBool(values['ssl'])
self._ssl = gui.toBool(values['ssl'])
self._username = values['username']
self._password = values['password']
self._timeout = values['timeout']
@ -317,7 +317,7 @@ class RegexLdap(auths.Authenticator):
return {
'host': self._host,
'port': self._port,
'ssl': gui.boolToStr(self._ssl),
'ssl': gui.fromBool(self._ssl),
'username': self._username,
'password': self._password,
'timeout': self._timeout,
@ -336,7 +336,7 @@ class RegexLdap(auths.Authenticator):
'v4',
self._host,
self._port,
gui.boolToStr(self._ssl),
gui.fromBool(self._ssl),
self._username,
self._password,
self._timeout,
@ -368,7 +368,7 @@ class RegexLdap(auths.Authenticator):
_regex,
self._userNameAttr,
) = vals[1:]
self._ssl = gui.strToBool(ssl)
self._ssl = gui.toBool(ssl)
self._groupNameAttr = self._groupNameAttr + '=' + _regex
self._userNameAttr = '\n'.join(self._userNameAttr.split(','))
elif vals[0] == 'v2':
@ -386,7 +386,7 @@ class RegexLdap(auths.Authenticator):
self._groupNameAttr,
self._userNameAttr,
) = vals[1:]
self._ssl = gui.strToBool(ssl)
self._ssl = gui.toBool(ssl)
elif vals[0] == 'v3':
logger.debug("Data v3: %s", vals[1:])
(
@ -403,7 +403,7 @@ class RegexLdap(auths.Authenticator):
self._userNameAttr,
self._altClass,
) = vals[1:]
self._ssl = gui.strToBool(ssl)
self._ssl = gui.toBool(ssl)
elif vals[0] == 'v4':
logger.debug("Data v4: %s", vals[1:])
(
@ -421,7 +421,7 @@ class RegexLdap(auths.Authenticator):
self._altClass,
self._mfaAttr,
) = vals[1:]
self._ssl = gui.strToBool(ssl)
self._ssl = gui.toBool(ssl)
def __connection(self) -> typing.Any:
"""

View File

@ -201,7 +201,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
if values:
self._host = values['host']
self._port = values['port']
self._ssl = gui.strToBool(values['ssl'])
self._ssl = gui.toBool(values['ssl'])
self._username = values['username']
self._password = values['password']
self._timeout = values['timeout']
@ -219,7 +219,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
return {
'host': self._host,
'port': self._port,
'ssl': gui.boolToStr(self._ssl),
'ssl': gui.fromBool(self._ssl),
'username': self._username,
'password': self._password,
'timeout': self._timeout,
@ -238,7 +238,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
'v1',
self._host,
self._port,
gui.boolToStr(self._ssl),
gui.fromBool(self._ssl),
self._username,
self._password,
self._timeout,
@ -271,7 +271,7 @@ class SimpleLDAPAuthenticator(auths.Authenticator):
self._memberAttr,
self._userNameAttr,
) = vals[1:]
self._ssl = gui.strToBool(ssl)
self._ssl = gui.toBool(ssl)
def __connection(
self,

View File

@ -28,7 +28,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""
.. moduleauthor:: Adolfo Gómez, dkmaster at dkmon dot com
Author: Adolfo Gómez, dkmaster at dkmon dot com
"""
import base64

View File

@ -242,7 +242,7 @@ class gui:
return sorted(choices, key=lambda item: item['text'].lower())
@staticmethod
def strToBool(str_: typing.Union[str, bytes, bool]) -> bool:
def toBool(value: typing.Union[str, bool, int]) -> bool:
"""
Converts the string "true" (case insensitive) to True (boolean).
Anything else is converted to false
@ -253,14 +253,12 @@ class gui:
Returns:
True if the string is "true" (case insensitive), False else.
"""
if isinstance(str_, bool):
return str_
if str(str_).lower() == gui.TRUE:
if value is True or str(value).lower() in [gui.TRUE, '1', 'yes']:
return True
return False
@staticmethod
def boolToStr(bol: bool) -> str:
def fromBool(bol: bool) -> str:
"""
Converts a boolean to the string representation. True is converted to
"true", False to "false".

View File

@ -103,7 +103,7 @@ class LinuxOsManager(osmanagers.OSManager):
if values is not None:
self._onLogout = values['onLogout']
self._idle = int(values['idle'])
self._deadLine = gui.strToBool(values['deadLine'])
self._deadLine = gui.toBool(values['deadLine'])
else:
self._onLogout = ''
self._idle = -1
@ -190,7 +190,7 @@ class LinuxOsManager(osmanagers.OSManager):
Serializes the os manager data so we can store it in database
"""
return '\t'.join(
['v3', self._onLogout, str(self._idle), gui.boolToStr(self._deadLine)]
['v3', self._onLogout, str(self._idle), gui.fromBool(self._deadLine)]
).encode('utf8')
def unmarshal(self, data: bytes):
@ -205,7 +205,7 @@ class LinuxOsManager(osmanagers.OSManager):
self._onLogout, self._idle, self._deadLine = (
values[1],
int(values[2]),
gui.strToBool(values[3]),
gui.toBool(values[3]),
)
self.__setProcessUnusedMachines()
@ -214,5 +214,5 @@ class LinuxOsManager(osmanagers.OSManager):
return {
'onLogout': self._onLogout,
'idle': str(self._idle),
'deadLine': gui.boolToStr(self._deadLine),
'deadLine': gui.fromBool(self._deadLine),
}

View File

@ -112,7 +112,7 @@ class WindowsOsManager(osmanagers.OSManager):
if values is not None:
self._onLogout = values['onLogout']
self._idle = int(values['idle'])
self._deadLine = gui.strToBool(values['deadLine'])
self._deadLine = gui.toBool(values['deadLine'])
else:
self._onLogout = ''
self._idle = -1
@ -222,7 +222,7 @@ class WindowsOsManager(osmanagers.OSManager):
Serializes the os manager data so we can store it in database
"""
return '\t'.join(
['v3', self._onLogout, str(self._idle), gui.boolToStr(self._deadLine)]
['v3', self._onLogout, str(self._idle), gui.fromBool(self._deadLine)]
).encode('utf8')
def unmarshal(self, data: bytes) -> None:
@ -238,7 +238,7 @@ class WindowsOsManager(osmanagers.OSManager):
self._onLogout, self._idle, self._deadLine = (
vals[1],
int(vals[2]),
gui.strToBool(vals[3]),
gui.toBool(vals[3]),
)
except Exception:
logger.exception(
@ -251,5 +251,5 @@ class WindowsOsManager(osmanagers.OSManager):
return {
'onLogout': self._onLogout,
'idle': str(self._idle),
'deadLine': gui.boolToStr(self._deadLine),
'deadLine': gui.fromBool(self._deadLine),
}

View File

@ -190,7 +190,7 @@ class IPMachinesService(IPServiceBase):
'port': str(self._port),
'skipTimeOnFailure': str(self._skipTimeOnFailure),
'maxSessionForMachine': str(self._maxSessionForMachine),
'lockByExternalAccess': gui.boolToStr(self._lockByExternalAccess),
'lockByExternalAccess': gui.fromBool(self._lockByExternalAccess),
}
def marshal(self) -> bytes:
@ -202,7 +202,7 @@ class IPMachinesService(IPServiceBase):
str(self._port).encode(),
str(self._skipTimeOnFailure).encode(),
str(self._maxSessionForMachine).encode(),
gui.boolToStr(self._lockByExternalAccess).encode(),
gui.fromBool(self._lockByExternalAccess).encode(),
]
)
@ -225,7 +225,7 @@ class IPMachinesService(IPServiceBase):
if values[0] in (b'v5', b'v6'):
self._maxSessionForMachine = int(values[4].decode())
if values[0] in (b'v6',):
self._lockByExternalAccess = gui.strToBool(values[5].decode())
self._lockByExternalAccess = gui.toBool(values[5].decode())
# Sets maximum services for this
self.maxDeployed = len(self._ips)