Search code examples
unit-testingauthenticationunity-game-enginegoogle-cloud-firestorefirebase-security

How can I keep unit testing in Unity after introducing security rules to firestore?


I am using cloud firestore + cloud functions + firestore auth to support my game.

I developed the main part of the app with unit tests in the app plus typescript tests for cloud functions. Now I want to add security rules to secure the data.

When I do so, requiring the calls to be authenticated, all my unit tests in unity (naturally) fails, as I do not authenticate a user but mocks them as data representation of the user in the db.

I want to keep using my unit tests in unity but still requiring the real db to demand authentication.

I have tried to look around for mock auth, or auth test environment, but found nothing except the library rules-unit-testing.

I see the content of it with specialized logic for mocking user, making me think that I am understanding this the wrong way by trying to do this in unity. My question is, How to continue to do game tests in unity, which requires interacting with the firestore server, while keeping security rules?


Solution

  • I am answering my own question after more time.

    My analysis was that I ran into issues because I had coupled my code too tightly: server logic was on the client side and broke when introducing security rules. I decided to move logic to cloud functions and have only simple client side calls (sets, gets, updates, http functions).

    So if someone runs into similar problems (architecture hampers use of best practices) I suggest to re-think the architecture. Feels obvious when writing...

    Have fun coding all ^_^