Skip to content

Commit 1bf2c81

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

File tree

3 files changed

+50
-94
lines changed

3 files changed

+50
-94
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: 47 additions & 94 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

@@ -32,13 +33,13 @@
3233
* rules_version = '2';
3334
* service firebase.storage {
3435
* match /b/{bucket}/o {
35-
* ...
3636
* match /ios {
3737
* match /public/{allPaths=**} {
38-
* allow read, write;
38+
* allow write: if request.auth != null;
39+
* allow read: if true;
3940
* }
4041
* match /private/{allPaths=**} {
41-
* allow none;
42+
* allow read, write: if false;
4243
* }
4344
* }
4445
* }
@@ -49,6 +50,7 @@
4950
@interface FIRStorageIntegrationTests : XCTestCase
5051

5152
@property(strong, nonatomic) FIRApp *app;
53+
@property(strong, nonatomic) FIRAuth *auth;
5254
@property(strong, nonatomic) FIRStorage *storage;
5355

5456
@end
@@ -63,10 +65,20 @@ - (void)setUp {
6365
[super setUp];
6466

6567
self.app = [FIRApp defaultApp];
68+
self.auth = [FIRAuth authWithApp:self.app];
6669
self.storage = [FIRStorage storageForApp:self.app];
6770

6871
static dispatch_once_t once;
6972
dispatch_once(&once, ^{
73+
XCTestExpectation *logInExpectation = [self expectationWithDescription:@"login"];
74+
[self.auth signInWithEmail:@"[email protected]"
75+
password:@"testing"
76+
completion:^(FIRAuthDataResult *result, NSError *error) {
77+
XCTAssertNil(error);
78+
[logInExpectation fulfill];
79+
}];
80+
[self waitForExpectations];
81+
7082
XCTestExpectation *setUpExpectation = [self expectationWithDescription:@"setUp"];
7183

7284
NSArray<NSString *> *largeFiles = @[ @"ios/public/1mb" ];
@@ -122,9 +134,8 @@ - (void)testName {
122134
XCTAssertEqualObjects(ref.description, aGSURI);
123135
}
124136

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

130141
[ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) {
@@ -136,37 +147,8 @@ - (void)testUnauthenticatedGetMetadata {
136147
[self waitForExpectations];
137148
}
138149

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"];
150+
- (void)testDelete {
151+
XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"];
170152

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

@@ -205,27 +187,8 @@ - (void)testDeleteWithNilCompletion {
205187
[self waitForExpectations];
206188
}
207189

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"];
190+
- (void)testPutDataSpecialCharacter {
191+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataSpecialCharacter"];
229192
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/-._~!$'()*,=:@&+;"];
230193

231194
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -241,9 +204,9 @@ - (void)testUnauthenticatedSimplePutSpecialCharacter {
241204
[self waitForExpectations];
242205
}
243206

244-
- (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
207+
- (void)testPutDataInBackgroundQueue {
245208
XCTestExpectation *expectation =
246-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataInBackgroundQueue"];
209+
[self expectationWithDescription:@"testPutDataInBackgroundQueue"];
247210
FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testBytesUpload"];
248211

249212
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -261,9 +224,8 @@ - (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
261224
[self waitForExpectations];
262225
}
263226

264-
- (void)testUnauthenticatedSimplePutEmptyData {
265-
XCTestExpectation *expectation =
266-
[self expectationWithDescription:@"testUnauthenticatedSimplePutEmptyData"];
227+
- (void)testPutDataWithEmptyData {
228+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataWithEmptyData"];
267229

268230
FIRStorageReference *ref =
269231
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutEmptyData"];
@@ -281,9 +243,8 @@ - (void)testUnauthenticatedSimplePutEmptyData {
281243
[self waitForExpectations];
282244
}
283245

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

289250
NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding];
@@ -300,9 +261,8 @@ - (void)testUnauthenticatedSimplePutDataUnauthorized {
300261
[self waitForExpectations];
301262
}
302263

303-
- (void)testUnauthenticatedSimplePutFile {
304-
XCTestExpectation *expectation =
305-
[self expectationWithDescription:@"testUnauthenticatedSimplePutFile"];
264+
- (void)testPutFile {
265+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFile"];
306266

307267
FIRStorageReference *ref =
308268
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFile"];
@@ -372,9 +332,8 @@ - (void)testPutFileWithSpecialCharacters {
372332
[self waitForExpectations];
373333
}
374334

375-
- (void)testUnauthenticatedSimplePutDataNoMetadata {
376-
XCTestExpectation *expectation =
377-
[self expectationWithDescription:@"testUnauthenticatedSimplePutDataNoMetadata"];
335+
- (void)testPutDataNoMetadata {
336+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataNoMetadata"];
378337

379338
FIRStorageReference *ref =
380339
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutDataNoMetadata"];
@@ -392,9 +351,8 @@ - (void)testUnauthenticatedSimplePutDataNoMetadata {
392351
[self waitForExpectations];
393352
}
394353

395-
- (void)testUnauthenticatedSimplePutFileNoMetadata {
396-
XCTestExpectation *expectation =
397-
[self expectationWithDescription:@"testUnauthenticatedSimplePutFileNoMetadata"];
354+
- (void)testPutFileNoMetadata {
355+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFileNoMetadata"];
398356

399357
FIRStorageReference *ref =
400358
[self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFileNoMetadata"];
@@ -416,9 +374,8 @@ - (void)testUnauthenticatedSimplePutFileNoMetadata {
416374
[self waitForExpectations];
417375
}
418376

419-
- (void)testUnauthenticatedSimpleGetData {
420-
XCTestExpectation *expectation =
421-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetData"];
377+
- (void)testGetData {
378+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetData"];
422379

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

@@ -432,9 +389,9 @@ - (void)testUnauthenticatedSimpleGetData {
432389
[self waitForExpectations];
433390
}
434391

435-
- (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
392+
- (void)testGetDataInBackgroundQueue {
436393
XCTestExpectation *expectation =
437-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDataInBackgroundQueue"];
394+
[self expectationWithDescription:@"testGetDataInBackgroundQueue"];
438395

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

@@ -450,9 +407,8 @@ - (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
450407
[self waitForExpectations];
451408
}
452409

453-
- (void)testUnauthenticatedSimpleGetDataTooSmall {
454-
XCTestExpectation *expectation =
455-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDataTooSmall"];
410+
- (void)testGetDataTooSmall {
411+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDataTooSmall"];
456412

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

@@ -467,9 +423,8 @@ - (void)testUnauthenticatedSimpleGetDataTooSmall {
467423
[self waitForExpectations];
468424
}
469425

470-
- (void)testUnauthenticatedSimpleGetDownloadURL {
471-
XCTestExpectation *expectation =
472-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetDownloadURL"];
426+
- (void)testGetDownloadURL {
427+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDownloadURL"];
473428

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

@@ -494,9 +449,8 @@ - (void)testUnauthenticatedSimpleGetDownloadURL {
494449
[self waitForExpectations];
495450
}
496451

497-
- (void)testUnauthenticatedSimpleGetFile {
498-
XCTestExpectation *expectation =
499-
[self expectationWithDescription:@"testUnauthenticatedSimpleGetFile"];
452+
- (void)testGetFile {
453+
XCTestExpectation *expectation = [self expectationWithDescription:@"testGetFile"];
500454

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

@@ -639,9 +593,8 @@ - (void)testUpdateMetadata {
639593
[self waitForExpectations];
640594
}
641595

642-
- (void)testUnauthenticatedResumeGetFile {
643-
XCTestExpectation *expectation =
644-
[self expectationWithDescription:@"testUnauthenticatedResumeGetFile"];
596+
- (void)testResumeGetFile {
597+
XCTestExpectation *expectation = [self expectationWithDescription:@"testResumeGetFile"];
645598

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

@@ -693,9 +646,9 @@ - (void)testUnauthenticatedResumeGetFile {
693646
XCTAssertEqualWithAccuracy(sqrt(INT_MAX - 499), computationResult, 0.1);
694647
}
695648

696-
- (void)testUnauthenticatedResumeGetFileInBackgroundQueue {
649+
- (void)testResumeGetFileInBackgroundQueue {
697650
XCTestExpectation *expectation =
698-
[self expectationWithDescription:@"testUnauthenticatedResumeGetFileInBackgroundQueue"];
651+
[self expectationWithDescription:@"testResumeGetFileInBackgroundQueue"];
699652

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

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)