mardi 5 juillet 2016

User authentication in Firebase 3.0 javascript test code

I'm trying to test drive some Firebase 3.0 client-side JavaScript. I want to simulate a user logging in with email and password authentication and performing some database reads,writes and updates. I'm using Mocha/Chai to run/write my tests.

When I originally tried to initialise my Firebase connection in my tests using:

import firebase from 'firebase'
var config = {
    apikey: "my-api-key",
    authdomain: "my-site.firebaseapp.com",
    databaseurl: "http://ift.tt/29tJZRt",
    storagebucket: "my-site.appspot.com"
};
firebase.initializeApp(config);

I got the following error on the call to initializeApp():

c:\Code\Shtum\Web\node_modules\firebase\auth-node\auth.js:61

throw new Error('Invalid service account provided');

^

I can understand that the test is running in the context of Node rather than the browser, so I've set up a service account and have successfully authenticated using that and performed a database update.

However what I really want to do is simulate a user logging in so that I can test my security configuration, but I can't find a way to do this.

Is there a way that I simulate user authentication from my javascript test code?

Aucun commentaire:

Enregistrer un commentaire