-
Notifications
You must be signed in to change notification settings - Fork 930
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 15 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@firebase/testing", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"private": true, | ||
"description": "", | ||
"author": "Firebase <[email protected]> (https://firebase.google.com/)", | ||
|
@@ -16,7 +16,6 @@ | |
}, | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"firebase-admin": "5.12.0", | ||
"request-promise": "4.2.2" | ||
}, | ||
"devDependencies": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import * as admin from 'firebase-admin'; | ||
import { firebase } from '@firebase/app'; | ||
import request from 'request-promise'; | ||
import * as fs from 'fs'; | ||
import { FirebaseApp, FirebaseOptions } from '@firebase/app-types'; | ||
import { base64 } from '@firebase/util'; | ||
|
||
const DBURL = 'http://localhost:9000'; | ||
|
||
|
@@ -32,36 +34,43 @@ class FakeCredentials { | |
} | ||
} | ||
|
||
export function apps(): (admin.app.App | null)[] { | ||
return admin.apps; | ||
export function apps(): (FirebaseApp | null)[] { | ||
return firebase.apps; | ||
} | ||
|
||
export function initializeAdminApp(options: any): admin.app.App { | ||
if (!('databaseName' in options)) { | ||
throw new Error('databaseName not specified'); | ||
} | ||
return admin.initializeApp( | ||
{ | ||
credential: new FakeCredentials(), | ||
export type AppOptions = { | ||
databaseName?: string; | ||
projectId?: string; | ||
auth: object; | ||
}; | ||
export function initializeTestApp(options: AppOptions): FirebaseApp { | ||
let appOptions: FirebaseOptions; | ||
if ('databaseName' in options) { | ||
appOptions = { | ||
databaseURL: DBURL + '?ns=' + options.databaseName | ||
}, | ||
'app-' + (new Date().getTime() + Math.random()) | ||
); | ||
} | ||
|
||
export function initializeTestApp(options: any): admin.app.App { | ||
if (!('databaseName' in options)) { | ||
throw new Error('databaseName not specified'); | ||
}; | ||
} else if ('projectId' in options) { | ||
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. Is there a reason to not support both |
||
appOptions = { | ||
projectId: options.projectId | ||
}; | ||
} else { | ||
throw new Error('neither databaseName or projectId were specified'); | ||
} | ||
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 |
||
// if options.auth is not present, we will construct an app with auth == null | ||
return admin.initializeApp( | ||
{ | ||
credential: new FakeCredentials(), | ||
databaseURL: DBURL + '?ns=' + options.databaseName, | ||
databaseAuthVariableOverride: options.auth || null | ||
}, | ||
'app-' + (new Date().getTime() + Math.random()) | ||
); | ||
const header = { | ||
alg: 'RS256', | ||
kid: 'fakekid' | ||
}; | ||
const fakeToken = [ | ||
base64.encodeString(JSON.stringify(header), /*webSafe=*/ false), | ||
base64.encodeString(JSON.stringify(options.auth), /*webSafe=*/ false), | ||
'fakesignature' | ||
].join('.'); | ||
const appName = 'app-' + new Date().getTime() + '-' + Math.random(); | ||
const app = firebase.initializeApp(appOptions, appName); | ||
// hijacking INTERNAL.getToken to bypass FirebaseAuth and allows specifying of auth headers | ||
(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 = { | ||
|
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.
We don't need to do this, even though it is a breaking change major
0
s allow for breaking changes between other versions also. Additionally, I update this at publish time so no need to edit.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