-
Notifications
You must be signed in to change notification settings - Fork 948
Enable firestore sdk to talk to emulator #1007
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
Changes from 5 commits
808659f
b7d185b
0c7999c
254bf54
e7a155e
3b03a9c
d8865f7
92977e8
3a2ff76
8452e3f
b2259f5
bf748c3
5497fba
d335a60
585366f
85ca2e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,12 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import { firebase } from '@firebase/app'; | ||
import * as admin from 'firebase-admin'; | ||
import request from 'request-promise'; | ||
import * as fs from 'fs'; | ||
import { FirebaseApp } from '@firebase/app-types'; | ||
import { base64 } from '@firebase/util'; | ||
|
||
const DBURL = 'http://localhost:9000'; | ||
|
||
|
@@ -64,6 +67,34 @@ export function initializeTestApp(options: any): admin.app.App { | |
); | ||
} | ||
|
||
export function initializeFirestoreTestApp(options: any): FirebaseApp { | ||
if (!('projectId' in options)) { | ||
throw new Error('projectId not specified'); | ||
} | ||
if (typeof options.auth != 'object') { | ||
throw new Error('auth must be an object'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want, you could declare the type for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
var header = { | ||
alg: 'RS256', | ||
kid: 'fakekid' | ||
}; | ||
var fakeToken = [ | ||
base64.encodeString(JSON.stringify(header), /*webSafe=*/ true), | ||
base64.encodeString(JSON.stringify(options.auth), /*webSafe=*/ true), | ||
'fakesignature' | ||
].join('.'); | ||
let app = firebase.initializeApp( | ||
{ | ||
projectId: options.projectId, | ||
tokenOverride: fakeToken | ||
}, | ||
'app-' + new Date().getTime() + '-' + Math.random() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can make this a little more intuitive if you add a local variable that will help let users know that this is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we initialize the app here, then immediately hijack the |
||
(app as any).INTERNAL.getToken = () => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a comment here explaining that this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
Promise.resolve({ accessToken: fakeToken }); | ||
return app; | ||
} | ||
|
||
export type LoadDatabaseRulesOptions = { | ||
databaseName: String; | ||
rules: String; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to remove this to get the CI to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done