aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2018-04-13 14:37:28 -0700
committerGravatar GitHub <noreply@github.com>2018-04-13 14:37:28 -0700
commit4e01558661d74cb7eba3b6ba66d3ecc90720d5f6 (patch)
treef89ca0b8bd61c01b9dd70cbced72687672f5a653 /Example
parent60d43d7b0980719beac21811da712f1cb4881308 (diff)
parentd7316f70dc4825e75cecd47740c0541248aa9641 (diff)
Merge pull request #1055 from firebase/mrschmidt-removedownloadurl
Removing FirebaseStorage.downloadURL
Diffstat (limited to 'Example')
-rw-r--r--Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m32
-rw-r--r--Example/Storage/Tests/Unit/FIRStorageMetadataTests.m60
2 files changed, 39 insertions, 53 deletions
diff --git a/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m b/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
index 8e826c9..b20108a 100644
--- a/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
+++ b/Example/Storage/Tests/Integration/FIRStorageIntegrationTests.m
@@ -12,10 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-#import <FirebaseStorage/FIRStorageMetadata.h>
#import <XCTest/XCTest.h>
-#import <math.h>
-
#import "FirebaseStorage.h"
#import <FirebaseCore/FIRApp.h>
@@ -381,7 +378,7 @@ NSTimeInterval kFIRStorageIntegrationTestTimeout = 30;
/// Only allow 1kB size, which is smaller than our file
[ref dataWithMaxSize:1 * 1024
completion:^(NSData *data, NSError *error) {
- XCTAssertEqual(data, nil);
+ XCTAssertNil(data);
XCTAssertEqual(error.code, FIRStorageErrorCodeDownloadSizeExceeded);
[expectation fulfill];
}];
@@ -389,6 +386,33 @@ NSTimeInterval kFIRStorageIntegrationTestTimeout = 30;
[self waitForExpectations];
}
+- (void)testUnauthenticatedSimpleGetDownloadURL {
+ XCTestExpectation *expectation =
+ [self expectationWithDescription:@"testUnauthenticatedSimpleGetDownloadURL"];
+
+ FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"];
+
+ // Download URL format is
+ // "https://firebasestorage.googleapis.com/v0/b/{bucket}/o/{path}?alt=media&token={token}"
+ NSString *downloadURLPattern =
+ @"^https:\\/\\/firebasestorage.googleapis.com\\/v0\\/b\\/[^\\/]*\\/o\\/"
+ @"ios%2Fpublic%2F1mb\\?alt=media&token=[a-z0-9-]*$";
+
+ [ref downloadURLWithCompletion:^(NSURL *downloadURL, NSError *error) {
+ XCTAssertNil(error);
+ NSRegularExpression *testRegex =
+ [NSRegularExpression regularExpressionWithPattern:downloadURLPattern options:0 error:nil];
+ NSString *urlString = [downloadURL absoluteString];
+ XCTAssertEqual([testRegex numberOfMatchesInString:urlString
+ options:0
+ range:NSMakeRange(0, [urlString length])],
+ 1);
+ [expectation fulfill];
+ }];
+
+ [self waitForExpectations];
+}
+
- (void)testUnauthenticatedSimpleGetFile {
XCTestExpectation *expectation =
[self expectationWithDescription:@"testUnauthenticatedSimpleGetData"];
diff --git a/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m b/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
index 84b5271..6a83741 100644
--- a/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
+++ b/Example/Storage/Tests/Unit/FIRStorageMetadataTests.m
@@ -15,6 +15,8 @@
#import <FirebaseStorage/FIRStorageMetadata.h>
#import <XCTest/XCTest.h>
+#import "FIRStorageGetDownloadURLTask.h"
+#import "FIRStorageGetDownloadURLTask_Private.h"
#import "FIRStorageMetadata.h"
#import "FIRStorageMetadata_Private.h"
#import "FIRStorageUtils.h"
@@ -39,7 +41,6 @@
kFIRStorageMetadataContentLanguage : @"en-us",
kFIRStorageMetadataContentType : @"application/octet-stream",
kFIRStorageMetadataCustomMetadata : @{@"foo" : @{@"bar" : @"baz"}},
- kFIRStorageMetadataDownloadTokens : @"1234567890",
kFIRStorageMetadataGeneration : @"12345",
kFIRStorageMetadataMetageneration : @"67890",
kFIRStorageMetadataName : @"path/to/object",
@@ -58,12 +59,6 @@
XCTAssertEqualObjects(metadata.contentType, metaDict[kFIRStorageMetadataContentType]);
XCTAssertEqualObjects(metadata.customMetadata, metaDict[kFIRStorageMetadataCustomMetadata]);
XCTAssertEqualObjects(metadata.md5Hash, metaDict[kFIRStorageMetadataMd5Hash]);
- NSString *URLFormat = @"https://firebasestorage.googleapis.com/v0/b/%@/o/%@?alt=media&token=%@";
- NSString *URLString = [NSString
- stringWithFormat:URLFormat, metaDict[kFIRStorageMetadataBucket],
- [FIRStorageUtils GCSEscapedString:metaDict[kFIRStorageMetadataName]],
- metaDict[kFIRStorageMetadataDownloadTokens]];
- XCTAssertEqualObjects([metadata.downloadURL description], URLString);
NSString *generation = [NSString stringWithFormat:@"%lld", metadata.generation];
XCTAssertEqualObjects(generation, metaDict[kFIRStorageMetadataGeneration]);
NSString *metageneration = [NSString stringWithFormat:@"%lld", metadata.metageneration];
@@ -86,7 +81,6 @@
kFIRStorageMetadataContentLanguage : @"en-us",
kFIRStorageMetadataContentType : @"application/octet-stream",
kFIRStorageMetadataCustomMetadata : @{@"foo" : @{@"bar" : @"baz"}},
- kFIRStorageMetadataDownloadTokens : @"1234567890",
kFIRStorageMetadataGeneration : @"12345",
kFIRStorageMetadataMetageneration : @"67890",
kFIRStorageMetadataName : @"path/to/object",
@@ -97,7 +91,7 @@
};
FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:metaDict];
NSDictionary *dictRepresentation = [metadata dictionaryRepresentation];
- XCTAssertNotEqual(dictRepresentation, nil);
+ XCTAssertNotNil(dictRepresentation);
XCTAssertEqualObjects(dictRepresentation[kFIRStorageMetadataBucket],
metaDict[kFIRStorageMetadataBucket]);
XCTAssertEqualObjects(dictRepresentation[kFIRStorageMetadataCacheControl],
@@ -130,60 +124,28 @@
metaDict[kFIRStorageMetadataMd5Hash]);
}
-- (void)testInitialzeNoDownloadTokensGetToken {
- NSDictionary *metaDict = @{
- kFIRStorageMetadataBucket : @"bucket",
- kFIRStorageMetadataName : @"path/to/object",
- };
- FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:metaDict];
- XCTAssertNotNil(metadata);
- XCTAssertEqual(metadata.downloadURL, nil);
- XCTAssertEqual(metadata.downloadURLs, nil);
-}
-
-- (void)testInitialzeMultipleDownloadTokensGetToken {
+- (void)testInitializeEmptyDownloadURL {
NSDictionary *metaDict = @{
kFIRStorageMetadataBucket : @"bucket",
- kFIRStorageMetadataDownloadTokens : @"12345,67890",
kFIRStorageMetadataName : @"path/to/object",
};
- FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:metaDict];
- XCTAssertNotNil(metadata);
- NSString *URLformat = @"https://firebasestorage.googleapis.com/v0/b/%@/o/%@?alt=media&token=%@";
- NSString *URLString0 = [NSString
- stringWithFormat:URLformat, metaDict[kFIRStorageMetadataBucket],
- [FIRStorageUtils GCSEscapedString:metaDict[kFIRStorageMetadataName]],
- @"12345"];
- NSString *URLString1 = [NSString
- stringWithFormat:URLformat, metaDict[kFIRStorageMetadataBucket],
- [FIRStorageUtils GCSEscapedString:metaDict[kFIRStorageMetadataName]],
- @"67890"];
- XCTAssertEqualObjects([metadata.downloadURL absoluteString], URLString0);
- XCTAssertEqualObjects([metadata.downloadURLs[0] absoluteString], URLString0);
- XCTAssertEqualObjects([metadata.downloadURLs[1] absoluteString], URLString1);
+ NSURL *actualURL = [FIRStorageGetDownloadURLTask downloadURLFromMetadataDictionary:metaDict];
+ XCTAssertNil(actualURL);
}
-- (void)testMultipleDownloadURLsGetToken {
+- (void)testInitializeDownloadURLFromToken {
NSDictionary *metaDict = @{
kFIRStorageMetadataBucket : @"bucket",
+ kFIRStorageMetadataDownloadTokens : @"12345,ignored",
kFIRStorageMetadataName : @"path/to/object",
};
- FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] initWithDictionary:metaDict];
NSString *URLformat = @"https://firebasestorage.googleapis.com/v0/b/%@/o/%@?alt=media&token=%@";
- NSString *URLString0 = [NSString
+ NSString *expectedURL = [NSString
stringWithFormat:URLformat, metaDict[kFIRStorageMetadataBucket],
[FIRStorageUtils GCSEscapedString:metaDict[kFIRStorageMetadataName]],
@"12345"];
- NSString *URLString1 = [NSString
- stringWithFormat:URLformat, metaDict[kFIRStorageMetadataBucket],
- [FIRStorageUtils GCSEscapedString:metaDict[kFIRStorageMetadataName]],
- @"67890"];
- NSURL *URL0 = [NSURL URLWithString:URLString0];
- NSURL *URL1 = [NSURL URLWithString:URLString1];
- NSArray *downloadURLs = @[ URL0, URL1 ];
- [metadata setValue:downloadURLs forKey:@"downloadURLs"];
- NSDictionary *newMetaDict = metadata.dictionaryRepresentation;
- XCTAssertEqualObjects(newMetaDict[kFIRStorageMetadataDownloadTokens], @"12345,67890");
+ NSURL *actualURL = [FIRStorageGetDownloadURLTask downloadURLFromMetadataDictionary:metaDict];
+ XCTAssertEqualObjects([actualURL absoluteString], expectedURL);
}
- (void)testInitialzeMetadataWithFile {