mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-22 13:34:04 +03:00
Fixed managed and unmanaged actor_v3
This commit is contained in:
parent
974f652df0
commit
dc5cc99afd
2
client
2
client
@ -1 +1 @@
|
|||||||
Subproject commit d340a8075e7692354a1b486fde98d78ba165890b
|
Subproject commit c699725350b09f1f9f3440708b3ed7659e0daa3e
|
@ -389,8 +389,8 @@ class Initialize(ActorV3Action):
|
|||||||
) -> dict[str, typing.Any]:
|
) -> dict[str, typing.Any]:
|
||||||
return ActorV3Action.actorResult(
|
return ActorV3Action.actorResult(
|
||||||
{
|
{
|
||||||
'own_token': alias_token or own_token, # Compat with old actor versions, TBR on 5.0
|
'own_token': own_token or alias_token, # Compat with old actor versions, TBR on 5.0
|
||||||
'token': alias_token or own_token, # New token, will be used from now onwards
|
'token': own_token or alias_token, # New token, will be used from now onwards
|
||||||
'unique_id': unique_id,
|
'unique_id': unique_id,
|
||||||
'os': os,
|
'os': os,
|
||||||
}
|
}
|
||||||
@ -410,6 +410,9 @@ class Initialize(ActorV3Action):
|
|||||||
# Not on alias token, try to locate on Service table
|
# Not on alias token, try to locate on Service table
|
||||||
if not service:
|
if not service:
|
||||||
service = typing.cast('Service', Service.objects.get(token=token))
|
service = typing.cast('Service', Service.objects.get(token=token))
|
||||||
|
# If exists, create and alias for it
|
||||||
|
alias_token = CryptoManager().randomString(40) # fix alias with new token
|
||||||
|
service.aliases.create(alias=alias_token)
|
||||||
|
|
||||||
# Locate an userService that belongs to this service and which
|
# Locate an userService that belongs to this service and which
|
||||||
# Build the possible ids and make initial filter to match service
|
# Build the possible ids and make initial filter to match service
|
||||||
|
@ -110,10 +110,8 @@ class ActorInitializeTest(rest.test.RESTActorTestCase):
|
|||||||
result = success(unique_id)
|
result = success(unique_id)
|
||||||
|
|
||||||
# Ensure own token is assigned
|
# Ensure own token is assigned
|
||||||
self.assertEqual(result['own_token'], user_service.uuid)
|
self.assertEqual(result['token'], user_service.uuid)
|
||||||
|
self.assertEqual(result['own_token'], result['token']) # Compat value with 3.x actors
|
||||||
# Ensure no alias token is provided
|
|
||||||
self.assertIsNone(result['alias_token'])
|
|
||||||
|
|
||||||
# Ensure unique_id detected is ours
|
# Ensure unique_id detected is ours
|
||||||
self.assertEqual(result['unique_id'], unique_id)
|
self.assertEqual(result['unique_id'], unique_id)
|
||||||
@ -133,8 +131,8 @@ class ActorInitializeTest(rest.test.RESTActorTestCase):
|
|||||||
# Now invoke failure with valid token but invalid mac
|
# Now invoke failure with valid token but invalid mac
|
||||||
result = failure(actor_token, 'invalid mac', False)
|
result = failure(actor_token, 'invalid mac', False)
|
||||||
|
|
||||||
self.assertIsNone(result['own_token'], None)
|
self.assertIsNone(result['own_token'])
|
||||||
self.assertIsNone(result['alias_token'])
|
self.assertIsNone(result['token'])
|
||||||
self.assertIsNone(result['os'])
|
self.assertIsNone(result['os'])
|
||||||
self.assertIsNone(result['unique_id'])
|
self.assertIsNone(result['unique_id'])
|
||||||
|
|
||||||
@ -157,10 +155,13 @@ class ActorInitializeTest(rest.test.RESTActorTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Unmanaged host is the response for initialization of unmanaged actor ALWAYS
|
# Unmanaged host is the response for initialization of unmanaged actor ALWAYS
|
||||||
self.assertIsNone(result['alias_token'])
|
self.assertIsInstance(result['token'], str)
|
||||||
self.assertIsNone(result['own_token'])
|
self.assertEqual(result['token'], result['own_token'])
|
||||||
self.assertIsNone(result['unique_id'])
|
self.assertIsNone(result['unique_id'])
|
||||||
self.assertIsNone(result['os'])
|
self.assertIsNone(result['os'])
|
||||||
|
|
||||||
|
# Store alias token for later tests
|
||||||
|
alias_token = result['token']
|
||||||
|
|
||||||
# Now, invoke a "nice" initialize
|
# Now, invoke a "nice" initialize
|
||||||
result = success(
|
result = success(
|
||||||
@ -168,23 +169,23 @@ class ActorInitializeTest(rest.test.RESTActorTestCase):
|
|||||||
mac=unique_id,
|
mac=unique_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
alias_token = result['alias_token']
|
token = result['token']
|
||||||
|
|
||||||
self.assertIsInstance(alias_token, str)
|
self.assertIsInstance(token, str)
|
||||||
self.assertEqual(result['own_token'], user_service.uuid)
|
self.assertEqual(token, user_service.uuid)
|
||||||
self.assertEqual(result['alias_token'], alias_token)
|
self.assertEqual(token, result['own_token'])
|
||||||
self.assertEqual(result['unique_id'], unique_id)
|
self.assertEqual(result['unique_id'], unique_id)
|
||||||
|
|
||||||
# Ensure that the alias returned is on alias db, and it points to the same service as the one we belong to
|
# Ensure that the alias returned is on alias db, and it points to the same service as the one we belong to
|
||||||
alias = models.ServiceTokenAlias.objects.get(alias=result['alias_token'])
|
alias = models.ServiceTokenAlias.objects.get(alias=alias_token)
|
||||||
self.assertEqual(alias.service, user_service.deployed_service.service)
|
self.assertEqual(alias.service, user_service.deployed_service.service)
|
||||||
|
|
||||||
# Now, we should be able to "initialize" with valid mac and with original and alias tokens
|
# Now, we should be able to "initialize" with valid mac and with original and alias tokens
|
||||||
# If we call initialize and we get "own-token" means that we have already logged in with this data
|
# If we call initialize and we get "own-token" means that we have already logged in with this data
|
||||||
result = success(alias_token, mac=unique_id)
|
result = success(alias_token, mac=unique_id)
|
||||||
|
|
||||||
self.assertEqual(result['own_token'], user_service.uuid)
|
self.assertEqual(result['token'], user_service.uuid)
|
||||||
self.assertEqual(result['alias_token'], alias_token)
|
self.assertEqual(result['token'], result['own_token'])
|
||||||
self.assertEqual(result['unique_id'], unique_id)
|
self.assertEqual(result['unique_id'], unique_id)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -52,7 +52,10 @@ class UDSHttpResponse(HttpResponse):
|
|||||||
|
|
||||||
def __init__(self, content, *args, **kwargs):
|
def __init__(self, content, *args, **kwargs):
|
||||||
super().__init__(content, *args, **kwargs)
|
super().__init__(content, *args, **kwargs)
|
||||||
self.content = content
|
self.content = content # type: ignore # mypy does not know about this setter
|
||||||
|
|
||||||
|
def json(self) -> typing.Any:
|
||||||
|
return super().json() # type: ignore # mypy does not know about this method
|
||||||
|
|
||||||
|
|
||||||
class UDSClientMixin:
|
class UDSClientMixin:
|
||||||
|
Loading…
Reference in New Issue
Block a user