only do startswith when it is a string
This commit is contained in:
parent
80c5357b9b
commit
287d10494e
|
@ -27,19 +27,20 @@ class ServiceTaskDelegate:
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
value = json.dumps(value)
|
value = json.dumps(value)
|
||||||
|
|
||||||
secret_prefix = "secret:" # noqa: S105
|
if isinstance(value, str):
|
||||||
if value.startswith(secret_prefix):
|
secret_prefix = "secret:" # noqa: S105
|
||||||
key = value.removeprefix(secret_prefix)
|
if value.startswith(secret_prefix):
|
||||||
secret = SecretService().get_secret(key)
|
key = value.removeprefix(secret_prefix)
|
||||||
assert secret # noqa: S101
|
secret = SecretService().get_secret(key)
|
||||||
return secret.value
|
assert secret # noqa: S101
|
||||||
|
return secret.value
|
||||||
|
|
||||||
file_prefix = "file:"
|
file_prefix = "file:"
|
||||||
if value.startswith(file_prefix):
|
if value.startswith(file_prefix):
|
||||||
file_name = value.removeprefix(file_prefix)
|
file_name = value.removeprefix(file_prefix)
|
||||||
full_path = FileSystemService.full_path_from_relative_path(file_name)
|
full_path = FileSystemService.full_path_from_relative_path(file_name)
|
||||||
with open(full_path) as f:
|
with open(full_path) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
"""Test_various_bpmn_constructs."""
|
||||||
|
from flask.app import Flask
|
||||||
|
from spiffworkflow_backend.services.secret_service import SecretService
|
||||||
|
from spiffworkflow_backend.services.service_task_service import ServiceTaskDelegate
|
||||||
|
from spiffworkflow_backend.services.user_service import UserService
|
||||||
|
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
|
||||||
|
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||||
|
|
||||||
|
from spiffworkflow_backend.services.process_instance_processor import (
|
||||||
|
ProcessInstanceProcessor,
|
||||||
|
)
|
||||||
|
from spiffworkflow_backend.services.process_instance_service import (
|
||||||
|
ProcessInstanceService,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestServiceTaskDelegate(BaseTest):
|
||||||
|
|
||||||
|
def test_normalize_value_without_secret(
|
||||||
|
self, app: Flask, with_db_and_bpmn_file_cleanup: None
|
||||||
|
) -> None:
|
||||||
|
result = ServiceTaskDelegate.normalize_value("hey")
|
||||||
|
assert result == "hey"
|
||||||
|
|
||||||
|
def test_normalize_value_with_int(
|
||||||
|
self, app: Flask, with_db_and_bpmn_file_cleanup: None
|
||||||
|
) -> None:
|
||||||
|
result = ServiceTaskDelegate.normalize_value(1)
|
||||||
|
assert result == 1
|
||||||
|
|
||||||
|
def test_normalize_value_with_secret(
|
||||||
|
self, app: Flask, with_db_and_bpmn_file_cleanup: None
|
||||||
|
) -> None:
|
||||||
|
user = self.find_or_create_user("test_user")
|
||||||
|
SecretService().add_secret("hot_secret", "my_secret_value", user.id)
|
||||||
|
result = ServiceTaskDelegate.normalize_value("secret:hot_secret")
|
||||||
|
assert result == "my_secret_value"
|
Loading…
Reference in New Issue