-
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 1 commit
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 |
---|---|---|
|
@@ -26,5 +26,6 @@ export { | |
assertSucceeds, | ||
initializeAdminApp, | ||
initializeTestApp, | ||
initializeFirestoreTestApp, | ||
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 need to remove this to get the CI to pass. 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 |
||
loadDatabaseRules | ||
} from './src/api'; |
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 * as util from '@firebase/util'; | ||
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 better way to import these? |
||
|
||
const DBURL = 'http://localhost:9000'; | ||
|
||
|
@@ -64,6 +67,30 @@ 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 = [ | ||
util.base64.encodeString(JSON.stringify(header),/*webSafe=*/true), | ||
util.base64.encodeString(JSON.stringify(options.auth),/*webSafe=*/true), | ||
"fakesignature" | ||
].join("."); | ||
return 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. Can we initialize the app here, then immediately hijack the |
||
} | ||
|
||
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.
Do we have to modify the Firestore SDK in order to get this to work? I'd prefer not to introduce this
tokenOverride
value.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.
AFAICT, we'd have to change
app-types
to exportFirebaseAppImpl
or to moveINTERNAL
intoFirebaseApp
to give visibility to the testing package. If that's the only way to do this, I'd rather modify thefirestore
package thanapp
package