|
49 | 49 |
|
50 | 50 | API_URL = "https://oeo.test/" |
51 | 51 |
|
| 52 | +# TODO: eliminate this and replace with `build_capabilities` usage |
52 | 53 | BASIC_ENDPOINTS = [{"path": "/credentials/basic", "methods": ["GET"]}] |
53 | 54 |
|
54 | 55 |
|
@@ -552,6 +553,104 @@ def test_capabilities_caching(requests_mock): |
552 | 553 | assert m.call_count == 1 |
553 | 554 |
|
554 | 555 |
|
| 556 | +def _get_capabilities_auth_dependent(request, context): |
| 557 | + capabilities = build_capabilities() |
| 558 | + capabilities["endpoints"] = [ |
| 559 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 560 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 561 | + ] |
| 562 | + if "Authorization" in request.headers: |
| 563 | + capabilities["endpoints"].append({"methods": ["GET"], "path": "/me"}) |
| 564 | + return capabilities |
| 565 | + |
| 566 | + |
| 567 | +def test_capabilities_caching_after_authenticate_basic(requests_mock): |
| 568 | + user, pwd = "john262", "J0hndo3" |
| 569 | + get_capabilities_mock = requests_mock.get(API_URL, json=_get_capabilities_auth_dependent) |
| 570 | + requests_mock.get(API_URL + 'credentials/basic', text=_credentials_basic_handler(user, pwd)) |
| 571 | + |
| 572 | + con = Connection(API_URL) |
| 573 | + assert con.capabilities().capabilities["endpoints"] == [ |
| 574 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 575 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 576 | + ] |
| 577 | + assert get_capabilities_mock.call_count == 1 |
| 578 | + con.capabilities() |
| 579 | + assert get_capabilities_mock.call_count == 1 |
| 580 | + |
| 581 | + con.authenticate_basic(username=user, password=pwd) |
| 582 | + assert get_capabilities_mock.call_count == 1 |
| 583 | + assert con.capabilities().capabilities["endpoints"] == [ |
| 584 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 585 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 586 | + {"methods": ["GET"], "path": "/me"}, |
| 587 | + ] |
| 588 | + |
| 589 | + assert get_capabilities_mock.call_count == 2 |
| 590 | + |
| 591 | + |
| 592 | +def test_capabilities_caching_after_authenticate_oidc_refresh_token(requests_mock): |
| 593 | + client_id = "myclient" |
| 594 | + refresh_token = "fr65h!" |
| 595 | + get_capabilities_mock = requests_mock.get(API_URL, json=_get_capabilities_auth_dependent) |
| 596 | + requests_mock.get( |
| 597 | + API_URL + "credentials/oidc", |
| 598 | + json={"providers": [{"id": "oi", "issuer": "https://oidc.test", "title": "OI!", "scopes": ["openid"]}]}, |
| 599 | + ) |
| 600 | + oidc_mock = OidcMock( |
| 601 | + requests_mock=requests_mock, |
| 602 | + expected_grant_type="refresh_token", |
| 603 | + expected_client_id=client_id, |
| 604 | + expected_fields={"refresh_token": refresh_token}, |
| 605 | + ) |
| 606 | + |
| 607 | + conn = Connection(API_URL) |
| 608 | + assert conn.capabilities().capabilities["endpoints"] == [ |
| 609 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 610 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 611 | + ] |
| 612 | + |
| 613 | + assert get_capabilities_mock.call_count == 1 |
| 614 | + conn.capabilities() |
| 615 | + assert get_capabilities_mock.call_count == 1 |
| 616 | + |
| 617 | + conn.authenticate_oidc_refresh_token(client_id=client_id, refresh_token=refresh_token) |
| 618 | + assert get_capabilities_mock.call_count == 1 |
| 619 | + assert conn.capabilities().capabilities["endpoints"] == [ |
| 620 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 621 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 622 | + {"methods": ["GET"], "path": "/me"}, |
| 623 | + ] |
| 624 | + assert get_capabilities_mock.call_count == 2 |
| 625 | + |
| 626 | + |
| 627 | +def test_capabilities_caching_after_authenticate_oidc_access_token(requests_mock): |
| 628 | + get_capabilities_mock = requests_mock.get(API_URL, json=_get_capabilities_auth_dependent) |
| 629 | + requests_mock.get( |
| 630 | + API_URL + "credentials/oidc", |
| 631 | + json={"providers": [{"id": "oi", "issuer": "https://oidc.test", "title": "OI!", "scopes": ["openid"]}]}, |
| 632 | + ) |
| 633 | + |
| 634 | + conn = Connection(API_URL) |
| 635 | + assert conn.capabilities().capabilities["endpoints"] == [ |
| 636 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 637 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 638 | + ] |
| 639 | + |
| 640 | + assert get_capabilities_mock.call_count == 1 |
| 641 | + conn.capabilities() |
| 642 | + assert get_capabilities_mock.call_count == 1 |
| 643 | + |
| 644 | + conn.authenticate_oidc_access_token(access_token="6cc355!") |
| 645 | + assert get_capabilities_mock.call_count == 1 |
| 646 | + assert conn.capabilities().capabilities["endpoints"] == [ |
| 647 | + {"methods": ["GET"], "path": "/credentials/basic"}, |
| 648 | + {"methods": ["GET"], "path": "/credentials/oidc"}, |
| 649 | + {"methods": ["GET"], "path": "/me"}, |
| 650 | + ] |
| 651 | + assert get_capabilities_mock.call_count == 2 |
| 652 | + |
| 653 | + |
555 | 654 | def test_file_formats(requests_mock): |
556 | 655 | requests_mock.get("https://oeo.test/", json={"api_version": "1.0.0"}) |
557 | 656 | m = requests_mock.get("https://oeo.test/file_formats", json={"output": {"GTiff": {"gis_data_types": ["raster"]}}}) |
|
0 commit comments