Skip to content

Commit 9538a6e

Browse files
authored
Merge pull request #230 from eclecticiq/nest-taxii2-urls
Nest taxii2 endpoints under `/taxii2/`
2 parents e848ee3 + e37dd45 commit 9538a6e

12 files changed

Lines changed: 35 additions & 31 deletions

CHANGES.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
Changelog
22
=========
33

4-
0.6.0 (2022-05-25
4+
0.7.0 (2022-05-27)
5+
------------------
6+
* Nest taxii2 endpoints under `/taxii2/`
7+
8+
0.6.0 (2022-05-25)
59
------------------
610
* Add `public_discovery` option to taxii2 config
711
* Add support for publicly readable taxii 2 api roots

opentaxii/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
This module defines the package version for use in __init__.py and setup.py.
44
"""
55

6-
__version__ = '0.6.0'
6+
__version__ = '0.7.0'

opentaxii/server.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,11 @@ def discovery_handler(self):
480480
response[key] = self.config.get(key)
481481
default_api_root, api_roots = self.persistence.get_api_roots()
482482
if default_api_root:
483-
response["default"] = f"/{default_api_root.id}/"
484-
response["api_roots"] = [f"/{api_root.id}/" for api_root in api_roots]
483+
response["default"] = f"/taxii2/{default_api_root.id}/"
484+
response["api_roots"] = [f"/taxii2/{api_root.id}/" for api_root in api_roots]
485485
return make_taxii2_response(response)
486486

487-
@register_handler(r"^/(?P<api_root_id>[^/]+)/$", handles_own_auth=True)
487+
@register_handler(r"^/taxii2/(?P<api_root_id>[^/]+)/$", handles_own_auth=True)
488488
def api_root_handler(self, api_root_id):
489489
try:
490490
api_root = self.persistence.get_api_root(api_root_id=api_root_id)
@@ -503,7 +503,7 @@ def api_root_handler(self, api_root_id):
503503
response["description"] = api_root.description
504504
return make_taxii2_response(response)
505505

506-
@register_handler(r"^/(?P<api_root_id>[^/]+)/status/(?P<job_id>[^/]+)/$")
506+
@register_handler(r"^/taxii2/(?P<api_root_id>[^/]+)/status/(?P<job_id>[^/]+)/$")
507507
def job_handler(self, api_root_id, job_id):
508508
try:
509509
job, job_details = self.persistence.get_job_and_details(
@@ -531,7 +531,7 @@ def job_handler(self, api_root_id, job_id):
531531
}
532532
return make_taxii2_response(response)
533533

534-
@register_handler(r"^/(?P<api_root_id>[^/]+)/collections/$", handles_own_auth=True)
534+
@register_handler(r"^/taxii2/(?P<api_root_id>[^/]+)/collections/$", handles_own_auth=True)
535535
def collections_handler(self, api_root_id):
536536
try:
537537
api_root = self.persistence.get_api_root(api_root_id=api_root_id)
@@ -561,7 +561,7 @@ def collections_handler(self, api_root_id):
561561
return make_taxii2_response(response)
562562

563563
@register_handler(
564-
r"^/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/$",
564+
r"^/taxii2/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/$",
565565
handles_own_auth=True,
566566
)
567567
def collection_handler(self, api_root_id, collection_id_or_alias):
@@ -589,7 +589,7 @@ def collection_handler(self, api_root_id, collection_id_or_alias):
589589
return make_taxii2_response(response)
590590

591591
@register_handler(
592-
r"^/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/manifest/$",
592+
r"^/taxii2/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/manifest/$",
593593
handles_own_auth=True,
594594
)
595595
def manifest_handler(self, api_root_id, collection_id_or_alias):
@@ -634,7 +634,7 @@ def manifest_handler(self, api_root_id, collection_id_or_alias):
634634
)
635635

636636
@register_handler(
637-
r"^/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/objects/$",
637+
r"^/taxii2/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/objects/$",
638638
("GET", "POST"),
639639
valid_content_types=("application/taxii+json;version=2.1",),
640640
handles_own_auth=True,
@@ -726,7 +726,7 @@ def objects_post_handler(self, api_root_id, collection_id_or_alias):
726726
)
727727

728728
@register_handler(
729-
r"^/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/objects/(?P<object_id>[^/]+)/$",
729+
r"^/taxii2/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)/objects/(?P<object_id>[^/]+)/$",
730730
("GET", "DELETE"),
731731
handles_own_auth=True,
732732
)
@@ -807,7 +807,7 @@ def object_delete_handler(self, api_root_id, collection_id_or_alias, object_id):
807807

808808
@register_handler(
809809
(
810-
r"^/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)"
810+
r"^/taxii2/(?P<api_root_id>[^/]+)/collections/(?P<collection_id_or_alias>[^/]+)"
811811
r"/objects/(?P<object_id>[^/]+)/versions/$"
812812
),
813813
handles_own_auth=True,

tests/taxii2/test_taxii2_api_root.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_api_root(
183183
),
184184
):
185185
func = getattr(authenticated_client, method)
186-
response = func(f"/{api_root_id}/", headers=headers)
186+
response = func(f"/taxii2/{api_root_id}/", headers=headers)
187187
assert response.status_code == expected_status
188188
assert {
189189
key: response.headers.get(key) for key in expected_headers
@@ -224,7 +224,7 @@ def test_api_root_unauthenticated(
224224
):
225225
func = getattr(client, method)
226226
response = func(
227-
f"/{api_root_id}/",
227+
f"/taxii2/{api_root_id}/",
228228
headers={"Accept": "application/taxii+json;version=2.1"},
229229
)
230230
assert response.status_code == expected_status_code

tests/taxii2/test_taxii2_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def test_collection(
189189
},
190190
):
191191
func = getattr(authenticated_client, method)
192-
response = func(f"/{api_root_id}/collections/{collection_id}/", headers=headers)
192+
response = func(f"/taxii2/{api_root_id}/collections/{collection_id}/", headers=headers)
193193
assert response.status_code == expected_status
194194
assert {
195195
key: response.headers.get(key) for key in expected_headers
@@ -234,7 +234,7 @@ def test_collection_unauthenticated(
234234
):
235235
func = getattr(client, method)
236236
response = func(
237-
f"/{API_ROOTS[0].id}/collections/{collection_id}/",
237+
f"/taxii2/{API_ROOTS[0].id}/collections/{collection_id}/",
238238
headers={"Accept": "application/taxii+json;version=2.1"},
239239
)
240240
assert response.status_code == expected_status_code

tests/taxii2/test_taxii2_collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_collections(
213213
},
214214
):
215215
func = getattr(authenticated_client, method)
216-
response = func(f"/{api_root_id}/collections/", headers=headers)
216+
response = func(f"/taxii2/{api_root_id}/collections/", headers=headers)
217217
assert response.status_code == expected_status
218218
assert {
219219
key: response.headers.get(key) for key in expected_headers
@@ -258,7 +258,7 @@ def test_collections_unauthenticated(
258258
):
259259
func = getattr(client, method)
260260
response = func(
261-
f"/{api_root_id}/collections/",
261+
f"/taxii2/{api_root_id}/collections/",
262262
headers={"Accept": "application/taxii+json;version=2.1"},
263263
)
264264
assert response.status_code == expected_status_code

tests/taxii2/test_taxii2_discovery.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"title": "Some TAXII Server",
3030
"description": "This TAXII Server contains a listing of...",
3131
"contact": "string containing contact information",
32-
"default": f"/{API_ROOTS_WITH_DEFAULT[0].id}/",
33-
"api_roots": [f"/{item.id}/" for item in API_ROOTS_WITH_DEFAULT],
32+
"default": f"/taxii2/{API_ROOTS_WITH_DEFAULT[0].id}/",
33+
"api_roots": [f"/taxii2/{item.id}/" for item in API_ROOTS_WITH_DEFAULT],
3434
},
3535
id="good, with default api root",
3636
),
@@ -45,7 +45,7 @@
4545
"title": "Some TAXII Server",
4646
"description": "This TAXII Server contains a listing of...",
4747
"contact": "string containing contact information",
48-
"api_roots": [f"/{item.id}/" for item in API_ROOTS_WITHOUT_DEFAULT],
48+
"api_roots": [f"/taxii2/{item.id}/" for item in API_ROOTS_WITHOUT_DEFAULT],
4949
},
5050
id="good, without default api root",
5151
),

tests/taxii2/test_taxii2_manifest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def test_manifest(
726726
else:
727727
querystring = ""
728728
response = func(
729-
f"/{api_root_id}/collections/{collection_id}/manifest/{querystring}",
729+
f"/taxii2/{api_root_id}/collections/{collection_id}/manifest/{querystring}",
730730
headers=headers,
731731
)
732732
assert response.status_code == expected_status
@@ -773,7 +773,7 @@ def test_manifest_unauthenticated(
773773
):
774774
func = getattr(client, method)
775775
response = func(
776-
f"/{API_ROOTS[0].id}/collections/{collection_id}/manifest/",
776+
f"/taxii2/{API_ROOTS[0].id}/collections/{collection_id}/manifest/",
777777
headers={"Accept": "application/taxii+json;version=2.1"},
778778
)
779779
assert response.status_code == expected_status_code

tests/taxii2/test_taxii2_object.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ def test_object(
826826
querystring = ""
827827
kwargs = {"headers": headers}
828828
response = func(
829-
f"/{api_root_id}/collections/{collection_id}/objects/{object_id}/{querystring}",
829+
f"/taxii2/{api_root_id}/collections/{collection_id}/objects/{object_id}/{querystring}",
830830
**kwargs,
831831
)
832832
assert response.status_code == expected_status
@@ -897,7 +897,7 @@ def test_object_unauthenticated(
897897
):
898898
func = getattr(client, method)
899899
response = func(
900-
f"/{API_ROOTS[0].id}/collections/{collection_id}/objects/{stix_id}/",
900+
f"/taxii2/{API_ROOTS[0].id}/collections/{collection_id}/objects/{stix_id}/",
901901
headers={"Accept": "application/taxii+json;version=2.1"},
902902
)
903903
assert response.status_code == expected_status_code

tests/taxii2/test_taxii2_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ def test_objects(
10621062
if method == "post":
10631063
kwargs["json"] = post_data
10641064
response = func(
1065-
f"/{api_root_id}/collections/{collection_id}/objects/{querystring}",
1065+
f"/taxii2/{api_root_id}/collections/{collection_id}/objects/{querystring}",
10661066
**kwargs,
10671067
)
10681068
assert response.status_code == expected_status
@@ -1147,7 +1147,7 @@ def test_objects_unauthenticated(
11471147
}
11481148
func = getattr(client, method)
11491149
response = func(
1150-
f"/{API_ROOTS[0].id}/collections/{collection_id}/objects/",
1150+
f"/taxii2/{API_ROOTS[0].id}/collections/{collection_id}/objects/",
11511151
**kwargs,
11521152
)
11531153
assert response.status_code == expected_status_code

0 commit comments

Comments
 (0)