Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHT-datasource doesn't handle remote authentication #9701

Open
dianabarsan opened this issue Dec 10, 2024 · 3 comments
Open

CHT-datasource doesn't handle remote authentication #9701

dianabarsan opened this issue Dec 10, 2024 · 3 comments
Labels
Type: Bug Fix something that isn't working as intended

Comments

@dianabarsan
Copy link
Member

Describe the bug
cht-datasource uses fetch to interact with a remote data source. However, all it receives when the datasource is initialized is the URL, but not authentication, and it further does not handle authentication at all.

const response = await fetch(`${context.url}/${path}?${params}`);

And fetch does not support adding inlined basic authentication in the URL, for basic auth it requires an Authorization header.

There are some integration tests, but these are relying on enriching global fetch with a request-promise-native cookie jar that contains a session cookie:

global.fetch = require('fetch-cookie').default(global.fetch, cookieJar);

We are removing

To Reproduce
Steps to reproduce the behavior:

  1. Remove this line:
    global.fetch = require('fetch-cookie').default(global.fetch, cookieJar);
  2. Run integration tests.
  3. See lots of person and place api failures.

Expected behavior
CHT-datasource should be independent of hacks we set up in e2e tests.

Environment

  • Instance: local
  • App: api
  • Version: all

Additional context
As part of #6250 , and in conjunction with #8338 , I am removing all session setup and only relying on basic auth. CouchDb can now handle basic auth with many iterations out of the box, and maintaining sessions adds code complexity with we don't need anymore (fe. an entire PouchDb plugin which we now no longer need to maintain).

@dianabarsan dianabarsan added the Type: Bug Fix something that isn't working as intended label Dec 10, 2024
@jkuester
Copy link
Contributor

I am removing all session setup and only relying on basic auth

Wait, so https://github.com/medic/pouchdb-session-authentication is going away? I thought we just switched to that? 🤔 😅

all it receives when the datasource is initialized is the URL, but not authentication, and it further does not handle authentication at all.

FTR, this was by design. We concluded it was unnecessary to do any authentication work in the initial MVP of cht-datasource since it would be able to inherent the session from the context that it was running in. Not sure I would characterize this as a "bug".

With the removal of session authentication, are we going to be in a situation where production workflows are going to be running with the user/pass included in the URL? It seems like this would not be the case in webapp/admin (which are the two places that the remote cht-datasource context is getting used). In api/sentinel, the local cht-datasource context is used (which uses Pouch instead of fetch). So, I guess I do not see where we would have an issue with the production code.

That does still leave us with the problem of how the integration tests for the remote cht-datasource context should work now. Ideally we could find a way to make this work without any "hacks", but if that is not possible I would prefer to hack the test code instead of adding unnecessary complexity to the implementation code...

@dianabarsan
Copy link
Member Author

dianabarsan commented Dec 13, 2024

Wait, so https://github.com/medic/pouchdb-session-authentication is going away? I thought we just switched to that? 🤔 😅

Yes, this is going away. It's additional code we need to maintain and we don't need it anymore.

are we going to be in a situation where production workflows are going to be running with the user/pass included in the URL

No, we're going to pass an "Authorization" header with "Basic" authentication in api and sentinel. But some other services (like healthcheck) are still using auth in URLs I believe. We hadn't switched those to sessions yet.

how the integration tests

In my PR, I switched all datasource integration tests to hit the code through API endpoints. Up to you if you want to add other integration tests when implementing support for remote auth.

@jkuester
Copy link
Contributor

I switched all datasource integration tests to hit the code through API endpoints

Have not looked at the actual code change here, but taking this statement at face value this seems like a significant regression in test coverage, leaving the remote context of cht-datasource untested for by any sort of integration tests. This also seems to directly contradict the agreement reached in a separate PR to duplicate the tests here.

The reason why I think integration test coverage is so important here is because the low-level nature of the cht-datasource code makes it pretty risky to assume it is sufficiently tested by other integration/e2e workflows. I am less worried about the local context flows because the integration tests hitting the api REST endpoints do pretty much call directly through to the local cht-datasource logic. However, the remote context code is currently only consumed by the admin app and by online-only users of webapp. To properly test the behavior of the remote context against real api REST endpoints we need these additional integration tests specific to the remote context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Fix something that isn't working as intended
Projects
None yet
Development

No branches or pull requests

2 participants