0

I'm working on a client/server game. Normally the client and server run in two different processes, but I want to test their interaction in a unit test (or I guess you could say integration test) via the Karma test runner. In order to make that work I believe I'll need to authenticate as both the client and server from the same process. Is there a way to do this? Below is some code showing what I want to do. Right now the client authentication seems to remove the server authentication.

var server_ref = new Firebase('https://cardbrew-staging.firebaseio.com');
var token = 'mysecuritytoken';
server_ref.authWithCustomToken(token, function(error, authData) {
  console.log('server authed, listening to queue...');
  server_ref.child('user-queue').on('child_added', function(snap) {
    console.log('user entered queue:', snap.key());
  });
});

var client_ref = new Firebase('https://cardbrew-staging.firebaseio.com');
client_ref.authAnonymously(function(error, authData) {
  var user_id = authData.uid;
  console.log('client authed, user_id:', user_id);
  client_ref.child('user-queue').child(user_id).set(true);
});
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jesse Aldridge
  • 7,991
  • 9
  • 48
  • 75
  • 2
    See http://stackoverflow.com/questions/32372396/multiple-custom-authentication-requests-to-firebase-failing – Frank van Puffelen Oct 20 '15 at 13:30
  • Also, for the benefit of others attempting to apply this to multiple auth scenarios (not specifically for the testing scenario requested here), see [this answer](https://groups.google.com/d/msg/firebase-talk/9n26blpr_VY/eCWZsAMFDAAJ). Generally, let Firebase enforce authentication instead of trying to hack your server to impersonate users. – Kato Oct 20 '15 at 20:02

0 Answers0