@@ -92,6 +92,18 @@ class StorageIntegration: XCTestCase {
92
92
waitForExpectations ( )
93
93
}
94
94
95
+ func testUnauthenticatedGetMetadataUnauthorized( ) {
96
+ let expectation = self . expectation ( description: #function)
97
+ let ref = storage. reference ( ) . child ( " ios/private/secretfile.txt " )
98
+ ref. getMetadata ( completion: { ( metadata, error) -> Void in
99
+ XCTAssertNil ( metadata, " Metadata should be nil " )
100
+ XCTAssertNotNil ( error, " Error should not be nil " )
101
+ XCTAssertEqual ( ( error! as NSError ) . code, StorageErrorCode . unauthorized. rawValue)
102
+ expectation. fulfill ( )
103
+ } )
104
+ waitForExpectations ( )
105
+ }
106
+
95
107
func testUnauthenticatedUpdateMetadata( ) {
96
108
let expectation = self . expectation ( description: #function)
97
109
@@ -129,6 +141,28 @@ class StorageIntegration: XCTestCase {
129
141
waitForExpectations ( )
130
142
}
131
143
144
+ func testUnauthenticatedDeleteNonExistingFile( ) {
145
+ let expectation = self . expectation ( description: #function)
146
+ let ref = storage. reference ( withPath: " ios/public/fileThatDoesNotExist " )
147
+ ref. delete { error in
148
+ XCTAssertNotNil ( error, " Error should not be nil " )
149
+ XCTAssertEqual ( ( error! as NSError ) . code, StorageErrorCode . objectNotFound. rawValue)
150
+ expectation. fulfill ( )
151
+ }
152
+ waitForExpectations ( )
153
+ }
154
+
155
+ func testUnauthenticatedDeleteFileUnauthorized( ) {
156
+ let expectation = self . expectation ( description: #function)
157
+ let ref = storage. reference ( withPath: " ios/private/secretfile.txt " )
158
+ ref. delete { error in
159
+ XCTAssertNotNil ( error, " Error should not be nil " )
160
+ XCTAssertEqual ( ( error! as NSError ) . code, StorageErrorCode . unauthorized. rawValue)
161
+ expectation. fulfill ( )
162
+ }
163
+ waitForExpectations ( )
164
+ }
165
+
132
166
func testDeleteWithNilCompletion( ) throws {
133
167
let expectation = self . expectation ( description: #function)
134
168
let ref = storage. reference ( withPath: " ios/public/fileToDelete " )
@@ -290,6 +324,24 @@ class StorageIntegration: XCTestCase {
290
324
waitForExpectations ( )
291
325
}
292
326
327
+ func testUnauthenticatedSimplePutBlankImage( ) throws {
328
+ let expectation = self . expectation ( description: #function)
329
+ let fileName = " blank.jpg "
330
+ let ref = storage. reference ( withPath: " ios/public/ " + fileName)
331
+ let tmpDirURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
332
+ let imageURL = tmpDirURL. appendingPathComponent ( fileName)
333
+
334
+ let data = Data ( )
335
+ try data. write ( to: imageURL, options: . atomicWrite)
336
+
337
+ ref. putFile ( from: imageURL, metadata: nil , completion: { metadata, error in
338
+ XCTAssertNotNil ( metadata, " Metadata should not be nil " )
339
+ XCTAssertNil ( error, " Error should be nil " )
340
+ expectation. fulfill ( )
341
+ } )
342
+ waitForExpectations ( )
343
+ }
344
+
293
345
func testUnauthenticatedSimpleGetData( ) {
294
346
let expectation = self . expectation ( description: #function)
295
347
@@ -357,6 +409,39 @@ class StorageIntegration: XCTestCase {
357
409
waitForExpectations ( )
358
410
}
359
411
412
+ func testUnauthenticatedSimpleGetFileWithCompletion( ) throws {
413
+ let expectation = self . expectation ( description: #function)
414
+ let ref = storage. reference ( withPath: " ios/public/cookie " )
415
+ let cookieString = " Here's a 🍪, yay! "
416
+ let data = try XCTUnwrap ( cookieString. data ( using: . utf8) , " Data construction failed " )
417
+
418
+ ref. putData ( data, metadata: nil , completion: { metadata, error in
419
+ XCTAssertNotNil ( metadata, " Metadata should not be nil " )
420
+ XCTAssertNil ( error, " Error should be nil " )
421
+
422
+ let tmpDirURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
423
+ let fileURL = tmpDirURL. appendingPathComponent ( " cookie.txt " )
424
+ ref. write ( toFile: fileURL) { url, error in
425
+ XCTAssertNil ( error, " Error should be nil " )
426
+
427
+ guard let url = url else {
428
+ XCTFail ( " Failed to unwrap url " )
429
+ return
430
+ }
431
+ XCTAssertEqual ( fileURL, url)
432
+
433
+ do {
434
+ let stringData = try String ( contentsOf: fileURL, encoding: . utf8)
435
+ XCTAssertEqual ( stringData, cookieString)
436
+ expectation. fulfill ( )
437
+ } catch {
438
+ XCTFail ( " Could not get String contents of fetched data " )
439
+ }
440
+ }
441
+ } )
442
+ waitForExpectations ( )
443
+ }
444
+
360
445
func testUnauthenticatedSimpleGetFile( ) throws {
361
446
let expectation = self . expectation ( description: #function)
362
447
let ref = storage. reference ( withPath: " ios/public/helloworld " )
0 commit comments