Unit testing security rules with the Firebase Emulator Suite

  Рет қаралды 49,263

Firebase

Firebase

Күн бұрын

Пікірлер: 95
@IsaiahSmith
@IsaiahSmith 4 жыл бұрын
I honestly don't comment on KZbin videos much, but Todd, you're videos are always extremely well done and helpful! I just had to share how much I (and I'm sure many others) enjoy the work you do helping everyone learn how to use Firebase in better ways
@agung_laksana
@agung_laksana 2 жыл бұрын
please make a new video, the syntax is no longer valid for the latest npm package
@quangle5701
@quangle5701 3 жыл бұрын
Excellent step-by-step instructions of how to do unit test for cloud firestore with firebase emulator. Thank you very much.
@Firebase
@Firebase 3 жыл бұрын
You are welcome!
@scottmyers6488
@scottmyers6488 4 жыл бұрын
Excellent, the best tutorials ever. Completely generous!
@mmathems395
@mmathems395 Жыл бұрын
Thank you for this one Todd, I went through this a lot today and hopefully it'll see me through what I'm currently stuck on. Nice, clear and very well explained examples. If I may also say, I am still amazed at how you managed to emulate the various circumstances in order to test them, and further amazed by how you'd be sure that the circumstances were being perfectly emulated ... It's coming from me thinking about other circumstances to emulate, and how I could be sure that I have set the circumstances perfectly. Many thanks.
@thepickicool97
@thepickicool97 4 жыл бұрын
While we're here, I'm still wondering why there's no solution from Google for full text search in firestore. Even a separate solution would be okay. Algolia is soooooooo expensive !
@clivehtownsend
@clivehtownsend 4 жыл бұрын
2:14 is pretty much how I live my life.... "Somewhat recent version of Java. I don't actually know what the precise minimum version is. I have XX installed and that seems to work"
@pebuchmann
@pebuchmann 3 жыл бұрын
This video is equally helpful and fun to watch! Be careful not to miss the "await" statement when writing docs as admin to the database because if not this leads to seemingly erratic behaviour.
@LautaroGruss
@LautaroGruss 3 жыл бұрын
AWESOME. Seriously, you explain it so clear! 100!
@Firebase
@Firebase 3 жыл бұрын
Glad it was helpful!
@GeoffreyHale
@GeoffreyHale 3 жыл бұрын
Great tutorial! Thorough and easy to follow. So helpful. Thank you!
@dc5
@dc5 4 жыл бұрын
Awesome video as always, thank you Todd! Looking forward to the next one.
@gavindavis963
@gavindavis963 Жыл бұрын
Is there an updated version of this process. @firebase/testing is deprecated and points to @firebase/rules-unit-testing. However, when I install the latest version of @firebase/rules-unit-testing the code in the video does not work. Specifically 'TypeError: firebase.initializeTestApp is not a function'. I am proceeding with @firebase/rules-unit-testing v1.3.7 as this seems to work. But just wondering if the new process has been explained
@NayanBhakhar-k1x
@NayanBhakhar-k1x Жыл бұрын
I also faced same issue as you mentioned here
@viczking8520
@viczking8520 4 жыл бұрын
anyone know how to fix FirebaseError: Failed to get document because client is offline. I've tried running firebase emulators:start at project level and even test level. The emulator starts at port 5000 correctly and all are online as in on emulator UI. So why does it say that the client is offline!!!!!!!!!!!!!!!
@xujok
@xujok 3 жыл бұрын
Just 1 year later the library has been detracted the API changed and nothing works after update ...
@markgoho
@markgoho 4 жыл бұрын
The MY_PROJECT_ID needs to be exactly the same as what the emulator knows from your local project or changes to security rules will not be picked up
@felippewick
@felippewick 2 жыл бұрын
"Let's just add an email for fun - uh, that was fun. *I need to get out more*" 😂
@theophileavoyne4252
@theophileavoyne4252 3 жыл бұрын
The @firebase/testing package has been deprecated. Could you do a video tutorial explaining how to use @firebase/rules-unit-testing?
@theophileavoyne4252
@theophileavoyne4252 3 жыл бұрын
​@@ToddKerpelmanCorp Looking forward then! Thank's for your valuable videos, you have a real teaching talent.
@chiubaca
@chiubaca 4 жыл бұрын
I'm trying to follow along but I've getting a mocha error Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (..\firebase-auth-testing\tests\test.js)
@9642arvind
@9642arvind 4 жыл бұрын
I got the same error. I resolved it by ensuring my emulator was running using firebase emulators:start
@b0otable
@b0otable 4 жыл бұрын
You need to make sure the emulator is connected. I had the issue as I was running on non-default ports. My changes: 1.) I changed to the updated @firebase/rules-unit-testing 2.) const db = firebase.initializeTestApp({projectId: MY_PROJECT_ID}).firestore(); db.useEmulator("localhost", 8086)
@bartl9798
@bartl9798 3 жыл бұрын
It's a bit confusing that this library got renamed to @firebase/rules-unit-testing because a lot of its functionality seems useful for testing Firebase in general (such as clearing the database).
@mmathems395
@mmathems395 Жыл бұрын
True, and I encountered the same problem earlier today. The solution was to change the version of @firebase/rules-unit-testing to 1.3.15 (the version I saw working within the Google Cloud Shell Editor. After that and reinstalling npm, this video could be followed.
@niklasopf
@niklasopf 3 ай бұрын
This tutorial was fantastic!
@danvilela
@danvilela 4 жыл бұрын
Thank you Todd! Your videos are helping me a LOT!
@Ganeki-san
@Ganeki-san 2 жыл бұрын
Please god update this code to use version 9 SDK, your docs link to this video but your docs literally recommend to ppl to use the version9 instead of this.
@peteredmonds1712
@peteredmonds1712 2 жыл бұрын
This was a great video, but is honestly should probably be removed. This is not the current way to do unit testing in Firebase and the mix of information is confusing
@rachelmmyers
@rachelmmyers 2 жыл бұрын
I think the value proposition of this video is that is explains the moving parts of testing Security Rules using the Emulator Suite. Our libraries will evolve, and documentation will always be more up to date than videos.
@nikolairivas9615
@nikolairivas9615 2 жыл бұрын
@@rachelmmyers I think it would be helpful to provide a sample file with the new library setup process as opposed to the random code snippets that are provided in the documentation. For those who already know the mechanics of this stuff, the code snippets may be adequate, but I believe most people who turn to KZbin for help are beginners and thus have little-to-no experience with setting up a test suite. If anything, I think it would be helpful to provide a short video explaining the new setup, as the rest of the process seems relatively unchanged.
@startover305
@startover305 5 ай бұрын
Does anybody where the next episode is 🤔? The playlist doesn’t seem to have the matching content mentioned in the video, like list
@kishan02patel
@kishan02patel 4 жыл бұрын
At 2:33 the command should be `npm i -g firebase-tools`. You might also need to add `sudo` in front of it. Thanks for the video!
@dharmarajr24
@dharmarajr24 4 жыл бұрын
I have watched this somewhere... Like yesterday XD ... But watching Todd again n again is fun n his lessons are interesting
@stoem
@stoem 4 жыл бұрын
I cannot get past the Java dependency for the emulators. I had to install Java on my Mac, found that appears to be the latest version jre-8u261-macosx-x64.dmg which then gives me java version "1.6.0_65" in the Terminal whilst the emulator insists on 1.8 or higher. Setting this up is a rabbit hole inside a rabbit hole.
@piotrkucuyma2342
@piotrkucuyma2342 3 жыл бұрын
05:34 I would love to know more about the "kraken-control-panel" project on the list though.
@chuguloco
@chuguloco 4 жыл бұрын
Could you please give me the link to the video refered in 12:04?
@b0otable
@b0otable 4 жыл бұрын
A lot of this does not work when using WSL
@nicolapigozzo
@nicolapigozzo 4 жыл бұрын
#askFirebase am i wrong or map fields are not supported on the new security rules? why can't I map a field like this: allow create: if !('userDetails.status' in incomingData());
@nicolapigozzo
@nicolapigozzo 4 жыл бұрын
btw @RachelMyers #askFirebase you have an error on your last blog post, please remove the bracket: allow create: if request.resource.data.keys().toSet() .hasOnly(["required","and","optional","keys"]). firebase.googleblog.com/2020/06/new-firestore-security-rules-features.html
@mjonausk
@mjonausk 3 жыл бұрын
Hmmm the assertSucceds and assertFails did not seem to work for me. I had to write my own little functions const isDocumentAccessible = async (db, path: string): Promise => { let isAccessible: boolean = true; try { await db.doc("/business/ABNMJ/expenses/2020/quarters/qtr1/items/item1").get(); } catch { isAccessible = false; } return isAccessible; };
@hugobotas8447
@hugobotas8447 4 жыл бұрын
Can't wait for the next one!
@enlightened_monkey8767
@enlightened_monkey8767 4 жыл бұрын
firebase real time database is not working in india from sep3 2020 and still there is no response from firebase team
@the_potato_god12
@the_potato_god12 3 жыл бұрын
The codelab isn't available anymore?
@albertgao7256
@albertgao7256 2 жыл бұрын
super good topic!!! guess i can do the same thing to test my realtime db validation as well!
@StanleySathler
@StanleySathler Жыл бұрын
Great video, Todd, thanks! I wish Google just updated their tutorials as they update the codebase - turns out `@firebase/testing` is now deprecated and we should use `@firebase/rules-unit-testing` instead
@MrPeter7e
@MrPeter7e 4 жыл бұрын
hi what happened with the pathway "Validate app behavior and verify security rules with Firebase Emulators"? I could completed it in google.dev, but I do not find it now.
@rubenheymans1988
@rubenheymans1988 3 жыл бұрын
how can you use the playground to test with multiple tenants?
@MaximilianBeck
@MaximilianBeck 4 жыл бұрын
Great introduction! Can you expand on when to use what project id for initialisation of the test sdk?
@duanehodges3146
@duanehodges3146 4 жыл бұрын
Is there a way to add thousands of documents to firestore for testing purposes?
@ryansampson7221
@ryansampson7221 Жыл бұрын
Darn. This video is severly outdated. Worst of all, its what the official docs point to still.
@StanleySathler
@StanleySathler Жыл бұрын
Classic Google style unfortunatelly.
@luthiers5488
@luthiers5488 4 жыл бұрын
Please make more videos on this topic, like for example when a document is updated/deleted
@antuancaraballo9691
@antuancaraballo9691 4 жыл бұрын
Very valuable, thank you for sharing!
@carlosaltamera353
@carlosaltamera353 4 жыл бұрын
This is just excellent. Thanks!
@mattnicolls5253
@mattnicolls5253 3 жыл бұрын
Can you please provide a link to the end working code in the description
@georgedicu7397
@georgedicu7397 2 жыл бұрын
Is there any flutter/dart examples?
@StephenMoreira
@StephenMoreira 4 жыл бұрын
This was gold. Thanks.
@Ondal1
@Ondal1 4 жыл бұрын
I'm really missing something like this for firebase function acting as triggers for CUD operations. Particularly when testing collection modifications which result in other collection documents being changed. Currently I can only get it working with ONE document change, where the code which should delete the database doesn't do so.
@9642arvind
@9642arvind 4 жыл бұрын
Could you also share best practices on splitting the code in the firestore.rules file and the test.js file
@davidtheprogrammer
@davidtheprogrammer 4 жыл бұрын
Was looking for this. Can't find anything on this
@jerrythomas8727
@jerrythomas8727 4 жыл бұрын
Can we use firebase emulators to test authentication also? If yes how?
@abderraoufsalah4371
@abderraoufsalah4371 3 жыл бұрын
What about realtime database
@nussknacker2719
@nussknacker2719 4 жыл бұрын
How can I test a query (list)?
@Norfeldt
@Norfeldt 4 жыл бұрын
Great video as always Todd 👏 Perhaps you could show how to setup a CI with the emulator (would be nice if it was using GitHub actions)?
@chuguloco
@chuguloco 4 жыл бұрын
Excellent tutorial!!!
@AdamBeguelin
@AdamBeguelin 4 жыл бұрын
I want my app to be able to create documents but not read or write those documents once they are created. Is this possible? I'm using cloud functions to process the documents but don't want the app to be able to come back and update the document, even if it's the owner of the document.
@cottz6718
@cottz6718 4 жыл бұрын
Hi Adam, you can make a rule like if the data coming is the same as the data in the database, in that case is impossible to change the original data.
@mattfrowe7697
@mattfrowe7697 4 жыл бұрын
Great tutorial, thank you!
@VladimirBrasil
@VladimirBrasil 4 жыл бұрын
Beautiful video: huge congrats! Functions will be nice to learn to test, probably in a future video. Pubsub as well, but maybe less users would appreciate (I would).
@9642arvind
@9642arvind 4 жыл бұрын
Thanks for the wonderful video! Please help me with this use case - I have a restaurant collection with restaurant documents. 1) Certain fields in this document (like restaurant name, timings, etc) can be updated by owners or by admin users with special custom claims. 2) Certain fields (like ratings, popularity, visit count) CAN NOT be updated by any user (will be updated using cloud functions). 3) Certain fields (like internal flags) can only be updated by users with the special custom claim and not by owners. Thank you for your response!
@YousefSh
@YousefSh 3 жыл бұрын
I'm confused. You imported the firebase admin SDK to add a document to the firestore running in the emulator. Then how would use you use the admin SDK to add a document to the production database?
@YousefSh
@YousefSh 3 жыл бұрын
Like, you didn't add any config to the admin SDK telling it whether to write data to the emulator or the production SDK. So why did it go to the emulator by default?
@YousefSh
@YousefSh 3 жыл бұрын
@@ToddKerpelmanCorp Ah. Environment Variables. Thank you!
@isaacworsley1941
@isaacworsley1941 4 жыл бұрын
Request for a video helping with Firestore security rules coverage?
@vballaddict75252
@vballaddict75252 3 жыл бұрын
Hint: DON'T type a rule description as "if(...)" instead of "it(...)" because (a) it won't show up as an error and (b) it'll be difficult to track down! LOL
@argada
@argada 4 жыл бұрын
Excellent video! Question, what would be an elegant way to ensure the emulator starts and is available for use prior to proceeding with test execution?
@bartl9798
@bartl9798 3 жыл бұрын
Use firebase emulators:exec "test command"
@ashtonthomas3474
@ashtonthomas3474 4 жыл бұрын
I think you wanted `npm i -g firebase-tools` and not `npm -i g firebase-tools` @2:30
@AndreiNedelus
@AndreiNedelus 4 жыл бұрын
I'm wondering how you set-up the firebase rules with a framework like react
@dahnmaier4773
@dahnmaier4773 4 жыл бұрын
Same. They are framework agnostic (firebase init). You can run the same tests with jest.
@clivehtownsend
@clivehtownsend 4 жыл бұрын
Also, 2:23 should read ```npm i g firebase-tools``` instead of ```npm -i g firebase-tools``` Thanks for the video!
@yannneq
@yannneq 4 жыл бұрын
Great video, i have been looking for something like this! The rule at 21:47 did not work form me, though. allow read: if (request.auth.uid == resource.data.userId) i had to use this instead: allow read: if (request.auth.uid == request.resource.data.userId)
@YousefSh
@YousefSh 3 жыл бұрын
Is this possible for storage rules too?
@YousefSh
@YousefSh 3 жыл бұрын
Meaning, running unit tests against the rules?
@topgeargaming8679
@topgeargaming8679 4 жыл бұрын
What do u mean by "if true" and "if false" why not just "true" and "false".
@JulienReszka
@JulienReszka 3 жыл бұрын
Firebase/testing is deprecated, use @firebase/rules-unit-testing
@miguelchavez8690
@miguelchavez8690 4 жыл бұрын
I cannot pass to kzbin.info/www/bejne/jHXYnamcd9WtkKc I keep getting this error after I ran the emulators, cant find a solution, any ideas? @firebase/firestore: Firestore (7.16.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connection droppedThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend. My internet connection seems fine, thanks!
@gootrizotti
@gootrizotti 4 жыл бұрын
The same issue here
@theanswer1993
@theanswer1993 Жыл бұрын
Aren't these integration tests?
@dharmarajr24
@dharmarajr24 4 жыл бұрын
No no .. it was not firecast series XD
Intermediate topics in Firebase Security Rules - Firecasts
29:37
Security Rules! 🔑 | Get to know Cloud Firestore #6
22:39
Firebase
Рет қаралды 276 М.
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 19 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 135 МЛН
Noodles Eating Challenge, So Magical! So Much Fun#Funnyfamily #Partygames #Funny
00:33
I tried 5 Firebase alternatives
10:31
Fireship
Рет қаралды 811 М.
Cloud Firestore Data Modeling (Google I/O'19)
40:37
Firebase
Рет қаралды 174 М.
The Local Firebase Emulator UI in 15 minutes
14:16
Firebase
Рет қаралды 121 М.
Security Rules deep dive
12:09
Firebase
Рет қаралды 18 М.
Testing In React Tutorial - Jest and React Testing Library
21:28
🚀  TDD, Where Did It All Go Wrong (Ian Cooper)
1:03:55
DevTernity Conference
Рет қаралды 569 М.
How do Cloud Functions work? | Get to know Cloud Firestore #11
18:21
DHH discusses SQLite (and Stoicism)
54:00
Aaron Francis
Рет қаралды 101 М.
Firestore Security Rules - How to Hack a Firebase App
10:05
Fireship
Рет қаралды 132 М.
Cloud Firestore Pricing | Get to know Cloud Firestore #3
16:23
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 19 МЛН