Skip to content

Commit

Permalink
fixes some tests for auth, fixes the recursive property lookup, fixes…
Browse files Browse the repository at this point in the history
… the replacement of alert variables
  • Loading branch information
sadnub committed May 14, 2024
1 parent ab8f8c5 commit 7e380b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions api/tacticalrmm/accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_check_creds(self):
r = self.client.post(url, data, format="json")
self.assertEqual(r.status_code, 200)
self.assertIn("totp", r.data.keys())
self.assertEqual(r.data["totp"], "totp not set")
self.assertEqual(r.data["totp"], False)

data = {"username": "bob", "password": "a3asdsa2314"}
r = self.client.post(url, data, format="json")
Expand All @@ -40,7 +40,7 @@ def test_check_creds(self):
data = {"username": "bob", "password": "hunter2"}
r = self.client.post(url, data, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data, "ok")
self.assertEqual(r.data["totp"], True)

# test user set to block dashboard logins
self.bob.block_dashboard_login = True
Expand Down Expand Up @@ -404,7 +404,7 @@ def test_post_totp_set(self):

r = self.client.post(url)
self.assertEqual(r.status_code, 200)
self.assertEqual(r.data, "totp token already set")
self.assertEqual(r.data, False)


class TestAPIAuthentication(TacticalTestCase):
Expand Down
16 changes: 12 additions & 4 deletions api/tacticalrmm/alerts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ def site(self) -> "Site":
def client(self) -> "Client":
return self.agent.client

@property
def get_result(self):
if self.alert_type == AlertType.CHECK:
return self.assigned_check.checkresults.get(agent=self.agent)
elif self.alert_type == AlertType.TASK:
return self.assigned_task.taskresults.get(agent=self.agent)
else:
return None

def resolve(self) -> None:
self.resolved = True
self.resolved_on = djangotime.now()
Expand Down Expand Up @@ -709,13 +718,12 @@ def parse_script_args(self, args: List[str]) -> List[str]:
temp_args = []

for arg in args:
temp_arg = ""
temp_arg = arg
for string, model, prop in re.findall(RE_DB_VALUE, arg):
value = get_db_value(string=f"{model}.{prop}", instance=self)

temp_arg = temp_arg.replace(string, str(value))
else:
temp_arg = arg
if value != None:
temp_arg = temp_arg.replace(string, str(value))

temp_args.append(temp_arg)

Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/tacticalrmm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def get_latest_trmm_ver() -> str:
# will return 3 groups of matches in a tuple when uses with re.findall
# i.e. - {{client.name}}, client, name
RE_DB_VALUE = re.compile(
r"(\{\{\s*(client|site|agent|global|alert)\.([\w\-\s]+)\s*\}\})"
r"(\{\{\s*(client|site|agent|global|alert)(?:\.([\w\-\s\.]+))+\s*\}\})"
)


Expand Down

0 comments on commit 7e380b3

Please sign in to comment.