# firebase-security-testing

> Testing framework for firestore and firebase storage security rules.

Latest version **0.1.0** (published 2020-04-21) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install firebase-security-testing
pnpm add firebase-security-testing
yarn add firebase-security-testing
bun add firebase-security-testing
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2020-04-21 |
| First published | 2019-03-14 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 17.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Niklas Gögge |
| Maintainers | dergoegge |
| Keywords | firebase, security-rules, testing |

## Links

- npm: https://www.npmjs.com/package/firebase-security-testing
- Homepage: https://github.com/dergoegge/firebase-security-testing
- npm.io page: https://npm.io/package/firebase-security-testing

## Dependencies (2)

- [cli-color](https://npm.io/package/cli-color.md) ^1.4.0
- [firebase-tools](https://npm.io/package/firebase-tools.md) ^7.3.2

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2020-04-21
- 0.0.7 — 2019-09-13
- 0.0.6 — 2019-09-13
- 0.0.5 — 2019-03-15
- 0.0.4 — 2019-03-15
- 0.0.3 — 2019-03-15
- 0.0.2 — 2019-03-14
- 0.0.1 — 2019-03-14

## README

# Firebase security rules testing

There is currently no official testing framework for firebase storage security rules.

There is how ever the [Firebase Rules API](https://developers.google.com/apis-explorer/?hl=en_US#search/firebaserules/firebaserules/v1/) which does provide unit testing functionality.
The simulator in the firebase console makes use of this api.

This repository is an attempt at a client for this api and since the api works for both **Firestore** and **Firebase Storage** you will be able to test both types of security rules with this client.

I also opened a feature request with firebase, so maybe they will realease something like this pretty soon with official support.

## Install
```sh
npm i firebase-security-testing
```

## Setup
In order for this package to work you will have to set the `FIREBASE_TOKEN` environment variable.
You can obtain the token with:
```sh
firebase login:ci
```

## Examples

## 
```javascript
const { RuleTestSuite, validateRuleSuite } = require('firebase-security-testing');

// Initialise the rule test suite
var storageRules = new RuleTestSuite({
	rulePath: 'storage.rules', // path to your rules file
	project: '<project-name>', // your project name
	description: 'storage rules' // optional for logging of results
});

// add a test case
storageRules.test('<description>'/* description for logging */, {
	path: '/b/<bucket-name>/o/path/to/resource',
	method: 'get',
	auth: {
		uid: '...',
		token: {
			'...': '...'
		}
	}
}).shouldSucceed(); // this test case should succeed

// ad another test case
storageRules.test('<description>'/* description for logging */, {
	path: '/b/<bucket-name>/o/path/to/resource',
	method: 'create'
}).shouldFail(); // this test case should fail

// validate the tests
validateRuleSuite(storageRules, { logging: true, exitOnFailure: true });

```

*The `exitOnFailure` option defaults to true.*

## Test case options

The options for the test cases ("as far as i can tell") are the ones listed in the documentation for [firestore request](https://firebase.google.com/docs/reference/rules/rules.firestore.Request), [firestore resource](https://firebase.google.com/docs/reference/rules/rules.firestore.Resource), [storage request](https://firebase.google.com/docs/reference/security/storage/#request), [storage resource](https://firebase.google.com/docs/reference/security/storage/#resource)

## Contributing
Every contribution welcome just open a issue or pr...

---
_Source: https://npm.io/package/firebase-security-testing · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
