|
2 | 2 |
|
3 | 3 | import pytest
|
4 | 4 |
|
5 |
| -# - BASIC_AUTH={"public_endpoints":[{"path":"/","method":"GET"},{"path":"/search","method":"GET"}],"users":[{"username":"admin","password":"admin","permissions":"*"},{"username":"reader","password":"reader","permissions":[{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]} |
6 |
| - |
7 | 5 |
|
8 | 6 | @pytest.mark.asyncio
|
9 |
| -async def test_get_search_not_authenticated(app_client_basic_auth): |
10 |
| - """Test public endpoint search without authentication""" |
| 7 | +async def test_get_search_not_authenticated(app_client_basic_auth, ctx): |
| 8 | + """Test public endpoint [GET /search] without authentication""" |
11 | 9 | if not os.getenv("BASIC_AUTH"):
|
12 | 10 | pytest.skip()
|
13 |
| - params = {"query": '{"gsd": {"gt": 14}}'} |
| 11 | + params = {"id": ctx.item["id"]} |
14 | 12 |
|
15 | 13 | response = await app_client_basic_auth.get("/search", params=params)
|
16 | 14 |
|
17 |
| - assert response.status_code == 200 |
18 |
| - assert response.json() == { |
19 |
| - "type": "FeatureCollection", |
20 |
| - "features": [], |
21 |
| - "links": [], |
22 |
| - "context": {"returned": 0, "limit": 10, "matched": 0}, |
23 |
| - } |
| 15 | + assert response.status_code == 200, response |
| 16 | + assert response.json()["features"][0]["geometry"] == ctx.item["geometry"] |
24 | 17 |
|
25 | 18 |
|
26 | 19 | @pytest.mark.asyncio
|
27 |
| -async def test_post_search_authenticated(app_client_basic_auth): |
28 |
| - """Test protected post search with reader auhtentication""" |
| 20 | +async def test_post_search_authenticated(app_client_basic_auth, ctx): |
| 21 | + """Test protected endpoint [POST /search] with reader auhtentication""" |
29 | 22 | if not os.getenv("BASIC_AUTH"):
|
30 | 23 | pytest.skip()
|
31 |
| - params = { |
32 |
| - "bbox": [97.504892, -45.254738, 174.321298, -2.431580], |
33 |
| - "fields": {"exclude": ["properties"]}, |
34 |
| - } |
| 24 | + params = {"id": ctx.item["id"]} |
35 | 25 | headers = {"Authorization": "Basic cmVhZGVyOnJlYWRlcg=="}
|
36 | 26 |
|
37 | 27 | response = await app_client_basic_auth.post("/search", json=params, headers=headers)
|
38 | 28 |
|
39 |
| - assert response.status_code == 200 |
40 |
| - assert response.json() == { |
41 |
| - "type": "FeatureCollection", |
42 |
| - "features": [], |
43 |
| - "links": [], |
44 |
| - "context": {"returned": 0, "limit": 10, "matched": 0}, |
45 |
| - } |
| 29 | + assert response.status_code == 200, response |
| 30 | + assert response.json()["features"][0]["geometry"] == ctx.item["geometry"] |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.asyncio |
| 34 | +async def test_delete_resource_anonymous( |
| 35 | + app_client_basic_auth, |
| 36 | +): |
| 37 | + """Test protected endpoint [DELETE /collections/{collection_id}] without auhtentication""" |
| 38 | + if not os.getenv("BASIC_AUTH"): |
| 39 | + pytest.skip() |
| 40 | + |
| 41 | + response = await app_client_basic_auth.delete("/collections/test-collection") |
| 42 | + |
| 43 | + assert response.status_code == 401 |
| 44 | + assert response.json() == {"detail": "Not authenticated"} |
46 | 45 |
|
47 | 46 |
|
48 | 47 | @pytest.mark.asyncio
|
49 |
| -async def test_delete_resource_insufficient_permissions(app_client_basic_auth): |
50 |
| - """Test protected delete collection with reader auhtentication""" |
| 48 | +async def test_delete_resource_invalid_credentials(app_client_basic_auth, ctx): |
| 49 | + """Test protected endpoint [DELETE /collections/{collection_id}] with invalid credentials""" |
51 | 50 | if not os.getenv("BASIC_AUTH"):
|
52 | 51 | pytest.skip()
|
53 |
| - headers = { |
54 |
| - "Authorization": "Basic cmVhZGVyOnJlYWRlcg==" |
55 |
| - } # Assuming this is a valid authorization token |
| 52 | + |
| 53 | + headers = {"Authorization": "Basic YWRtaW46cGFzc3dvcmQ="} |
56 | 54 |
|
57 | 55 | response = await app_client_basic_auth.delete(
|
58 |
| - "/collections/test-collection", headers=headers |
| 56 | + f"/collections/{ctx.collection['id']}", headers=headers |
59 | 57 | )
|
60 | 58 |
|
61 |
| - assert ( |
62 |
| - response.status_code == 403 |
63 |
| - ) # Expecting a 403 status code for insufficient permissions |
| 59 | + assert response.status_code == 401 |
| 60 | + assert response.json() == {"detail": "Incorrect username or password"} |
| 61 | + |
| 62 | + |
| 63 | +@pytest.mark.asyncio |
| 64 | +async def test_delete_resource_insufficient_permissions(app_client_basic_auth, ctx): |
| 65 | + """Test protected endpoint [DELETE /collections/{collection_id}] with reader user which has insufficient permissions""" |
| 66 | + if not os.getenv("BASIC_AUTH"): |
| 67 | + pytest.skip() |
| 68 | + |
| 69 | + headers = {"Authorization": "Basic cmVhZGVyOnJlYWRlcg=="} |
| 70 | + |
| 71 | + response = await app_client_basic_auth.delete( |
| 72 | + f"/collections/{ctx.collection['id']}", headers=headers |
| 73 | + ) |
| 74 | + |
| 75 | + assert response.status_code == 403 |
64 | 76 | assert response.json() == {
|
65 | 77 | "detail": "Insufficient permissions for [DELETE /collections/test-collection]"
|
66 | 78 | }
|
| 79 | + |
| 80 | + |
| 81 | +@pytest.mark.asyncio |
| 82 | +async def test_delete_resource_sufficient_permissions(app_client_basic_auth, ctx): |
| 83 | + """Test protected endpoint [DELETE /collections/{collection_id}] with admin user which has sufficient permissions""" |
| 84 | + if not os.getenv("BASIC_AUTH"): |
| 85 | + pytest.skip() |
| 86 | + |
| 87 | + headers = {"Authorization": "Basic YWRtaW46YWRtaW4="} |
| 88 | + |
| 89 | + response = await app_client_basic_auth.delete( |
| 90 | + f"/collections/{ctx.collection['id']}", headers=headers |
| 91 | + ) |
| 92 | + |
| 93 | + assert response.status_code == 204 |
0 commit comments