cornflow 1.2.1__py3-none-any.whl → 1.2.3a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cornflow/app.py +3 -1
- cornflow/cli/__init__.py +4 -0
- cornflow/cli/actions.py +4 -0
- cornflow/cli/config.py +4 -0
- cornflow/cli/migrations.py +13 -8
- cornflow/cli/permissions.py +4 -0
- cornflow/cli/roles.py +4 -0
- cornflow/cli/schemas.py +5 -0
- cornflow/cli/service.py +235 -131
- cornflow/cli/tools/api_generator.py +13 -10
- cornflow/cli/tools/endpoint_tools.py +191 -196
- cornflow/cli/tools/models_tools.py +87 -60
- cornflow/cli/tools/schema_generator.py +161 -67
- cornflow/cli/tools/schemas_tools.py +4 -5
- cornflow/cli/users.py +8 -0
- cornflow/cli/views.py +4 -0
- cornflow/commands/dag.py +3 -2
- cornflow/commands/permissions.py +3 -3
- cornflow/commands/schemas.py +6 -4
- cornflow/commands/users.py +12 -17
- cornflow/endpoints/dag.py +27 -25
- cornflow/endpoints/data_check.py +128 -165
- cornflow/endpoints/example_data.py +9 -3
- cornflow/endpoints/execution.py +40 -34
- cornflow/endpoints/health.py +7 -7
- cornflow/endpoints/instance.py +39 -12
- cornflow/endpoints/meta_resource.py +4 -5
- cornflow/schemas/execution.py +9 -1
- cornflow/schemas/health.py +1 -0
- cornflow/shared/authentication/auth.py +73 -42
- cornflow/shared/const.py +10 -1
- cornflow/shared/exceptions.py +3 -1
- cornflow/shared/utils_tables.py +36 -8
- cornflow/shared/validators.py +1 -1
- cornflow/tests/const.py +1 -0
- cornflow/tests/custom_test_case.py +4 -4
- cornflow/tests/unit/test_alarms.py +1 -2
- cornflow/tests/unit/test_cases.py +4 -7
- cornflow/tests/unit/test_commands.py +90 -0
- cornflow/tests/unit/test_executions.py +22 -1
- cornflow/tests/unit/test_health.py +4 -1
- cornflow/tests/unit/test_log_in.py +46 -9
- cornflow/tests/unit/test_tables.py +3 -3
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/METADATA +1 -1
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/RECORD +48 -48
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/WHEEL +1 -1
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/entry_points.txt +0 -0
- {cornflow-1.2.1.dist-info → cornflow-1.2.3a1.dist-info}/top_level.txt +0 -0
cornflow/shared/utils_tables.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
import inspect
|
3
3
|
import os
|
4
4
|
import sys
|
5
|
+
import collections
|
5
6
|
|
6
7
|
from importlib import import_module
|
7
8
|
from sqlalchemy.dialects.postgresql import TEXT
|
@@ -31,14 +32,42 @@ def import_models():
|
|
31
32
|
|
32
33
|
|
33
34
|
def all_subclasses(cls, models=None):
|
34
|
-
subclasses
|
35
|
+
"""Finds all direct and indirect subclasses of a given class.
|
36
|
+
|
37
|
+
Optionally filters a provided list of models first.
|
38
|
+
|
39
|
+
Args:
|
40
|
+
cls: The base class to find subclasses for.
|
41
|
+
models: An optional iterable of classes to pre-filter.
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
A set containing all subclasses found.
|
45
|
+
"""
|
46
|
+
filtered_subclasses = set()
|
35
47
|
if models is not None:
|
36
48
|
for val in models:
|
37
|
-
|
38
|
-
|
49
|
+
# Ensure val is a class before checking issubclass
|
50
|
+
if isinstance(val, type) and issubclass(val, cls):
|
51
|
+
filtered_subclasses.add(val)
|
52
|
+
|
53
|
+
all_descendants = set()
|
54
|
+
# Use a deque for efficient pop(0)
|
55
|
+
queue = collections.deque(cls.__subclasses__())
|
56
|
+
# Keep track of visited classes during the traversal to handle potential complex hierarchies
|
57
|
+
# (though direct subclass relationships shouldn't form cycles)
|
58
|
+
# Initialize with direct subclasses as they are the starting point.
|
59
|
+
visited_for_queue = set(cls.__subclasses__())
|
60
|
+
|
61
|
+
while queue:
|
62
|
+
current_sub = queue.popleft()
|
63
|
+
all_descendants.add(current_sub)
|
64
|
+
|
65
|
+
for grandchild in current_sub.__subclasses__():
|
66
|
+
if grandchild not in visited_for_queue:
|
67
|
+
visited_for_queue.add(grandchild)
|
68
|
+
queue.append(grandchild)
|
39
69
|
|
40
|
-
return
|
41
|
-
[s for c in cls.__subclasses__() for s in all_subclasses(c)]))
|
70
|
+
return filtered_subclasses.union(all_descendants)
|
42
71
|
|
43
72
|
|
44
73
|
type_converter = {
|
@@ -76,6 +105,5 @@ def item_as_dict(item):
|
|
76
105
|
|
77
106
|
def items_as_dict_list(ls):
|
78
107
|
return [
|
79
|
-
{c.name: getattr(item, c.name) for c in item.__table__.columns}
|
80
|
-
|
81
|
-
]
|
108
|
+
{c.name: getattr(item, c.name) for c in item.__table__.columns} for item in ls
|
109
|
+
]
|
cornflow/shared/validators.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
"""
|
2
2
|
This file has several validators
|
3
3
|
"""
|
4
|
+
|
4
5
|
import re
|
5
6
|
from typing import Tuple, Union
|
6
7
|
|
7
8
|
from jsonschema import Draft7Validator, validators
|
8
9
|
from disposable_email_domains import blocklist
|
9
|
-
from jsonschema.protocols import Validator
|
10
10
|
|
11
11
|
|
12
12
|
def is_special_character(character):
|
cornflow/tests/const.py
CHANGED
@@ -17,6 +17,7 @@ INSTANCE_GC_20 = _get_file("./data/gc_20_7.json")
|
|
17
17
|
INSTANCE_FILE_FAIL = _get_file("./unit/test_instances.py")
|
18
18
|
|
19
19
|
EXECUTION_PATH = _get_file("./data/new_execution.json")
|
20
|
+
CUSTOM_CONFIG_PATH = _get_file("./data/new_execution_custom_config.json")
|
20
21
|
BAD_EXECUTION_PATH = _get_file("./data/bad_execution.json")
|
21
22
|
EXECUTION_SOLUTION_PATH = _get_file("./data/new_execution_solution.json")
|
22
23
|
EXECUTIONS_LIST = [EXECUTION_PATH, _get_file("./data/new_execution_2.json")]
|
@@ -635,9 +635,9 @@ class BaseTestCases:
|
|
635
635
|
# (we patch the request to airflow to check if the schema is valid)
|
636
636
|
# we create 4 instances
|
637
637
|
data_many = [self.payload for _ in range(4)]
|
638
|
-
|
639
|
-
|
640
|
-
self.apply_filter(self.url, dict(schema="timer"),
|
638
|
+
|
639
|
+
self.get_rows(self.url, data_many)
|
640
|
+
self.apply_filter(self.url, dict(schema="timer"), [])
|
641
641
|
|
642
642
|
def test_opt_filters_date_lte(self):
|
643
643
|
"""
|
@@ -1117,7 +1117,7 @@ class LoginTestCases:
|
|
1117
1117
|
|
1118
1118
|
self.assertEqual(400, response.status_code)
|
1119
1119
|
self.assertEqual(
|
1120
|
-
"Invalid token
|
1120
|
+
"Invalid token format or signature",
|
1121
1121
|
response.json["error"],
|
1122
1122
|
)
|
1123
1123
|
|
@@ -91,7 +91,6 @@ class TestAlarmsEndpoint(CustomTestCase):
|
|
91
91
|
class TestAlarmsDetailEndpoint(TestAlarmsEndpoint, BaseTestCases.DetailEndpoint):
|
92
92
|
def setUp(self):
|
93
93
|
super().setUp()
|
94
|
-
self.url = self.url
|
95
94
|
self.idx = 0
|
96
95
|
self.payload = {
|
97
96
|
"name": "Alarm 1",
|
@@ -138,4 +137,4 @@ class TestAlarmsDetailEndpoint(TestAlarmsEndpoint, BaseTestCases.DetailEndpoint)
|
|
138
137
|
# We check deleted at has a value
|
139
138
|
self.assertIsNotNone(row.deleted_at)
|
140
139
|
else:
|
141
|
-
self.assertIsNone(row.deleted_at)
|
140
|
+
self.assertIsNone(row.deleted_at)
|
@@ -42,6 +42,7 @@ import zlib
|
|
42
42
|
|
43
43
|
# Import from internal modules
|
44
44
|
from cornflow.models import CaseModel, ExecutionModel, InstanceModel, UserModel
|
45
|
+
from cornflow.shared.const import DATA_DOES_NOT_EXIST_MSG
|
45
46
|
from cornflow.shared.utils import hash_json_256
|
46
47
|
from cornflow.tests.const import (
|
47
48
|
INSTANCE_URL,
|
@@ -227,12 +228,8 @@ class TestCasesFromInstanceExecutionEndpoint(CustomTestCase):
|
|
227
228
|
"execution_id": execution_id,
|
228
229
|
"schema": "solve_model_dag",
|
229
230
|
}
|
230
|
-
self.instance = InstanceModel.get_one_object(
|
231
|
-
|
232
|
-
)
|
233
|
-
self.execution = ExecutionModel.get_one_object(
|
234
|
-
user=self.user, idx=execution_id
|
235
|
-
)
|
231
|
+
self.instance = InstanceModel.get_one_object(user=self.user, idx=instance_id)
|
232
|
+
self.execution = ExecutionModel.get_one_object(user=self.user, idx=execution_id)
|
236
233
|
|
237
234
|
def test_new_case_execution(self):
|
238
235
|
"""
|
@@ -729,7 +726,7 @@ class TestCaseToInstanceEndpoint(CustomTestCase):
|
|
729
726
|
headers=self.get_header_with_auth(self.token),
|
730
727
|
)
|
731
728
|
self.assertEqual(response.status_code, 404)
|
732
|
-
self.assertEqual(response.json["error"],
|
729
|
+
self.assertEqual(response.json["error"], DATA_DOES_NOT_EXIST_MSG)
|
733
730
|
|
734
731
|
|
735
732
|
class TestCaseJsonPatch(CustomTestCase):
|
@@ -29,6 +29,7 @@ from cornflow.app import (
|
|
29
29
|
register_dag_permissions,
|
30
30
|
register_roles,
|
31
31
|
register_views,
|
32
|
+
register_base_assignations,
|
32
33
|
)
|
33
34
|
from cornflow.commands.dag import register_deployed_dags_command_test
|
34
35
|
from cornflow.endpoints import resources, alarms_resources
|
@@ -494,3 +495,92 @@ class TestCommands(TestCase):
|
|
494
495
|
},
|
495
496
|
)
|
496
497
|
self.assertEqual(403, response.status_code)
|
498
|
+
|
499
|
+
def test_permissions_not_deleted_when_roles_removed_from_code(self):
|
500
|
+
"""
|
501
|
+
Test that permissions are NOT deleted when roles are removed from ROLES_WITH_ACCESS.
|
502
|
+
|
503
|
+
This test demonstrates the current bug: when a role is removed from
|
504
|
+
ROLES_WITH_ACCESS in an endpoint's code, the corresponding permissions
|
505
|
+
in the database are not automatically deleted. This happens because
|
506
|
+
the deletion logic in register_base_permissions_command is commented out.
|
507
|
+
|
508
|
+
The test should currently FAIL to demonstrate the bug exists.
|
509
|
+
"""
|
510
|
+
# First, initialize the access system normally
|
511
|
+
self.runner.invoke(access_init)
|
512
|
+
|
513
|
+
# Get the original ROLES_WITH_ACCESS for ExampleDataListEndpoint
|
514
|
+
from cornflow.endpoints.example_data import ExampleDataListEndpoint
|
515
|
+
|
516
|
+
original_roles = ExampleDataListEndpoint.ROLES_WITH_ACCESS.copy()
|
517
|
+
|
518
|
+
# Verify initial permissions are created for all three roles
|
519
|
+
# Get the view ID for the endpoint
|
520
|
+
from cornflow.models import ViewModel
|
521
|
+
|
522
|
+
view = ViewModel.query.filter_by(name="example-data").first()
|
523
|
+
self.assertIsNotNone(view, "example-data view should exist")
|
524
|
+
|
525
|
+
# Check permissions exist for all original roles
|
526
|
+
from cornflow.shared.const import ACTIONS_MAP
|
527
|
+
from cornflow.models import PermissionViewRoleModel
|
528
|
+
|
529
|
+
# Check GET action permissions (action_id=1 is typically GET)
|
530
|
+
get_action_id = 1
|
531
|
+
initial_permissions = PermissionViewRoleModel.query.filter_by(
|
532
|
+
api_view_id=view.id, action_id=get_action_id
|
533
|
+
).all()
|
534
|
+
|
535
|
+
initial_role_ids = [perm.role_id for perm in initial_permissions]
|
536
|
+
self.assertEqual(
|
537
|
+
len(original_roles),
|
538
|
+
len(initial_permissions),
|
539
|
+
f"Should have permissions for all {len(original_roles)} original roles",
|
540
|
+
)
|
541
|
+
|
542
|
+
# Now simulate removing PLANNER_ROLE from ROLES_WITH_ACCESS
|
543
|
+
from cornflow.shared.const import PLANNER_ROLE, VIEWER_ROLE, ADMIN_ROLE
|
544
|
+
|
545
|
+
modified_roles = [VIEWER_ROLE, ADMIN_ROLE] # Remove PLANNER_ROLE
|
546
|
+
|
547
|
+
# Temporarily modify the ROLES_WITH_ACCESS
|
548
|
+
ExampleDataListEndpoint.ROLES_WITH_ACCESS = modified_roles
|
549
|
+
|
550
|
+
try:
|
551
|
+
|
552
|
+
# Run the permission registration again
|
553
|
+
# (this simulates redeploying the app with modified roles)
|
554
|
+
self.runner.invoke(register_base_assignations, ["-v"])
|
555
|
+
|
556
|
+
# Check permissions after the "code change"
|
557
|
+
updated_permissions = PermissionViewRoleModel.query.filter_by(
|
558
|
+
api_view_id=view.id, action_id=get_action_id
|
559
|
+
).all()
|
560
|
+
|
561
|
+
updated_role_ids = [perm.role_id for perm in updated_permissions]
|
562
|
+
|
563
|
+
# THIS IS THE BUG: The permission for PLANNER_ROLE should be deleted
|
564
|
+
# but it's not because the deletion logic is commented out
|
565
|
+
# So we expect this assertion to FAIL, demonstrating the bug
|
566
|
+
self.assertEqual(
|
567
|
+
len(modified_roles),
|
568
|
+
len(updated_permissions),
|
569
|
+
f"After removing PLANNER_ROLE from code, should only have {len(modified_roles)} permissions, "
|
570
|
+
f"but still has {len(updated_permissions)} permissions. "
|
571
|
+
f"This demonstrates the bug: permissions are not deleted when roles are removed from ROLES_WITH_ACCESS.",
|
572
|
+
)
|
573
|
+
|
574
|
+
# Also check that PLANNER_ROLE permission was actually removed
|
575
|
+
planner_permissions = [
|
576
|
+
perm for perm in updated_permissions if perm.role_id == PLANNER_ROLE
|
577
|
+
]
|
578
|
+
self.assertEqual(
|
579
|
+
0,
|
580
|
+
len(planner_permissions),
|
581
|
+
"PLANNER_ROLE permission should have been deleted but still exists",
|
582
|
+
)
|
583
|
+
|
584
|
+
finally:
|
585
|
+
# Restore original ROLES_WITH_ACCESS to avoid affecting other tests
|
586
|
+
ExampleDataListEndpoint.ROLES_WITH_ACCESS = original_roles
|
@@ -18,6 +18,7 @@ from cornflow.tests.const import (
|
|
18
18
|
DAG_URL,
|
19
19
|
BAD_EXECUTION_PATH,
|
20
20
|
EXECUTION_SOLUTION_PATH,
|
21
|
+
CUSTOM_CONFIG_PATH,
|
21
22
|
)
|
22
23
|
from cornflow.tests.custom_test_case import CustomTestCase, BaseTestCases
|
23
24
|
from cornflow.tests.unit.tools import patch_af_client
|
@@ -43,6 +44,7 @@ class TestExecutionsListEndpoint(BaseTestCases.ListFilters):
|
|
43
44
|
self.bad_payload = load_file_fk(BAD_EXECUTION_PATH)
|
44
45
|
self.payloads = [load_file_fk(f) for f in EXECUTIONS_LIST]
|
45
46
|
self.solution = load_file_fk(EXECUTION_SOLUTION_PATH)
|
47
|
+
self.custom_config_payload = load_file_fk(CUSTOM_CONFIG_PATH)
|
46
48
|
self.keys_to_check = [
|
47
49
|
"data_hash",
|
48
50
|
"created_at",
|
@@ -57,11 +59,25 @@ class TestExecutionsListEndpoint(BaseTestCases.ListFilters):
|
|
57
59
|
"instance_id",
|
58
60
|
"name",
|
59
61
|
"indicators",
|
62
|
+
"username",
|
63
|
+
"updated_at"
|
60
64
|
]
|
61
65
|
|
62
66
|
def test_new_execution(self):
|
63
67
|
self.create_new_row(self.url, self.model, payload=self.payload)
|
64
68
|
|
69
|
+
def test_get_custom_config(self):
|
70
|
+
id = self.create_new_row(
|
71
|
+
self.url, self.model, payload=self.custom_config_payload
|
72
|
+
)
|
73
|
+
url = EXECUTION_URL + "/" + str(id) + "/" + "?run=0"
|
74
|
+
|
75
|
+
response = self.get_one_row(
|
76
|
+
url,
|
77
|
+
payload={**self.custom_config_payload, **dict(id=id)},
|
78
|
+
)
|
79
|
+
self.assertEqual(response["config"]["block_model"]["solver"], "mip.gurobi")
|
80
|
+
|
65
81
|
@patch("cornflow.endpoints.execution.Airflow")
|
66
82
|
def test_new_execution_run(self, af_client_class):
|
67
83
|
patch_af_client(af_client_class)
|
@@ -260,6 +276,8 @@ class TestExecutionsDetailEndpointMock(CustomTestCase):
|
|
260
276
|
"schema",
|
261
277
|
"user_id",
|
262
278
|
"indicators",
|
279
|
+
"username",
|
280
|
+
"updated_at"
|
263
281
|
}
|
264
282
|
# we only check the following because this endpoint does not return data
|
265
283
|
self.items_to_check = ["name", "description"]
|
@@ -274,7 +292,6 @@ class TestExecutionsDetailEndpoint(
|
|
274
292
|
):
|
275
293
|
def setUp(self):
|
276
294
|
super().setUp()
|
277
|
-
self.url = self.url
|
278
295
|
self.query_arguments = {"run": 0}
|
279
296
|
|
280
297
|
# TODO: this test should be moved as it is not using the detail endpoint
|
@@ -303,6 +320,8 @@ class TestExecutionsDetailEndpoint(
|
|
303
320
|
"name",
|
304
321
|
"created_at",
|
305
322
|
"state",
|
323
|
+
"username",
|
324
|
+
"updated_at"
|
306
325
|
]
|
307
326
|
execution = self.get_one_row(
|
308
327
|
self.url + idx,
|
@@ -450,6 +469,8 @@ class TestExecutionsLogEndpoint(TestExecutionsDetailEndpointMock):
|
|
450
469
|
"user_id",
|
451
470
|
"config",
|
452
471
|
"indicators",
|
472
|
+
"username",
|
473
|
+
"updated_at"
|
453
474
|
]
|
454
475
|
|
455
476
|
def test_get_one_execution(self):
|
@@ -4,7 +4,7 @@ from cornflow.shared import db
|
|
4
4
|
|
5
5
|
from cornflow.app import create_app
|
6
6
|
from cornflow.commands import access_init_command
|
7
|
-
from cornflow.shared.const import STATUS_HEALTHY
|
7
|
+
from cornflow.shared.const import STATUS_HEALTHY, CORNFLOW_VERSION
|
8
8
|
from cornflow.tests.const import HEALTH_URL
|
9
9
|
from cornflow.tests.custom_test_case import CustomTestCase
|
10
10
|
|
@@ -29,6 +29,9 @@ class TestHealth(CustomTestCase):
|
|
29
29
|
self.assertEqual(200, response.status_code)
|
30
30
|
cf_status = response.json["cornflow_status"]
|
31
31
|
af_status = response.json["airflow_status"]
|
32
|
+
cf_version = response.json["cornflow_version"]
|
33
|
+
expected_version = CORNFLOW_VERSION
|
32
34
|
self.assertEqual(str, type(cf_status))
|
33
35
|
self.assertEqual(str, type(af_status))
|
34
36
|
self.assertEqual(cf_status, STATUS_HEALTHY)
|
37
|
+
self.assertEqual(cf_version, expected_version)
|
@@ -135,11 +135,20 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
135
135
|
Tests token validation failure when the kid is not found in public keys
|
136
136
|
"""
|
137
137
|
# Import the real exceptions to ensure they are preserved
|
138
|
-
from jwt.exceptions import
|
138
|
+
from jwt.exceptions import (
|
139
|
+
InvalidTokenError,
|
140
|
+
ExpiredSignatureError,
|
141
|
+
InvalidIssuerError,
|
142
|
+
InvalidSignatureError,
|
143
|
+
DecodeError,
|
144
|
+
)
|
139
145
|
|
140
146
|
# Keep the real exception classes in the mock
|
141
147
|
mock_jwt.ExpiredSignatureError = ExpiredSignatureError
|
142
148
|
mock_jwt.InvalidTokenError = InvalidTokenError
|
149
|
+
mock_jwt.InvalidIssuerError = InvalidIssuerError
|
150
|
+
mock_jwt.InvalidSignatureError = InvalidSignatureError
|
151
|
+
mock_jwt.DecodeError = DecodeError
|
143
152
|
|
144
153
|
mock_jwt.get_unverified_header.return_value = {"kid": "test_kid"}
|
145
154
|
|
@@ -165,7 +174,7 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
165
174
|
|
166
175
|
self.assertEqual(400, response.status_code)
|
167
176
|
self.assertEqual(
|
168
|
-
response.json["error"], "Invalid token
|
177
|
+
response.json["error"], "Invalid token format, signature, or configuration"
|
169
178
|
)
|
170
179
|
|
171
180
|
@mock.patch("cornflow.shared.authentication.auth.jwt")
|
@@ -174,11 +183,20 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
174
183
|
Tests token validation failure when the token header is missing the kid
|
175
184
|
"""
|
176
185
|
# Import the real exceptions to ensure they are preserved
|
177
|
-
from jwt.exceptions import
|
186
|
+
from jwt.exceptions import (
|
187
|
+
InvalidTokenError,
|
188
|
+
ExpiredSignatureError,
|
189
|
+
InvalidIssuerError,
|
190
|
+
InvalidSignatureError,
|
191
|
+
DecodeError,
|
192
|
+
)
|
178
193
|
|
179
194
|
# Keep the real exception classes in the mock
|
180
195
|
mock_jwt.ExpiredSignatureError = ExpiredSignatureError
|
181
196
|
mock_jwt.InvalidTokenError = InvalidTokenError
|
197
|
+
mock_jwt.InvalidIssuerError = InvalidIssuerError
|
198
|
+
mock_jwt.InvalidSignatureError = InvalidSignatureError
|
199
|
+
mock_jwt.DecodeError = DecodeError
|
182
200
|
|
183
201
|
# Mock jwt.get_unverified_header to return a header without kid
|
184
202
|
mock_jwt.get_unverified_header.return_value = {"alg": "RS256"}
|
@@ -194,8 +212,7 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
194
212
|
|
195
213
|
self.assertEqual(400, response.status_code)
|
196
214
|
self.assertEqual(
|
197
|
-
response.json["error"]
|
198
|
-
"Invalid token: Missing key identifier (kid) in token header",
|
215
|
+
"Invalid token format, signature, or configuration", response.json["error"]
|
199
216
|
)
|
200
217
|
|
201
218
|
@mock.patch("cornflow.shared.authentication.auth.requests.get")
|
@@ -205,11 +222,20 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
205
222
|
Tests failure when trying to fetch public keys from the OIDC provider
|
206
223
|
"""
|
207
224
|
# Import the real exceptions to ensure they are preserved
|
208
|
-
from jwt.exceptions import
|
225
|
+
from jwt.exceptions import (
|
226
|
+
InvalidTokenError,
|
227
|
+
ExpiredSignatureError,
|
228
|
+
InvalidIssuerError,
|
229
|
+
InvalidSignatureError,
|
230
|
+
DecodeError,
|
231
|
+
)
|
209
232
|
|
210
233
|
# Keep the real exception classes in the mock
|
211
234
|
mock_jwt.ExpiredSignatureError = ExpiredSignatureError
|
212
235
|
mock_jwt.InvalidTokenError = InvalidTokenError
|
236
|
+
mock_jwt.InvalidIssuerError = InvalidIssuerError
|
237
|
+
mock_jwt.InvalidSignatureError = InvalidSignatureError
|
238
|
+
mock_jwt.DecodeError = DecodeError
|
213
239
|
|
214
240
|
# Clear the cache
|
215
241
|
from cornflow.shared.authentication.auth import public_keys_cache
|
@@ -240,8 +266,8 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
240
266
|
|
241
267
|
self.assertEqual(400, response.status_code)
|
242
268
|
self.assertEqual(
|
269
|
+
"Invalid token format, signature, or configuration",
|
243
270
|
response.json["error"],
|
244
|
-
"Failed to fetch public keys from authentication provider",
|
245
271
|
)
|
246
272
|
|
247
273
|
@mock.patch("cornflow.shared.authentication.Auth.decode_token")
|
@@ -289,11 +315,20 @@ class TestLogInOpenAuth(CustomTestCase):
|
|
289
315
|
the system fetches fresh keys from the provider.
|
290
316
|
"""
|
291
317
|
# Import the real exceptions to ensure they are preserved
|
292
|
-
from jwt.exceptions import
|
318
|
+
from jwt.exceptions import (
|
319
|
+
InvalidTokenError,
|
320
|
+
ExpiredSignatureError,
|
321
|
+
InvalidIssuerError,
|
322
|
+
InvalidSignatureError,
|
323
|
+
DecodeError,
|
324
|
+
)
|
293
325
|
|
294
326
|
# Keep the real exception classes in the mock
|
295
327
|
mock_jwt.ExpiredSignatureError = ExpiredSignatureError
|
296
328
|
mock_jwt.InvalidTokenError = InvalidTokenError
|
329
|
+
mock_jwt.InvalidIssuerError = InvalidIssuerError
|
330
|
+
mock_jwt.InvalidSignatureError = InvalidSignatureError
|
331
|
+
mock_jwt.DecodeError = DecodeError
|
297
332
|
|
298
333
|
# Mock jwt to return valid unverified header and payload
|
299
334
|
mock_jwt.get_unverified_header.return_value = {"kid": "test_kid"}
|
@@ -531,4 +566,6 @@ class TestLogInOpenAuthService(CustomTestCase):
|
|
531
566
|
)
|
532
567
|
|
533
568
|
self.assertEqual(400, response.status_code)
|
534
|
-
self.assertEqual(
|
569
|
+
self.assertEqual(
|
570
|
+
response.json["error"], "Invalid token format, signature, or configuration"
|
571
|
+
)
|
@@ -11,7 +11,7 @@ from cornflow.app import create_app
|
|
11
11
|
from cornflow.commands.access import access_init_command
|
12
12
|
from cornflow.models import UserRoleModel
|
13
13
|
from cornflow.shared import db
|
14
|
-
from cornflow.shared.const import ADMIN_ROLE, SERVICE_ROLE
|
14
|
+
from cornflow.shared.const import ADMIN_ROLE, SERVICE_ROLE, DATA_DOES_NOT_EXIST_MSG
|
15
15
|
from cornflow.tests.const import LOGIN_URL, SIGNUP_URL, TABLES_URL
|
16
16
|
|
17
17
|
|
@@ -220,7 +220,7 @@ class TestTablesDetailEndpoint(TestCase):
|
|
220
220
|
},
|
221
221
|
)
|
222
222
|
self.assertEqual(response.status_code, 404)
|
223
|
-
self.assertEqual(response.json["error"],
|
223
|
+
self.assertEqual(response.json["error"], DATA_DOES_NOT_EXIST_MSG)
|
224
224
|
|
225
225
|
|
226
226
|
class TestTablesEndpointAdmin(TestCase):
|
@@ -291,4 +291,4 @@ class TestTablesEndpointAdmin(TestCase):
|
|
291
291
|
self.assertEqual(response.status_code, 403)
|
292
292
|
self.assertEqual(
|
293
293
|
response.json["error"], "You do not have permission to access this endpoint"
|
294
|
-
)
|
294
|
+
)
|