firebase / firebase/firebase-js-sdk

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

Open
#5,875 4 comments 2 reactions 0 assignees View on GitHub
api: storage needs-attention question testing-sdk
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### [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:
```typescript
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.