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

No ability to unit test cloud functions as a simulated authenticated user #7509

Open
bocodez opened this issue Aug 1, 2023 · 1 comment
Open

Comments

@bocodez
Copy link

bocodez commented Aug 1, 2023

Operating System

Any

Browser Version

Any

Firebase SDK Version

9.14.0

Firebase SDK Product:

Firestore, Functions

Describe your project's tooling

VS Code set up as a generic project

Describe the problem

firebase/rules-unit-testing is a great way to test security rules, it allows easy switching between simulated users to check security from various users perspectives.

However, when your test involves calling a cloud function as such a simulated user, there is no way to do this. An example workflow:

  • Use authenticatedContext to switch to "Alice"
  • Call secured cloud function, which Alice is allowed to call
  • Unit test can expect "success"
  • Use authenticatedContext to switch to "Bob"
  • Call same secured cloud function, but Bob isn't on the list of allowed callees
  • Unit test can expect "failure"

I have searched around looking for a way to do this, but there is no mention out there on the internet.

So if it is possible, I would suggest that the documentation is updated.
If it is not possible, I would suggest adding this to firebase/rules-unit-testing which has a nice environment in place already.

I am not sure how major deployments of firebase are out there without automated testing for their security, and I feel that this is something that should not be overlooked.

Steps and code to reproduce issue

Make a new project with a cloud function that returns the authentication data.
Make a unit test that creates a simulated user with rules-unit-testing.
Hack the rules-unit-testing library to return a function object, and injected the authentication parameters into it.
Call the cloud function.

Expect to see authentication in the returned data.

It wasn't there.

@bocodez bocodez added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Aug 1, 2023
@jbalidiong jbalidiong added api: functions needs-attention testing-sdk testing with emulator and removed new A new issue that hasn't be categoirzed as question, bug or feature request labels Aug 1, 2023
@Vanethos
Copy link

Any news regarding this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants