12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
+ #import < FirebaseAuth/FirebaseAuth.h>
15
16
#import < FirebaseStorage/FirebaseStorage.h>
16
17
#import < XCTest/XCTest.h>
17
18
32
33
* rules_version = '2';
33
34
* service firebase.storage {
34
35
* match /b/{bucket}/o {
35
- * ...
36
36
* match /ios {
37
37
* match /public/{allPaths=**} {
38
- * allow read, write;
38
+ * allow write: if request.auth != null;
39
+ * allow read: if true;
39
40
* }
40
41
* match /private/{allPaths=**} {
41
- * allow none ;
42
+ * allow read, write: if false ;
42
43
* }
43
44
* }
44
45
* }
49
50
@interface FIRStorageIntegrationTests : XCTestCase
50
51
51
52
@property (strong , nonatomic ) FIRApp *app;
53
+ @property (strong , nonatomic ) FIRAuth *auth;
52
54
@property (strong , nonatomic ) FIRStorage *storage;
53
55
54
56
@end
@@ -63,10 +65,20 @@ - (void)setUp {
63
65
[super setUp ];
64
66
65
67
self.app = [FIRApp defaultApp ];
68
+ self.auth = [FIRAuth authWithApp: self .app];
66
69
self.storage = [FIRStorage storageForApp: self .app];
67
70
68
71
static dispatch_once_t once;
69
72
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
+
70
82
XCTestExpectation *setUpExpectation = [self expectationWithDescription: @" setUp" ];
71
83
72
84
NSArray <NSString *> *largeFiles = @[ @" ios/public/1mb" ];
@@ -122,9 +134,8 @@ - (void)testName {
122
134
XCTAssertEqualObjects (ref.description , aGSURI);
123
135
}
124
136
125
- - (void )testUnauthenticatedGetMetadata {
126
- XCTestExpectation *expectation =
127
- [self expectationWithDescription: @" testUnauthenticatedGetMetadata" ];
137
+ - (void )testGetMetadata {
138
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetMetadata" ];
128
139
FIRStorageReference *ref = [self .storage.reference child: @" ios/public/1mb" ];
129
140
130
141
[ref metadataWithCompletion: ^(FIRStorageMetadata *metadata, NSError *error) {
@@ -136,37 +147,8 @@ - (void)testUnauthenticatedGetMetadata {
136
147
[self waitForExpectations ];
137
148
}
138
149
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" ];
170
152
171
153
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/fileToDelete" ];
172
154
@@ -205,27 +187,8 @@ - (void)testDeleteWithNilCompletion {
205
187
[self waitForExpectations ];
206
188
}
207
189
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" ];
229
192
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/-._~!$'()*,=:@&+;" ];
230
193
231
194
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -241,9 +204,9 @@ - (void)testUnauthenticatedSimplePutSpecialCharacter {
241
204
[self waitForExpectations ];
242
205
}
243
206
244
- - (void )testUnauthenticatedSimplePutDataInBackgroundQueue {
207
+ - (void )testPutDataInBackgroundQueue {
245
208
XCTestExpectation *expectation =
246
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataInBackgroundQueue " ];
209
+ [self expectationWithDescription: @" testPutDataInBackgroundQueue " ];
247
210
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/testBytesUpload" ];
248
211
249
212
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -261,9 +224,8 @@ - (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
261
224
[self waitForExpectations ];
262
225
}
263
226
264
- - (void )testUnauthenticatedSimplePutEmptyData {
265
- XCTestExpectation *expectation =
266
- [self expectationWithDescription: @" testUnauthenticatedSimplePutEmptyData" ];
227
+ - (void )testPutDataWithEmptyData {
228
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutDataWithEmptyData" ];
267
229
268
230
FIRStorageReference *ref =
269
231
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutEmptyData" ];
@@ -281,9 +243,8 @@ - (void)testUnauthenticatedSimplePutEmptyData {
281
243
[self waitForExpectations ];
282
244
}
283
245
284
- - (void )testUnauthenticatedSimplePutDataUnauthorized {
285
- XCTestExpectation *expectation =
286
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataUnauthorized" ];
246
+ - (void )testPutData {
247
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutData" ];
287
248
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/private/secretfile.txt" ];
288
249
289
250
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -300,9 +261,8 @@ - (void)testUnauthenticatedSimplePutDataUnauthorized {
300
261
[self waitForExpectations ];
301
262
}
302
263
303
- - (void )testUnauthenticatedSimplePutFile {
304
- XCTestExpectation *expectation =
305
- [self expectationWithDescription: @" testUnauthenticatedSimplePutFile" ];
264
+ - (void )testPutFile {
265
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutFile" ];
306
266
307
267
FIRStorageReference *ref =
308
268
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutFile" ];
@@ -372,9 +332,8 @@ - (void)testPutFileWithSpecialCharacters {
372
332
[self waitForExpectations ];
373
333
}
374
334
375
- - (void )testUnauthenticatedSimplePutDataNoMetadata {
376
- XCTestExpectation *expectation =
377
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataNoMetadata" ];
335
+ - (void )testPutDataNoMetadata {
336
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutDataNoMetadata" ];
378
337
379
338
FIRStorageReference *ref =
380
339
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutDataNoMetadata" ];
@@ -392,9 +351,8 @@ - (void)testUnauthenticatedSimplePutDataNoMetadata {
392
351
[self waitForExpectations ];
393
352
}
394
353
395
- - (void )testUnauthenticatedSimplePutFileNoMetadata {
396
- XCTestExpectation *expectation =
397
- [self expectationWithDescription: @" testUnauthenticatedSimplePutFileNoMetadata" ];
354
+ - (void )testPutFileNoMetadata {
355
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutFileNoMetadata" ];
398
356
399
357
FIRStorageReference *ref =
400
358
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutFileNoMetadata" ];
@@ -416,9 +374,8 @@ - (void)testUnauthenticatedSimplePutFileNoMetadata {
416
374
[self waitForExpectations ];
417
375
}
418
376
419
- - (void )testUnauthenticatedSimpleGetData {
420
- XCTestExpectation *expectation =
421
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetData" ];
377
+ - (void )testGetData {
378
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetData" ];
422
379
423
380
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
424
381
@@ -432,9 +389,9 @@ - (void)testUnauthenticatedSimpleGetData {
432
389
[self waitForExpectations ];
433
390
}
434
391
435
- - (void )testUnauthenticatedSimpleGetDataInBackgroundQueue {
392
+ - (void )testGetDataInBackgroundQueue {
436
393
XCTestExpectation *expectation =
437
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDataInBackgroundQueue " ];
394
+ [self expectationWithDescription: @" testGetDataInBackgroundQueue " ];
438
395
439
396
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
440
397
@@ -450,9 +407,8 @@ - (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
450
407
[self waitForExpectations ];
451
408
}
452
409
453
- - (void )testUnauthenticatedSimpleGetDataTooSmall {
454
- XCTestExpectation *expectation =
455
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDataTooSmall" ];
410
+ - (void )testGetDataTooSmall {
411
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetDataTooSmall" ];
456
412
457
413
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
458
414
@@ -467,9 +423,8 @@ - (void)testUnauthenticatedSimpleGetDataTooSmall {
467
423
[self waitForExpectations ];
468
424
}
469
425
470
- - (void )testUnauthenticatedSimpleGetDownloadURL {
471
- XCTestExpectation *expectation =
472
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDownloadURL" ];
426
+ - (void )testGetDownloadURL {
427
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetDownloadURL" ];
473
428
474
429
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
475
430
@@ -494,9 +449,8 @@ - (void)testUnauthenticatedSimpleGetDownloadURL {
494
449
[self waitForExpectations ];
495
450
}
496
451
497
- - (void )testUnauthenticatedSimpleGetFile {
498
- XCTestExpectation *expectation =
499
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetFile" ];
452
+ - (void )testGetFile {
453
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetFile" ];
500
454
501
455
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/helloworld" ];
502
456
@@ -639,9 +593,8 @@ - (void)testUpdateMetadata {
639
593
[self waitForExpectations ];
640
594
}
641
595
642
- - (void )testUnauthenticatedResumeGetFile {
643
- XCTestExpectation *expectation =
644
- [self expectationWithDescription: @" testUnauthenticatedResumeGetFile" ];
596
+ - (void )testResumeGetFile {
597
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testResumeGetFile" ];
645
598
646
599
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
647
600
@@ -693,9 +646,9 @@ - (void)testUnauthenticatedResumeGetFile {
693
646
XCTAssertEqualWithAccuracy (sqrt (INT_MAX - 499 ), computationResult, 0.1 );
694
647
}
695
648
696
- - (void )testUnauthenticatedResumeGetFileInBackgroundQueue {
649
+ - (void )testResumeGetFileInBackgroundQueue {
697
650
XCTestExpectation *expectation =
698
- [self expectationWithDescription: @" testUnauthenticatedResumeGetFileInBackgroundQueue " ];
651
+ [self expectationWithDescription: @" testResumeGetFileInBackgroundQueue " ];
699
652
700
653
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
701
654
0 commit comments