Skip to content

@firebase/rules-unit-testing does not properly clear storage bucketsΒ #5875

Open
@marcfrankel

Description

@marcfrankel

[REQUIRED] Describe your environment

  • Operating System version: Macos 12.0.1
  • Browser version: Brave
  • Firebase SDK version: 9.6.1
  • @firebase/rules-unit-testing version: 2.0.1
  • Firebase Product: @firebase/rules-unit-testing and storage emulator

[REQUIRED] Describe the problem

Using the local emulator and @firebase/rules-unit-testing together can cause a bug where the RulesTestEnvironment's method clearStorage() only clears buckets that are named after the Firebase project ID they were initialized with.

My current workaround is to make several different RulesTestEnvironments with their projectId's set to the buckets I need to be cleared, but I believe this is a bug and the clearStorage() method should clear all the buckets. I'm guessing somewhere in the code someone swapped the idea of projectId and bucket name.

Steps to reproduce:

Relevant Code:

To recreate spin up the local firebase cloud storage emulator and have more than one bucket. They can be named anything (ie bucket_1 & bucket_2) the only important thing is they are a different name than your firebase project id. Using the local emulator upload some files into these buckets. Finally, make a bucket named after your project id and place a file in there as well.

In a typescript/javascript file run something like the following code:

import {
    RulesTestEnvironment,
    initializeTestEnvironment,
} from '@firebase/rules-unit-testing';

process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080';
process.env.FIREBASE_STORAGE_EMULATOR_HOST = 'localhost:9199';

testEnv = await initializeTestEnvironment({
    projectId: 'my-actual-project-id',
});

// other test code here

testEnv.clearStorage(); // This function incorrectly only deletes files from a bucket sharing the name of the project id, not all emulator buckets.

After the code is run only the file in the bucket that shares the name of the project id will be deleted. In my opinion, the way the method description is written the clearStorage() method should delete all the files in the emulator, but maybe I'm incorrect.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions