databaseWhen attempting to use firebase-admins initializeApp function, the URL is strictly enforced. I'm sure this is intended, however it is keeping me from proxying the firebase URL to a local server for testing. Example:
firebase.initializeApp({
credential: firebase.credential.cert(FIREBASE_CREDENTIALS),
databaseURL: 'http://localhost:4001/https://my.firebaseio.com'
});
Resulting in the following error:
Error: FIREBASE FATAL ERROR: Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com
I use mockyeah for integration testing, which is a nice solution for being able to record snapshots for outgoing requests and their responses. The only caveat is that in order to record the response you have to proxy the URL so that the server can make the call itself.
The issue isn't necessarily with implementation on either side. My overall question is, would supporting a proxied URL be feasible?
Listed above.
Listed above.
Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.
Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.
@jshcrowthe thanks for adding the label. I thought I'd add a little more information now that I've explored around looking for more options.
Since mockyeah would not directly work in this situation due to the strict url enforcement on the firbase side, I moved over to nock to try and utilize their direct http intercept functionality. Effectively it should have blocked the call from ever being made and just returning json. I quickly found out that google oath was the first call being made by firebase-admin and that you couldn't directly return the desired response from there.
I continued to look around and stumbled upon this post, Testing Firebase with firebase-server by @urish. This looked really promising and seemed to be the right answer. Unfortunately it was not. After diving in and looking at the example code, both the example mentioned in the post using mockery and the example on master using proxyquire, I found out it is nearly impossible for me to accomplish this using Jest. After some more time debugging I began to look more to see if anyone else had any similar issues to my own. I then found this in proxyquire's issues, https://github.com/thlorenz/proxyquire/issues/152, leading to this https://github.com/facebook/jest/issues/1937#issuecomment-254089972.
Turns out the issue with the firebase-server approach is using Jest due to its mock system. Now you're probably asking why this is a problem for firebasse-js-sdk to solve since it seems to be all in the testing framework/mocking system I'm using. To some degree I would agree with that. However, I do believe the issue here comes down to the strict URL enforcement. I'm sure there are some good reasons behind that design choice, but I'm finding it difficult to write integration tests that don't affect the system under test. The best current solution is hacking the /etc/hosts file and redirecting the my.firebaseio.com URL there, for CI that wont work though. Proxying the base url, even if it was a flag we could pass to the initializeApp method to indicate that we're testing, would be wonderful. What would be even better is if we could pass localhost:5000 into the base url, such that we can use firebase-server.
@therynamo if you set up something like DNSmasq (or just modify your /etc/hosts) you have override a subdomain to a local proxy. That way test-db.mylaptop.local will work and the SDK will parse the database name as test-db. You could also use this to override a database url (foo.firebaseio.com) to another IP.
The database internals require that we need to parse the subdomain. What CI environment do you have that doesn't let you write an etc/hosts file?
I don't know that I see an issue with allowing localhost URLs. I would defer to @schmidt-sebastian for a final say on that, but I think this could be a great PR for someone to take on.
I also want more flexibility in proxying Firebase by domain name to avoid China's block on Firebase traffic.
This was submitted in a PR and should be fixed. LMK if there are any other issues!
Stellar! Thanks @jshcrowthe! 馃憤
Most helpful comment
I also want more flexibility in proxying Firebase by domain name to avoid China's block on Firebase traffic.