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
23
24
/* *
24
25
* Firebase Storage Integration tests
25
26
*
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:
31
28
*
32
29
* rules_version = '2';
33
30
* service firebase.storage {
34
31
* match /b/{bucket}/o {
35
- * ...
36
32
* match /ios {
37
33
* match /public/{allPaths=**} {
38
- * allow read, write;
34
+ * allow write: if request.auth != null;
35
+ * allow read: if true;
39
36
* }
40
37
* match /private/{allPaths=**} {
41
- * allow none ;
38
+ * allow read, write: if false ;
42
39
* }
43
40
* }
44
41
* }
45
42
* }
46
43
*
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
+ *
47
48
* You can define these access rights in the Firebase Console of your project.
48
49
*/
50
+
51
+ NSString *
const kTestUser =
@" [email protected] " ;
52
+ NSString *const kTestPassword = @" testing" ;
53
+
49
54
@interface FIRStorageIntegrationTests : XCTestCase
50
55
51
56
@property (strong , nonatomic ) FIRApp *app;
57
+ @property (strong , nonatomic ) FIRAuth *auth;
52
58
@property (strong , nonatomic ) FIRStorage *storage;
53
59
54
60
@end
@@ -63,10 +69,20 @@ - (void)setUp {
63
69
[super setUp ];
64
70
65
71
self.app = [FIRApp defaultApp ];
72
+ self.auth = [FIRAuth authWithApp: self .app];
66
73
self.storage = [FIRStorage storageForApp: self .app];
67
74
68
75
static dispatch_once_t once;
69
76
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
+
70
86
XCTestExpectation *setUpExpectation = [self expectationWithDescription: @" setUp" ];
71
87
72
88
NSArray <NSString *> *largeFiles = @[ @" ios/public/1mb" ];
@@ -122,9 +138,8 @@ - (void)testName {
122
138
XCTAssertEqualObjects (ref.description , aGSURI);
123
139
}
124
140
125
- - (void )testUnauthenticatedGetMetadata {
126
- XCTestExpectation *expectation =
127
- [self expectationWithDescription: @" testUnauthenticatedGetMetadata" ];
141
+ - (void )testGetMetadata {
142
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetMetadata" ];
128
143
FIRStorageReference *ref = [self .storage.reference child: @" ios/public/1mb" ];
129
144
130
145
[ref metadataWithCompletion: ^(FIRStorageMetadata *metadata, NSError *error) {
@@ -136,37 +151,8 @@ - (void)testUnauthenticatedGetMetadata {
136
151
[self waitForExpectations ];
137
152
}
138
153
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" ];
170
156
171
157
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/fileToDelete" ];
172
158
@@ -205,27 +191,8 @@ - (void)testDeleteWithNilCompletion {
205
191
[self waitForExpectations ];
206
192
}
207
193
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" ];
229
196
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/-._~!$'()*,=:@&+;" ];
230
197
231
198
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -241,9 +208,9 @@ - (void)testUnauthenticatedSimplePutSpecialCharacter {
241
208
[self waitForExpectations ];
242
209
}
243
210
244
- - (void )testUnauthenticatedSimplePutDataInBackgroundQueue {
211
+ - (void )testPutDataInBackgroundQueue {
245
212
XCTestExpectation *expectation =
246
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataInBackgroundQueue " ];
213
+ [self expectationWithDescription: @" testPutDataInBackgroundQueue " ];
247
214
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/testBytesUpload" ];
248
215
249
216
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -261,9 +228,8 @@ - (void)testUnauthenticatedSimplePutDataInBackgroundQueue {
261
228
[self waitForExpectations ];
262
229
}
263
230
264
- - (void )testUnauthenticatedSimplePutEmptyData {
265
- XCTestExpectation *expectation =
266
- [self expectationWithDescription: @" testUnauthenticatedSimplePutEmptyData" ];
231
+ - (void )testPutDataWithEmptyData {
232
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutDataWithEmptyData" ];
267
233
268
234
FIRStorageReference *ref =
269
235
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutEmptyData" ];
@@ -281,9 +247,8 @@ - (void)testUnauthenticatedSimplePutEmptyData {
281
247
[self waitForExpectations ];
282
248
}
283
249
284
- - (void )testUnauthenticatedSimplePutDataUnauthorized {
285
- XCTestExpectation *expectation =
286
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataUnauthorized" ];
250
+ - (void )testPutData {
251
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutData" ];
287
252
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/private/secretfile.txt" ];
288
253
289
254
NSData *data = [@" Hello World" dataUsingEncoding: NSUTF8StringEncoding];
@@ -300,9 +265,8 @@ - (void)testUnauthenticatedSimplePutDataUnauthorized {
300
265
[self waitForExpectations ];
301
266
}
302
267
303
- - (void )testUnauthenticatedSimplePutFile {
304
- XCTestExpectation *expectation =
305
- [self expectationWithDescription: @" testUnauthenticatedSimplePutFile" ];
268
+ - (void )testPutFile {
269
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutFile" ];
306
270
307
271
FIRStorageReference *ref =
308
272
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutFile" ];
@@ -372,9 +336,8 @@ - (void)testPutFileWithSpecialCharacters {
372
336
[self waitForExpectations ];
373
337
}
374
338
375
- - (void )testUnauthenticatedSimplePutDataNoMetadata {
376
- XCTestExpectation *expectation =
377
- [self expectationWithDescription: @" testUnauthenticatedSimplePutDataNoMetadata" ];
339
+ - (void )testPutDataNoMetadata {
340
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutDataNoMetadata" ];
378
341
379
342
FIRStorageReference *ref =
380
343
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutDataNoMetadata" ];
@@ -392,9 +355,8 @@ - (void)testUnauthenticatedSimplePutDataNoMetadata {
392
355
[self waitForExpectations ];
393
356
}
394
357
395
- - (void )testUnauthenticatedSimplePutFileNoMetadata {
396
- XCTestExpectation *expectation =
397
- [self expectationWithDescription: @" testUnauthenticatedSimplePutFileNoMetadata" ];
358
+ - (void )testPutFileNoMetadata {
359
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testPutFileNoMetadata" ];
398
360
399
361
FIRStorageReference *ref =
400
362
[self .storage referenceWithPath: @" ios/public/testUnauthenticatedSimplePutFileNoMetadata" ];
@@ -416,9 +378,8 @@ - (void)testUnauthenticatedSimplePutFileNoMetadata {
416
378
[self waitForExpectations ];
417
379
}
418
380
419
- - (void )testUnauthenticatedSimpleGetData {
420
- XCTestExpectation *expectation =
421
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetData" ];
381
+ - (void )testGetData {
382
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetData" ];
422
383
423
384
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
424
385
@@ -432,9 +393,9 @@ - (void)testUnauthenticatedSimpleGetData {
432
393
[self waitForExpectations ];
433
394
}
434
395
435
- - (void )testUnauthenticatedSimpleGetDataInBackgroundQueue {
396
+ - (void )testGetDataInBackgroundQueue {
436
397
XCTestExpectation *expectation =
437
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDataInBackgroundQueue " ];
398
+ [self expectationWithDescription: @" testGetDataInBackgroundQueue " ];
438
399
439
400
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
440
401
@@ -450,9 +411,8 @@ - (void)testUnauthenticatedSimpleGetDataInBackgroundQueue {
450
411
[self waitForExpectations ];
451
412
}
452
413
453
- - (void )testUnauthenticatedSimpleGetDataTooSmall {
454
- XCTestExpectation *expectation =
455
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDataTooSmall" ];
414
+ - (void )testGetDataTooSmall {
415
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetDataTooSmall" ];
456
416
457
417
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
458
418
@@ -467,9 +427,8 @@ - (void)testUnauthenticatedSimpleGetDataTooSmall {
467
427
[self waitForExpectations ];
468
428
}
469
429
470
- - (void )testUnauthenticatedSimpleGetDownloadURL {
471
- XCTestExpectation *expectation =
472
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetDownloadURL" ];
430
+ - (void )testGetDownloadURL {
431
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetDownloadURL" ];
473
432
474
433
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
475
434
@@ -494,9 +453,8 @@ - (void)testUnauthenticatedSimpleGetDownloadURL {
494
453
[self waitForExpectations ];
495
454
}
496
455
497
- - (void )testUnauthenticatedSimpleGetFile {
498
- XCTestExpectation *expectation =
499
- [self expectationWithDescription: @" testUnauthenticatedSimpleGetFile" ];
456
+ - (void )testGetFile {
457
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testGetFile" ];
500
458
501
459
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/helloworld" ];
502
460
@@ -639,9 +597,8 @@ - (void)testUpdateMetadata {
639
597
[self waitForExpectations ];
640
598
}
641
599
642
- - (void )testUnauthenticatedResumeGetFile {
643
- XCTestExpectation *expectation =
644
- [self expectationWithDescription: @" testUnauthenticatedResumeGetFile" ];
600
+ - (void )testResumeGetFile {
601
+ XCTestExpectation *expectation = [self expectationWithDescription: @" testResumeGetFile" ];
645
602
646
603
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
647
604
@@ -693,9 +650,9 @@ - (void)testUnauthenticatedResumeGetFile {
693
650
XCTAssertEqualWithAccuracy (sqrt (INT_MAX - 499 ), computationResult, 0.1 );
694
651
}
695
652
696
- - (void )testUnauthenticatedResumeGetFileInBackgroundQueue {
653
+ - (void )testResumeGetFileInBackgroundQueue {
697
654
XCTestExpectation *expectation =
698
- [self expectationWithDescription: @" testUnauthenticatedResumeGetFileInBackgroundQueue " ];
655
+ [self expectationWithDescription: @" testResumeGetFileInBackgroundQueue " ];
699
656
700
657
FIRStorageReference *ref = [self .storage referenceWithPath: @" ios/public/1mb" ];
701
658
0 commit comments