Skip to content

Commit c3a1e88

Browse files
Use secure rules for Firebase Storage Integration tests
1 parent b168519 commit c3a1e88

File tree

3 files changed

+59
-99
lines changed

3 files changed

+59
-99
lines changed

FirebaseStorage.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas
5252
int_tests.requires_app_host = true
5353
int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat',
5454
'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist'
55+
int_tests.dependency 'FirebaseAuth', '~> 6.5'
5556
end
5657

5758
s.test_spec 'swift-integration' do |swift_int_tests|
@@ -60,5 +61,6 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas
6061
swift_int_tests.requires_app_host = true
6162
swift_int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat',
6263
'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist'
64+
swift_int_tests.dependency 'FirebaseAuth', '~> 6.5'
6365
end
6466
end

FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m

Lines changed: 56 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#import <FirebaseAuth/FirebaseAuth.h>
1516
#import <FirebaseStorage/FirebaseStorage.h>
1617
#import <XCTest/XCTest.h>
1718

@@ -23,32 +24,37 @@
2324
/**
2425
* Firebase Storage Integration tests
2526
*
26-
* To run these tests, you need to define the following access rights for your Firebase App:
27-
* - unauthentication read/write access to /ios/public
28-
* - authentication read/write access to /ios/private
29-
*
30-
* A sample configuration may look like:
27+
* To run these tests, you need to define the following access rights:
3128
*
3229
* rules_version = '2';
3330
* service firebase.storage {
3431
* match /b/{bucket}/o {
35-
* ...
3632
* match /ios {
3733
* match /public/{allPaths=**} {
38-
* allow read, write;
34+
* allow write: if request.auth != null;
35+
* allow read: if true;
3936
* }
4037
* match /private/{allPaths=**} {
41-
* allow none;
38+
* allow read, write: if false;
4239
* }
4340
* }
4441
* }
4542
* }
4643
*
44+
* You also need to enable email/password sign in and add a test user in your
45+
* Firebase Authentication settings. Your account credentials need to match
46+
* the credentials defined in `kTestUser` and `kTestPassword`.
47+
*
4748
* You can define these access rights in the Firebase Console of your project.
4849
*/
50+
51+
NSString *const kTestUser = @"[email protected]";
52+
NSString *const kTestPassword = @"testing";
53+
4954
@interface FIRStorageIntegrationTests : XCTestCase
5055

5156
@property(strong, nonatomic) FIRApp *app;
57+
@property(strong, nonatomic) FIRAuth *auth;
5258
@property(strong, nonatomic) FIRStorage *storage;
5359

5460
@end
@@ -63,10 +69,20 @@ - (void)setUp {
6369
[super setUp];
6470

6571
self.app = [FIRApp defaultApp];
72+
self.auth = [FIRAuth authWithApp:self.app];
6673
self.storage = [FIRStorage storageForApp:self.app];
6774

6875
static dispatch_once_t once;
6976
dispatch_once(&once, ^{
77+
XCTestExpectation *logInExpectation = [self expectationWithDescription:@"login"];
78+
[self.auth signInWithEmail:kTestUser
79+
password:kTestPassword
80+
completion:^(FIRAuthDataResult *result, NSError *error) {
81+
XCTAssertNil(error);
82+
[logInExpectation fulfill];
83+
}];
84+
[self waitForExpectations];
85+
7086
XCTestExpectation *setUpExpectation = [self expectationWithDescription:@"setUp"];
7187

7288
NSArray<NSString *> *largeFiles = @[ @"ios/public/1mb" ];
@@ -122,9 +138,8 @@ - (void)testName {
122138
XCTAssertEqualObjects(ref.description, aGSURI);
123139
}
124140

125-
- (void)testUnauthenticatedGetMetadata {
126-
XCTestExpectation *expectation =
127-
[self expectationWithDescription:@"testUnauthenticatedGetMetadata"];
141+
- (void)testGetMetadata {
142+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetMetadata"];
128143
FIRStorageReference *ref = [self.storage.reference child:@"ios/public/1mb"];
129144

130145
[ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) {
@@ -136,37 +151,8 @@ - (void)testUnauthenticatedGetMetadata {
136151
[self waitForExpectations];
137152
}
138153

139-
- (void)testUnauthenticatedUpdateMetadata {
140-
XCTestExpectation *expectation =
141-
[self expectationWithDescription:@"testUnauthenticatedUpdateMetadata"];
142-
143-
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
144-
145-
FIRStorageMetadata *meta = [[FIRStorageMetadata alloc] init];
146-
[meta setContentType:@"lol/custom"];
147-
[meta setCustomMetadata:@{
148-
@"lol" : @"custom metadata is neat",
149-
@"ちかてつ" : @"🚇",
150-
@"shinkansen" : @"新幹線"
151-
}];
152-
153-
[ref updateMetadata:meta
154-
completion:^(FIRStorageMetadata *metadata, NSError *error) {
155-
XCTAssertEqualObjects(meta.contentType, metadata.contentType);
156-
XCTAssertEqualObjects(meta.customMetadata[@"lol"], metadata.customMetadata[@"lol"]);
157-
XCTAssertEqualObjects(meta.customMetadata[@"ちかてつ"],
158-
metadata.customMetadata[@"ちかてつ"]);
159-
XCTAssertEqualObjects(meta.customMetadata[@"shinkansen"],
160-
metadata.customMetadata[@"shinkansen"]);
161-
XCTAssertNil(error, "Error should be nil");
162-
[expectation fulfill];
163-
}];
164-
165-
[self waitForExpectations];
166-
}
167-
168-
- (void)testUnauthenticatedDelete {
169-
XCTestExpectation *expectation = [self expectationWithDescription:@"testUnauthenticatedDelete"];
154+
- (void)testDelete {
155+
XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"];
170156

171157
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/fileToDelete"];
172158

@@ -205,27 +191,8 @@ - (void)testDeleteWithNilCompletion {
205191
[self waitForExpectations];
206192
}
207193

208-
- (void)testUnauthenticatedSimplePutData {
209-
XCTestExpectation *expectation =
210-
[self expectationWithDescription:@"testUnauthenticatedSimplePutData"];
211-
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testBytesUpload"];
212-
213-
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
214-
215-
[ref putData:data
216-
metadata:nil
217-
completion:^(FIRStorageMetadata *metadata, NSError *error) {
218-
XCTAssertNotNil(metadata, "Metadata should not be nil");
219-
XCTAssertNil(error, "Error should be nil");
220-
[expectation fulfill];
221-
}];
222-
223-
[self waitForExpectations];
224-
}
225-
226-
- (void)testUnauthenticatedSimplePutSpecialCharacter {
227-
XCTestExpectation *expectation =
228-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataEscapedName"];
194+
- (void)testPutDataSpecialCharacter {
195+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataSpecialCharacter"];
229196
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/-._~!$'()*,=:@&+;"];
230197

231198
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -241,9 +208,9 @@ - (void)testUnauthenticatedSimplePutSpecialCharacter {
241208
[self waitForExpectations];
242209
}
243210

244-
- (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
211+
- (void)testPutDataInBackgroundQueue {
245212
XCTestExpectation *expectation =
246-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataInBackgroundQueue"];
213+
[self expectationWithDescription:@"testPutDataInBackgroundQueue"];
247214
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testBytesUpload"];
248215

249216
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -261,9 +228,8 @@ - (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
261228
[self waitForExpectations];
262229
}
263230

264-
- (void)testUnauthenticatedSimplePutEmptyData {
265-
XCTestExpectation *expectation =
266-
[self expectationWithDescription:@"testUnauthenticatedSimplePutEmptyData"];
231+
- (void)testPutDataWithEmptyData {
232+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataWithEmptyData"];
267233

268234
FIRStorageReference *ref =
269235
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutEmptyData"];
@@ -281,9 +247,8 @@ - (void)testUnauthenticatedSimplePutEmptyData {
281247
[self waitForExpectations];
282248
}
283249

284-
- (void)testUnauthenticatedSimplePutDataUnauthorized {
285-
XCTestExpectation *expectation =
286-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataUnauthorized"];
250+
- (void)testPutData {
251+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutData"];
287252
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/private/secretfile.txt"];
288253

289254
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -300,9 +265,8 @@ - (void)testUnauthenticatedSimplePutDataUnauthorized {
300265
[self waitForExpectations];
301266
}
302267

303-
- (void)testUnauthenticatedSimplePutFile {
304-
XCTestExpectation *expectation =
305-
[self expectationWithDescription:@"testUnauthenticatedSimplePutFile"];
268+
- (void)testPutFile {
269+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFile"];
306270

307271
FIRStorageReference *ref =
308272
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFile"];
@@ -372,9 +336,8 @@ - (void)testPutFileWithSpecialCharacters {
372336
[self waitForExpectations];
373337
}
374338

375-
- (void)testUnauthenticatedSimplePutDataNoMetadata {
376-
XCTestExpectation *expectation =
377-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataNoMetadata"];
339+
- (void)testPutDataNoMetadata {
340+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataNoMetadata"];
378341

379342
FIRStorageReference *ref =
380343
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutDataNoMetadata"];
@@ -392,9 +355,8 @@ - (void)testUnauthenticatedSimplePutDataNoMetadata {
392355
[self waitForExpectations];
393356
}
394357

395-
- (void)testUnauthenticatedSimplePutFileNoMetadata {
396-
XCTestExpectation *expectation =
397-
[self expectationWithDescription:@"testUnauthenticatedSimplePutFileNoMetadata"];
358+
- (void)testPutFileNoMetadata {
359+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFileNoMetadata"];
398360

399361
FIRStorageReference *ref =
400362
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFileNoMetadata"];
@@ -416,9 +378,8 @@ - (void)testUnauthenticatedSimplePutFileNoMetadata {
416378
[self waitForExpectations];
417379
}
418380

419-
- (void)testUnauthenticatedSimpleGetData {
420-
XCTestExpectation *expectation =
421-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetData"];
381+
- (void)testGetData {
382+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetData"];
422383

423384
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
424385

@@ -432,9 +393,9 @@ - (void)testUnauthenticatedSimpleGetData {
432393
[self waitForExpectations];
433394
}
434395

435-
- (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
396+
- (void)testGetDataInBackgroundQueue {
436397
XCTestExpectation *expectation =
437-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDataInBackgroundQueue"];
398+
[self expectationWithDescription:@"testGetDataInBackgroundQueue"];
438399

439400
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
440401

@@ -450,9 +411,8 @@ - (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
450411
[self waitForExpectations];
451412
}
452413

453-
- (void)testUnauthenticatedSimpleGetDataTooSmall {
454-
XCTestExpectation *expectation =
455-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDataTooSmall"];
414+
- (void)testGetDataTooSmall {
415+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDataTooSmall"];
456416

457417
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
458418

@@ -467,9 +427,8 @@ - (void)testUnauthenticatedSimpleGetDataTooSmall {
467427
[self waitForExpectations];
468428
}
469429

470-
- (void)testUnauthenticatedSimpleGetDownloadURL {
471-
XCTestExpectation *expectation =
472-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDownloadURL"];
430+
- (void)testGetDownloadURL {
431+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDownloadURL"];
473432

474433
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
475434

@@ -494,9 +453,8 @@ - (void)testUnauthenticatedSimpleGetDownloadURL {
494453
[self waitForExpectations];
495454
}
496455

497-
- (void)testUnauthenticatedSimpleGetFile {
498-
XCTestExpectation *expectation =
499-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetFile"];
456+
- (void)testGetFile {
457+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetFile"];
500458

501459
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/helloworld"];
502460

@@ -639,9 +597,8 @@ - (void)testUpdateMetadata {
639597
[self waitForExpectations];
640598
}
641599

642-
- (void)testUnauthenticatedResumeGetFile {
643-
XCTestExpectation *expectation =
644-
[self expectationWithDescription:@"testUnauthenticatedResumeGetFile"];
600+
- (void)testResumeGetFile {
601+
XCTestExpectation *expectation = [self expectationWithDescription:@"testResumeGetFile"];
645602

646603
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
647604

@@ -693,9 +650,9 @@ - (void)testUnauthenticatedResumeGetFile {
693650
XCTAssertEqualWithAccuracy(sqrt(INT_MAX - 499), computationResult, 0.1);
694651
}
695652

696-
- (void)testUnauthenticatedResumeGetFileInBackgroundQueue {
653+
- (void)testResumeGetFileInBackgroundQueue {
697654
XCTestExpectation *expectation =
698-
[self expectationWithDescription:@"testUnauthenticatedResumeGetFileInBackgroundQueue"];
655+
[self expectationWithDescription:@"testResumeGetFileInBackgroundQueue"];
699656

700657
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
701658

scripts/style.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ s%^./%%
138138
\%^build/% d
139139
\%^Debug/% d
140140
\%^Release/% d
141+
\%^cmake-build-debug/% d
141142
142143
# pod gen output
143144
\%^gen/% d

0 commit comments

Comments
 (0)