-
Notifications
You must be signed in to change notification settings - Fork 905
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
Callable function in emulator returns 'unauthenticated' when passing in mock auth via firebase/testing lib #1475
Comments
@samtstern will best be able to look at this and help triage. |
I was able to reproduce this locally, thank you for the detailed bug. Now I can investigate. |
Ok so the failure happens when the My token looks something like this:
Because it's from the test SDK, it has an invalid signature: So I think this is working as intended right now, but we want to make the Functions SDK accept an invalid signature when it's running in the emulator ... not sure how to do that in the best way. |
OK @ryanmeisters this would basically come down to stubbing out the call to So for now I have to put this on the backlog, but hopefully we can get it done after we fix some more pressing bugs. I hope that makes sense! |
Definitely makes sense, thanks a lot for looking into it! No worries. I think I can work around it for now by leaving |
@ryanmeisters by the way you can check |
Maybe my setup (macOS 10.14.6), but when I run @ryanmeisters project I don't even see the
Even after uncommented the line specified. I can hit the method just fine if I curl it directly:
Additional setup details:
EDIT:The issue was on my side. I didn't realize the project id has to match the locally configured project id. I assumed because it was running in an emulator the project id was arbitrary. Once that was fixed I saw the exact same Leaving this here for posterity. |
I would be also interested in a better solution to this. I wonder why is it a problem to generate a token with the correct signature. I mean how is it possible that we can communicate with the emulated firestore just fine (there is surely some token handling as well), but the token for functions doesn't work? @ryanmeisters How do you approach mocking auth in tests? It seems that error is thrown way before the callable function is accessed. I am surprised that these "basics" are not figured out yet. How are people testing functions? |
Hey @FredyC. I feel your pain. Unfortunately it's been a while now so I don't remember all the nuances of getting this working. One thing is for sure--it was way too hard. If you're seeing an error before the function code is actually run, I remember having the same issue that @JamesMcMahon described above. Also here's a gist with some of my actual integration test code. Hope it helps! It does what @samtstern suggested and uses the |
@ryanmeisters Thanks for the heads up. Yea, I have given up. Instead, I've basically extracted logic to a separate non-cloud functions and writing tests for that is much easier. I just need to pass all the data inside. Hopefully, the remaining logic of communication with Firestore will work. |
Ahhh - took me 2 days of wrestling with this same problem before I found this thread. Bit disappointing I can't test my callable functions in the emulator :-( |
@luke-studley sorry about that experience and thanks for the bump! You inspired me to dig deeper and I found a solution I am happy with. PR on the way, this will be fixed in the next release. |
The fix has been released in |
Hi folks, I need to remind something here. [REQUIRED] Steps to reproduceI am using this repo ps: All steps are same as what @ryanmeisters did in this issue. Test EnvironmentMacOS: 10.15.3 ps: Please close all and reopen new command windows once you have updated versions of firebase-tools. Firebase-tools: v7.16.1run
Debug Info by Emulator is
Firebase-tools: v7.16.0run
Debug Info by Emulator is
|
@seki2020 is right, we have this issue again in version 7.16.1 |
Filed this bug with the testing SDK: We can work around it in the CLI though, PR coming. |
Version |
Not sure if this is the right place for this report, or if perhaps I am using the emulators/sdk incorrectly. I would like to write some integration tests and run against the Firebase emulator suite. I found the docs on testing security rules helpful, and it seems like the intention of the
@firebase/testing
library is to allow testing of functions/database beyond just security rules.That doc outlines how to mock authentication by passing and
auth
dictionary toinitializeTestApp(..)
, but when I use the resulting app to call an httpsCallable function, the emulator returns an 'unauthenticated' error.[REQUIRED] Environment info
firebase-tools: 7.0.2
Platform: macOS 10.14.5
[REQUIRED] Test case
Here is a minimal reproduction: https://github.com/ryanmeisters/firebase-callable-emulator-test
It contains a single
helloCallable
function that returns{hello: "world"}
, and a single test that calls the function and verifies the response. The test passes when noauth
is passed intoinitializeTestApp
, but gets 'unauthenticated' error ifauth
is passed.[REQUIRED] Steps to reproduce
npm install
./emulate.sh
(compiles typescript and runs emulators)cd functions && npm run test # test fails with 'unauthenticated'
npm run test
again. Test passes[REQUIRED] Expected behavior
The callable function should be called and receive the mock auth dictionary
[REQUIRED] Actual behavior
Function returns and
unauthenticated
error.Output of
firebase emulators:start --debug
and function callOutput of
npm run test
The text was updated successfully, but these errors were encountered: