Skip to content

Unable to Proxy Firebase Url #116

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

Closed
therynamo opened this issue Jul 27, 2017 · 8 comments
Closed

Unable to Proxy Firebase Url #116

therynamo opened this issue Jul 27, 2017 · 8 comments

Comments

@therynamo
Copy link

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOs Sierra 10.12.5
  • Firebase SDK version: shouldn't make much of a difference in this issue
  • Library version: ^5.1.0
  • Firebase Product: database

[REQUIRED] Step 3: Describe the problem

When 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?

Steps to reproduce:

Listed above.

Relevant Code:

Listed above.

Related Issue From firebase-admin.

@google-oss-bot
Copy link
Contributor

Hey there! I couldn't figure out what this issue is about, so I've labeled it for a human to triage. Hang tight.

@google-oss-bot
Copy link
Contributor

Hmmm this issue does not seem to follow the issue template. Make sure you provide all the required information.

@therynamo
Copy link
Author

@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, thlorenz/proxyquire#152, leading to this jestjs/jest#1937 (comment).

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.

@rockwotj
Copy link
Contributor

rockwotj commented Aug 1, 2017

@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?

@jshcrowthe
Copy link
Contributor

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.

@vincentwoo
Copy link

I also want more flexibility in proxying Firebase by domain name to avoid China's block on Firebase traffic.

@jshcrowthe
Copy link
Contributor

This was submitted in a PR and should be fixed. LMK if there are any other issues!

@therynamo
Copy link
Author

Stellar! Thanks @jshcrowthe! 👍

Feiyang1 pushed a commit that referenced this issue Apr 30, 2019
Also changes idb manager functions to get the key from the app config.
@firebase firebase locked and limited conversation to collaborators Oct 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants