From 39f4f500e36641f4d47f54914c8bdf019651959f Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 19 May 2020 11:05:17 -0700 Subject: [PATCH 01/19] Use secure rules for Firebase Storage Integration tests --- FirebaseStorage.podspec | 2 + .../Integration/FIRStorageIntegrationTests.m | 155 +++++++----------- scripts/style.sh | 1 + 3 files changed, 59 insertions(+), 99 deletions(-) diff --git a/FirebaseStorage.podspec b/FirebaseStorage.podspec index 089989986ae..0ef07ff953c 100644 --- a/FirebaseStorage.podspec +++ b/FirebaseStorage.podspec @@ -52,6 +52,7 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas int_tests.requires_app_host = true int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat', 'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist' + int_tests.dependency 'FirebaseAuth', '~> 6.5' end s.test_spec 'swift-integration' do |swift_int_tests| @@ -60,5 +61,6 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas swift_int_tests.requires_app_host = true swift_int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat', 'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist' + swift_int_tests.dependency 'FirebaseAuth', '~> 6.5' end end diff --git a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m index 21a23f38585..be058878f0b 100644 --- a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m +++ b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#import #import #import @@ -23,32 +24,37 @@ /** * Firebase Storage Integration tests * - * To run these tests, you need to define the following access rights for your Firebase App: - * - unauthentication read/write access to /ios/public - * - authentication read/write access to /ios/private - * - * A sample configuration may look like: + * To run these tests, you need to define the following access rights: * * rules_version = '2'; * service firebase.storage { * match /b/{bucket}/o { - * ... * match /ios { * match /public/{allPaths=**} { - * allow read, write; + * allow write: if request.auth != null; + * allow read: if true; * } * match /private/{allPaths=**} { - * allow none; + * allow read, write: if false; * } * } * } * } * + * You also need to enable email/password sign in and add a test user in your + * Firebase Authentication settings. Your account credentials need to match + * the credentials defined in `kTestUser` and `kTestPassword`. + * * You can define these access rights in the Firebase Console of your project. */ + +NSString *const kTestUser = @"test@example.com"; +NSString *const kTestPassword = @"testing"; + @interface FIRStorageIntegrationTests : XCTestCase @property(strong, nonatomic) FIRApp *app; +@property(strong, nonatomic) FIRAuth *auth; @property(strong, nonatomic) FIRStorage *storage; @end @@ -63,10 +69,20 @@ - (void)setUp { [super setUp]; self.app = [FIRApp defaultApp]; + self.auth = [FIRAuth authWithApp:self.app]; self.storage = [FIRStorage storageForApp:self.app]; static dispatch_once_t once; dispatch_once(&once, ^{ + XCTestExpectation *logInExpectation = [self expectationWithDescription:@"login"]; + [self.auth signInWithEmail:kTestUser + password:kTestPassword + completion:^(FIRAuthDataResult *result, NSError *error) { + XCTAssertNil(error); + [logInExpectation fulfill]; + }]; + [self waitForExpectations]; + XCTestExpectation *setUpExpectation = [self expectationWithDescription:@"setUp"]; NSArray *largeFiles = @[ @"ios/public/1mb" ]; @@ -122,9 +138,8 @@ - (void)testName { XCTAssertEqualObjects(ref.description, aGSURI); } -- (void)testUnauthenticatedGetMetadata { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedGetMetadata"]; +- (void)testGetMetadata { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetMetadata"]; FIRStorageReference *ref = [self.storage.reference child:@"ios/public/1mb"]; [ref metadataWithCompletion:^(FIRStorageMetadata *metadata, NSError *error) { @@ -136,37 +151,8 @@ - (void)testUnauthenticatedGetMetadata { [self waitForExpectations]; } -- (void)testUnauthenticatedUpdateMetadata { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedUpdateMetadata"]; - - FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; - - FIRStorageMetadata *meta = [[FIRStorageMetadata alloc] init]; - [meta setContentType:@"lol/custom"]; - [meta setCustomMetadata:@{ - @"lol" : @"custom metadata is neat", - @"ちかてつ" : @"🚇", - @"shinkansen" : @"新幹線" - }]; - - [ref updateMetadata:meta - completion:^(FIRStorageMetadata *metadata, NSError *error) { - XCTAssertEqualObjects(meta.contentType, metadata.contentType); - XCTAssertEqualObjects(meta.customMetadata[@"lol"], metadata.customMetadata[@"lol"]); - XCTAssertEqualObjects(meta.customMetadata[@"ちかてつ"], - metadata.customMetadata[@"ちかてつ"]); - XCTAssertEqualObjects(meta.customMetadata[@"shinkansen"], - metadata.customMetadata[@"shinkansen"]); - XCTAssertNil(error, "Error should be nil"); - [expectation fulfill]; - }]; - - [self waitForExpectations]; -} - -- (void)testUnauthenticatedDelete { - XCTestExpectation *expectation = [self expectationWithDescription:@"testUnauthenticatedDelete"]; +- (void)testDelete { + XCTestExpectation *expectation = [self expectationWithDescription:@"testDelete"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/fileToDelete"]; @@ -205,27 +191,8 @@ - (void)testDeleteWithNilCompletion { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutData { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutData"]; - FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testBytesUpload"]; - - NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]; - - [ref putData:data - metadata:nil - completion:^(FIRStorageMetadata *metadata, NSError *error) { - XCTAssertNotNil(metadata, "Metadata should not be nil"); - XCTAssertNil(error, "Error should be nil"); - [expectation fulfill]; - }]; - - [self waitForExpectations]; -} - -- (void)testUnauthenticatedSimplePutSpecialCharacter { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutDataEscapedName"]; +- (void)testPutDataSpecialCharacter { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataSpecialCharacter"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/-._~!$'()*,=:@&+;"]; NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]; @@ -241,9 +208,9 @@ - (void)testUnauthenticatedSimplePutSpecialCharacter { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutDataInBackgroundQueue { +- (void)testPutDataInBackgroundQueue { XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutDataInBackgroundQueue"]; + [self expectationWithDescription:@"testPutDataInBackgroundQueue"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testBytesUpload"]; NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]; @@ -261,9 +228,8 @@ - (void)testUnauthenticatedSimplePutDataInBackgroundQueue { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutEmptyData { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutEmptyData"]; +- (void)testPutDataWithEmptyData { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataWithEmptyData"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutEmptyData"]; @@ -281,9 +247,8 @@ - (void)testUnauthenticatedSimplePutEmptyData { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutDataUnauthorized { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutDataUnauthorized"]; +- (void)testPutData { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutData"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/private/secretfile.txt"]; NSData *data = [@"Hello World" dataUsingEncoding:NSUTF8StringEncoding]; @@ -300,9 +265,8 @@ - (void)testUnauthenticatedSimplePutDataUnauthorized { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutFile { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutFile"]; +- (void)testPutFile { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFile"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFile"]; @@ -372,9 +336,8 @@ - (void)testPutFileWithSpecialCharacters { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutDataNoMetadata { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutDataNoMetadata"]; +- (void)testPutDataNoMetadata { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutDataNoMetadata"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutDataNoMetadata"]; @@ -392,9 +355,8 @@ - (void)testUnauthenticatedSimplePutDataNoMetadata { [self waitForExpectations]; } -- (void)testUnauthenticatedSimplePutFileNoMetadata { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimplePutFileNoMetadata"]; +- (void)testPutFileNoMetadata { + XCTestExpectation *expectation = [self expectationWithDescription:@"testPutFileNoMetadata"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/testUnauthenticatedSimplePutFileNoMetadata"]; @@ -416,9 +378,8 @@ - (void)testUnauthenticatedSimplePutFileNoMetadata { [self waitForExpectations]; } -- (void)testUnauthenticatedSimpleGetData { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimpleGetData"]; +- (void)testGetData { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetData"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; @@ -432,9 +393,9 @@ - (void)testUnauthenticatedSimpleGetData { [self waitForExpectations]; } -- (void)testUnauthenticatedSimpleGetDataInBackgroundQueue { +- (void)testGetDataInBackgroundQueue { XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimpleGetDataInBackgroundQueue"]; + [self expectationWithDescription:@"testGetDataInBackgroundQueue"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; @@ -450,9 +411,8 @@ - (void)testUnauthenticatedSimpleGetDataInBackgroundQueue { [self waitForExpectations]; } -- (void)testUnauthenticatedSimpleGetDataTooSmall { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimpleGetDataTooSmall"]; +- (void)testGetDataTooSmall { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDataTooSmall"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; @@ -467,9 +427,8 @@ - (void)testUnauthenticatedSimpleGetDataTooSmall { [self waitForExpectations]; } -- (void)testUnauthenticatedSimpleGetDownloadURL { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimpleGetDownloadURL"]; +- (void)testGetDownloadURL { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetDownloadURL"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; @@ -494,9 +453,8 @@ - (void)testUnauthenticatedSimpleGetDownloadURL { [self waitForExpectations]; } -- (void)testUnauthenticatedSimpleGetFile { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedSimpleGetFile"]; +- (void)testGetFile { + XCTestExpectation *expectation = [self expectationWithDescription:@"testGetFile"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/helloworld"]; @@ -639,9 +597,8 @@ - (void)testUpdateMetadata { [self waitForExpectations]; } -- (void)testUnauthenticatedResumeGetFile { - XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedResumeGetFile"]; +- (void)testResumeGetFile { + XCTestExpectation *expectation = [self expectationWithDescription:@"testResumeGetFile"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; @@ -693,9 +650,9 @@ - (void)testUnauthenticatedResumeGetFile { XCTAssertEqualWithAccuracy(sqrt(INT_MAX - 499), computationResult, 0.1); } -- (void)testUnauthenticatedResumeGetFileInBackgroundQueue { +- (void)testResumeGetFileInBackgroundQueue { XCTestExpectation *expectation = - [self expectationWithDescription:@"testUnauthenticatedResumeGetFileInBackgroundQueue"]; + [self expectationWithDescription:@"testResumeGetFileInBackgroundQueue"]; FIRStorageReference *ref = [self.storage referenceWithPath:@"ios/public/1mb"]; diff --git a/scripts/style.sh b/scripts/style.sh index 000f4857a7d..5ff24c2b163 100755 --- a/scripts/style.sh +++ b/scripts/style.sh @@ -138,6 +138,7 @@ s%^./%% \%^build/% d \%^Debug/% d \%^Release/% d +\%^cmake-build-debug/% d # pod gen output \%^gen/% d From 0603c4ec0958d341031595a785702b562948c2c6 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 19 May 2020 12:06:34 -0700 Subject: [PATCH 02/19] Update FIRStorageIntegrationTests.m --- .../Tests/Integration/FIRStorageIntegrationTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m index be058878f0b..be3139eb167 100644 --- a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m +++ b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m @@ -74,12 +74,12 @@ - (void)setUp { static dispatch_once_t once; dispatch_once(&once, ^{ - XCTestExpectation *logInExpectation = [self expectationWithDescription:@"login"]; + XCTestExpectation *signInExpectation = [self expectationWithDescription:@"signIn"]; [self.auth signInWithEmail:kTestUser password:kTestPassword completion:^(FIRAuthDataResult *result, NSError *error) { XCTAssertNil(error); - [logInExpectation fulfill]; + [signInExpectation fulfill]; }]; [self waitForExpectations]; From c773b50343c36f8bb2cfc4d966c77f841b3f4980 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 14:32:23 -0700 Subject: [PATCH 03/19] Swift update, pasteable rules --- FirebaseStorage.podspec | 4 +-- .../Integration/FIRStorageIntegrationTests.m | 28 +++++++++---------- .../SwiftIntegration/StorageIntegration.swift | 17 +++++++---- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/FirebaseStorage.podspec b/FirebaseStorage.podspec index 0ef07ff953c..29c5e3c45db 100644 --- a/FirebaseStorage.podspec +++ b/FirebaseStorage.podspec @@ -52,7 +52,7 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas int_tests.requires_app_host = true int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat', 'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist' - int_tests.dependency 'FirebaseAuth', '~> 6.5' + int_tests.dependency 'FirebaseAuth', '~> 6.5' end s.test_spec 'swift-integration' do |swift_int_tests| @@ -61,6 +61,6 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas swift_int_tests.requires_app_host = true swift_int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat', 'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist' - swift_int_tests.dependency 'FirebaseAuth', '~> 6.5' + swift_int_tests.dependency 'FirebaseAuth', '~> 6.5' end end diff --git a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m index be3139eb167..94129cc559d 100644 --- a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m +++ b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m @@ -26,20 +26,20 @@ * * To run these tests, you need to define the following access rights: * - * rules_version = '2'; - * service firebase.storage { - * match /b/{bucket}/o { - * match /ios { - * match /public/{allPaths=**} { - * allow write: if request.auth != null; - * allow read: if true; - * } - * match /private/{allPaths=**} { - * allow read, write: if false; - * } - * } - * } - * } + rules_version = '2'; + service firebase.storage { + match /b/{bucket}/o { + match /ios { + match /public/{allPaths=**} { + allow write: if request.auth != null; + allow read: if true; + } + match /private/{allPaths=**} { + allow read, write: if false; + } + } + } + } * * You also need to enable email/password sign in and add a test user in your * Firebase Authentication settings. Your account credentials need to match diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 8d4ea49fdb9..f805dff013d 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -12,23 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. +// See console setup instructions in FIRStorageIntegrationTests.m + +import FirebaseAuth import FirebaseCore import FirebaseStorage import XCTest class StorageIntegration: XCTestCase { - var app: FirebaseApp! + static var app: FirebaseApp! + static var auth: Auth! var storage: Storage! static var once = false override class func setUp() { FirebaseApp.configure() + app = FirebaseApp.app() + auth = Auth.auth(app:app) + auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in + XCTAssertNil(error) + } } override func setUp() { super.setUp() - app = FirebaseApp.app() - storage = Storage.storage(app: app!) + storage = Storage.storage(app: StorageIntegration.app!) if !StorageIntegration.once { StorageIntegration.once = true @@ -69,13 +77,12 @@ class StorageIntegration: XCTestCase { } override func tearDown() { - app = nil storage = nil super.tearDown() } func testName() { - let aGS = app.options.projectID + let aGS = StorageIntegration.app.options.projectID let aGSURI = "gs://\(aGS!).appspot.com/path/to" let ref = storage.reference(forURL: aGSURI) XCTAssertEqual(ref.description, aGSURI) From fc9e2e0ba330e0268a73a0454dc065ee7408d358 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 14:55:57 -0700 Subject: [PATCH 04/19] disable watchos tests --- .github/workflows/storage.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/storage.yml b/.github/workflows/storage.yml index 4c94767b5d7..5ee0bceec89 100644 --- a/.github/workflows/storage.yml +++ b/.github/workflows/storage.yml @@ -65,7 +65,9 @@ jobs: strategy: matrix: - target: [ios, tvos, macos, watchos] + # watchos is disabled since pod lib lint cannot handle test Auth dep even if the dep is only + # specified for the other three platforms. + target: [ios, tvos, macos] steps: - uses: actions/checkout@v2 - name: Setup Bundler @@ -80,7 +82,7 @@ jobs: if: github.event_name == 'schedule' strategy: matrix: - target: [ios, tvos, macos, watchos] + target: [ios, tvos, macos] flags: [ '--skip-tests --use-modular-headers', '--skip-tests --use-libraries' From 172402a4f28b29a46353a41ad2db07ec30e16c08 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 15:03:11 -0700 Subject: [PATCH 05/19] rename for authorized --- .../SwiftIntegration/StorageIntegration.swift | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index f805dff013d..d6c0fccb786 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -88,7 +88,7 @@ class StorageIntegration: XCTestCase { XCTAssertEqual(ref.description, aGSURI) } - func testUnauthenticatedGetMetadata() { + func testGetMetadata() { let expectation = self.expectation(description: #function) let ref = storage.reference().child("ios/public/1mb") ref.getMetadata(completion: { (metadata, error) -> Void in @@ -99,7 +99,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedGetMetadataUnauthorized() { + func testGetMetadataUnauthorized() { let expectation = self.expectation(description: #function) let ref = storage.reference().child("ios/private/secretfile.txt") ref.getMetadata(completion: { (metadata, error) -> Void in @@ -111,7 +111,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedUpdateMetadata() { + func testUpdateMetadata() { let expectation = self.expectation(description: #function) let meta = StorageMetadata() @@ -133,7 +133,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedDelete() throws { + func testDelete() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/fileToDelete") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -148,7 +148,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedDeleteNonExistingFile() { + func testDeleteNonExistingFile() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/fileThatDoesNotExist") ref.delete { error in @@ -159,7 +159,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedDeleteFileUnauthorized() { + func testDeleteFileUnauthorized() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/private/secretfile.txt") ref.delete { error in @@ -183,7 +183,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutData() throws { + func testSimplePutData() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/testBytesUpload") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -195,7 +195,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutSpecialCharacter() throws { + func testSimplePutSpecialCharacter() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/-._~!$'()*,=:@&+;") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -207,7 +207,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataInBackgroundQueue() throws { + func testSimplePutDataInBackgroundQueue() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/testBytesUpload") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -221,9 +221,9 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutEmptyData() { + func testSimplePutEmptyData() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutEmptyData") + let ref = storage.reference(withPath: "ios/public/testSimplePutEmptyData") let data = Data() ref.putData(data, metadata: nil, completion: { metadata, error in XCTAssertNotNil(metadata, "Metadata should not be nil") @@ -233,7 +233,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataUnauthorized() throws { + func testSimplePutDataUnauthorized() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/private/secretfile.txt") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -246,9 +246,9 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutFile() throws { + func testSimplePutFile() throws { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutFile") + let ref = storage.reference(withPath: "ios/public/testSimplePutFile") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") @@ -301,10 +301,10 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataNoMetadata() throws { + func testSimplePutDataNoMetadata() throws { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutDataNoMetadata") + let ref = storage.reference(withPath: "ios/public/testSimplePutDataNoMetadata") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") ref.putData(data, metadata: nil, completion: { metadata, error in XCTAssertNotNil(metadata, "Metadata should not be nil") @@ -314,7 +314,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutFileNoMetadata() throws { + func testSimplePutFileNoMetadata() throws { let expectation = self.expectation(description: #function) let fileName = "hello&+@_ .txt" @@ -331,7 +331,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutBlankImage() throws { + func testSimplePutBlankImage() throws { let expectation = self.expectation(description: #function) let fileName = "blank.jpg" let ref = storage.reference(withPath: "ios/public/" + fileName) @@ -349,7 +349,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetData() { + func testSimpleGetData() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -361,7 +361,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDataInBackgroundQueue() { + func testSimpleGetDataInBackgroundQueue() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -375,7 +375,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDataTooSmall() { + func testSimpleGetDataTooSmall() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -388,7 +388,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDownloadURL() { + func testSimpleGetDownloadURL() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -416,7 +416,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetFileWithCompletion() throws { + func testSimpleGetFileWithCompletion() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/cookie") let cookieString = "Here's a 🍪, yay!" @@ -449,7 +449,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetFile() throws { + func testSimpleGetFile() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/helloworld") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) @@ -529,7 +529,7 @@ class StorageIntegration: XCTestCase { XCTAssertNil(actualMetadata.customMetadata) } - func testUpdateMetadata() { + func testUpdateMetadata2() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -580,7 +580,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedResumeGetFile() { + func testResumeGetFile() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) @@ -628,7 +628,7 @@ class StorageIntegration: XCTestCase { XCTAssertEqual(sqrt(Double(INT_MAX - 499)), computationResult, accuracy: 0.1) } - func testUnauthenticatedResumeGetFileInBackgroundQueue() { + func testResumeGetFileInBackgroundQueue() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) From f8a712db84032a122ec373e4f06b6c6865d83881 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 15:44:57 -0700 Subject: [PATCH 06/19] wait for signIn --- .../Tests/SwiftIntegration/StorageIntegration.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index d6c0fccb786..0c9d883436e 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -28,9 +28,15 @@ class StorageIntegration: XCTestCase { override class func setUp() { FirebaseApp.configure() app = FirebaseApp.app() - auth = Auth.auth(app:app) + auth = Auth.auth(app: app) + let group = DispatchGroup() + group.enter() auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in XCTAssertNil(error) + group.leave() + } + group.notify(queue: .main) { + print("Done signing in") } } From 7a9e15cae00c2e25cdfb1f4678236e7fdc01ac60 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 16:06:03 -0700 Subject: [PATCH 07/19] instance method signIn --- .../SwiftIntegration/StorageIntegration.swift | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 0c9d883436e..5298944c73a 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -20,32 +20,24 @@ import FirebaseStorage import XCTest class StorageIntegration: XCTestCase { - static var app: FirebaseApp! - static var auth: Auth! + var app: FirebaseApp! + var auth: Auth! var storage: Storage! static var once = false override class func setUp() { FirebaseApp.configure() - app = FirebaseApp.app() - auth = Auth.auth(app: app) - let group = DispatchGroup() - group.enter() - auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in - XCTAssertNil(error) - group.leave() - } - group.notify(queue: .main) { - print("Done signing in") - } } override func setUp() { super.setUp() - storage = Storage.storage(app: StorageIntegration.app!) + app = FirebaseApp.app() + auth = Auth.auth(app: app) + storage = Storage.storage(app: app!) if !StorageIntegration.once { StorageIntegration.once = true + signInAndWait() let setupExpectation = expectation(description: "setUp") let largeFiles = ["ios/public/1mb"] @@ -83,12 +75,14 @@ class StorageIntegration: XCTestCase { } override func tearDown() { + app = nil + auth = nil storage = nil super.tearDown() } func testName() { - let aGS = StorageIntegration.app.options.projectID + let aGS = app.options.projectID let aGSURI = "gs://\(aGS!).appspot.com/path/to" let ref = storage.reference(forURL: aGSURI) XCTAssertEqual(ref.description, aGSURI) @@ -718,6 +712,15 @@ class StorageIntegration: XCTestCase { waitForExpectations() } + private func signInAndWait() { + let expectation = self.expectation(description: #function) + auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in + XCTAssertNil(error) + expectation.fulfill() + } + waitForExpectations() + } + private func waitForExpectations() { let kFIRStorageIntegrationTestTimeout = 60.0 waitForExpectations(timeout: kFIRStorageIntegrationTestTimeout, From f4a89baecbd9673f2bcbf5637160cda941bbcddc Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Tue, 19 May 2020 17:24:41 -0700 Subject: [PATCH 08/19] fix race --- .../Tests/SwiftIntegration/StorageIntegration.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 5298944c73a..5eb3828f6eb 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -24,6 +24,7 @@ class StorageIntegration: XCTestCase { var auth: Auth! var storage: Storage! static var once = false + static var signedIn = false override class func setUp() { FirebaseApp.configure() @@ -35,9 +36,12 @@ class StorageIntegration: XCTestCase { auth = Auth.auth(app: app) storage = Storage.storage(app: app!) + if !StorageIntegration.signedIn { + signInAndWait() + } + if !StorageIntegration.once { StorageIntegration.once = true - signInAndWait() let setupExpectation = expectation(description: "setUp") let largeFiles = ["ios/public/1mb"] @@ -715,6 +719,7 @@ class StorageIntegration: XCTestCase { private func signInAndWait() { let expectation = self.expectation(description: #function) auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in + StorageIntegration.signedIn = true XCTAssertNil(error) expectation.fulfill() } From 529a70a2813fdaf035ce2aab4fc4092eb2008d09 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 07:37:31 -0700 Subject: [PATCH 09/19] fix exposed race --- Credentials.swift | 8 ++++++++ .../Tests/SwiftIntegration/StorageIntegration.swift | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Credentials.swift diff --git a/Credentials.swift b/Credentials.swift new file mode 100644 index 00000000000..57aaab1de4c --- /dev/null +++ b/Credentials.swift @@ -0,0 +1,8 @@ +// +// Credentials.swift +// FirebaseStorage-Unit-swift-integration +// +// Created by Paul Beusterien on 5/19/20. +// + +import Foundation diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 5eb3828f6eb..9dc772e40cd 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -41,7 +41,6 @@ class StorageIntegration: XCTestCase { } if !StorageIntegration.once { - StorageIntegration.once = true let setupExpectation = expectation(description: "setUp") let largeFiles = ["ios/public/1mb"] @@ -75,6 +74,7 @@ class StorageIntegration: XCTestCase { XCTFail("Exception thrown setting up files in setUp") } waitForExpectations() + StorageIntegration.once = true } } From 6c40fa9480f6f29392b3fda3e299d6effc5e65a4 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 07:39:11 -0700 Subject: [PATCH 10/19] Add credentials --- Credentials.swift | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/Credentials.swift b/Credentials.swift index 57aaab1de4c..6d3e22ab325 100644 --- a/Credentials.swift +++ b/Credentials.swift @@ -1,8 +1,35 @@ -// -// Credentials.swift -// FirebaseStorage-Unit-swift-integration -// -// Created by Paul Beusterien on 5/19/20. -// +/* +* Copyright 2020 Google LLC +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ import Foundation + +/* + Some of the Credentials needs to be populated for the Swift Tests to work. + Please follow the following steps to populate the valid Credentials + and copy it to Credentials.swift file: + + You will need to replace the following values: + $KUSER_NAME + The name of the user for Auth SignIn + $KPASSWORD + The password. + + */ + +class Credentials { + static let kUserName = KUSER_NAME + static let kPassword = KPASSWORD +} From a5e4d7ff4b4038fbe5a8afba418cbf36aa97e56e Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 07:40:49 -0700 Subject: [PATCH 11/19] Fix location --- .../Tests/SwiftIntegration/Credentials.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Credentials.swift => FirebaseStorage/Tests/SwiftIntegration/Credentials.swift (100%) diff --git a/Credentials.swift b/FirebaseStorage/Tests/SwiftIntegration/Credentials.swift similarity index 100% rename from Credentials.swift rename to FirebaseStorage/Tests/SwiftIntegration/Credentials.swift From c551c78204f3f95922d305e61acc23b40f8abda3 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 08:35:41 -0700 Subject: [PATCH 12/19] Add Credentials.h --- .../Tests/Integration/Credentials.h | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 FirebaseStorage/Tests/Integration/Credentials.h diff --git a/FirebaseStorage/Tests/Integration/Credentials.h b/FirebaseStorage/Tests/Integration/Credentials.h new file mode 100644 index 00000000000..97da9e5256c --- /dev/null +++ b/FirebaseStorage/Tests/Integration/Credentials.h @@ -0,0 +1,30 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + Some of the Credentials needs to be populated for the Integration Tests. + Please follow the following steps to populate the valid Credentials + and copy it to Credentials.swift file: + + You will need to replace the following values: + $KUSER_NAME + The name of the user for Auth SignIn + $KPASSWORD + The password. + */ + +#define KUSER_NAME $KUSER_NAME +#define KPASSWORD $KPASSWORD From f893a0af97065a1f419849592ba380894b240ca4 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 08:49:37 -0700 Subject: [PATCH 13/19] encrypted credentials --- .github/workflows/storage.yml | 6 ++++++ .gitignore | 4 ++++ .../Integration/FIRStorageIntegrationTests.m | 6 ++++-- .../SwiftIntegration/StorageIntegration.swift | 6 ++++-- scripts/gha-encrypted/Storage/Credentials.h.gpg | Bin 0 -> 654 bytes .../gha-encrypted/Storage/Credentials.swift.gpg | Bin 0 -> 680 bytes 6 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 scripts/gha-encrypted/Storage/Credentials.h.gpg create mode 100644 scripts/gha-encrypted/Storage/Credentials.swift.gpg diff --git a/.github/workflows/storage.yml b/.github/workflows/storage.yml index 5ee0bceec89..ebb3c1d36cc 100644 --- a/.github/workflows/storage.yml +++ b/.github/workflows/storage.yml @@ -27,6 +27,12 @@ jobs: - name: Install Secret GoogleService-Info.plist run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/storage-db-plist.gpg \ FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist "$plist_secret" + - name: Install Credentials.h + run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.h.gpg \ + FirebaseStorage/Tests/Integration/Credentials.h "$plist_secret" + - name: Install Credentials.swift + run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.swift.gpg \ + FirebaseStorage/Tests/SwiftIntegration/Credentials.swift "$plist_secret" - name: BuildAndTest # can be replaced with pod lib lint with CocoaPods 1.10 run: ([ -z $plist_secret ] || scripts/third_party/travis/retry.sh scripts/build.sh ${{ matrix.pod }} all) diff --git a/.gitignore b/.gitignore index 3f54f4916a3..f6d16893d35 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,10 @@ FirebaseMessaging/Tests/IntegrationTests/Resources/GoogleService-Info.plist # FirebaseMessaging test app GoogleService-Info.plist FirebaseMessaging/Apps/Sample/Sample/GoogleService-Info.plist +# Credentials for Firebase Storage Integration Tests +FirebaseStorage/Tests/SwiftIntegration/Credentials.swift +FirebaseStorage/Tests/Integration/Credentials.h + Secrets.tar # OS X diff --git a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m index 94129cc559d..80daa2f4f28 100644 --- a/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m +++ b/FirebaseStorage/Tests/Integration/FIRStorageIntegrationTests.m @@ -19,6 +19,8 @@ #import #import +#import "Credentials.h" + NSTimeInterval kFIRStorageIntegrationTestTimeout = 60; /** @@ -48,8 +50,8 @@ * You can define these access rights in the Firebase Console of your project. */ -NSString *const kTestUser = @"test@example.com"; -NSString *const kTestPassword = @"testing"; +NSString *const kTestUser = KUSER_NAME; +NSString *const kTestPassword = KPASSWORD; @interface FIRStorageIntegrationTests : XCTestCase diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 9dc772e40cd..c499641464f 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -718,9 +718,11 @@ class StorageIntegration: XCTestCase { private func signInAndWait() { let expectation = self.expectation(description: #function) - auth.signIn(withEmail: "test@example.com", password: "testing") { result, error in - StorageIntegration.signedIn = true + auth.signIn(withEmail: Credentials.kUserName, + password: Credentials.kPassword) { result, error in XCTAssertNil(error) + StorageIntegration.signedIn = true + print("Successfully signed in") expectation.fulfill() } waitForExpectations() diff --git a/scripts/gha-encrypted/Storage/Credentials.h.gpg b/scripts/gha-encrypted/Storage/Credentials.h.gpg new file mode 100644 index 0000000000000000000000000000000000000000..c13d59baf3b5202e4f4f2224b679105bc78b2d8c GIT binary patch literal 654 zcmV;90&)F}4Fm}T0{`GE(&^So?(Nd)0cV=HG_UEfg&M%D z))984Ajxny8bT_W8rAC)MLs9V#s1u4WubSX&aE@O*?5Li z$Dd8#_D_K#$l%*L99qn7)|?-{QN~C^&|ZnLU23Mhcc7#9ssJ~~In{7W>X{fqqN^!P z!nvMyDNZ@%G#8w^rDqX+#Ab@|i`4+5RYCbe@?%pkX}j>P&`RWgCIGveL2#_ZbjNrAvD+a*G_OHEm?a zCBW8?NZVIc-`PygY^IzfPd>0d``ix5FspjEHNogj1_>Snf%4Q;Y#v&SI56E)aAog- z>xOSj9NZSqxm1L9S9dc?eCf}_AZe*Ng-5R`nIL|WUvN%WfM@w)-gWXUQFZqo|VHrvcKJA(a500000 literal 0 HcmV?d00001 diff --git a/scripts/gha-encrypted/Storage/Credentials.swift.gpg b/scripts/gha-encrypted/Storage/Credentials.swift.gpg new file mode 100644 index 0000000000000000000000000000000000000000..4d2e6c9fc7401975076f78d462ef1e5f5d3d923e GIT binary patch literal 680 zcmV;Z0$2Tv4Fm}T0%B=(ZwKSpD(%wg0l+B>Qhhcbe=4}>iC>6bQYMhFQnH0H+L%KW z=Fwn4;rBv`)l<{}ldm6b|F^t}!OGOH+ZdO!=G>gDI|SG#KSssGH$*y2dHO%9xa$)_ z^g;`k1-y7ay2nmB64NUlgTlQ)->X%O3=?p>=f_Pv$S`UnHk;Q-^BnoIgF+N;&nutP zy(T%JRv*kCNvMKnROu&NjPh0Y;=!5KSL4ERn`Cc}c0+yxRe){tgRmJ@Yfy}|?}2$o zb(~EzO>pl->6pA2Q`c*j*e>J4c_7k{pRGTH430H{coKr{KHXfXLi}evz%Wh@O?TN& z+$mL&P0TQ!a{`A}Xh`BsEtvh=C@p)jeMqSE=Z-c0iu|Cy(GH4gRTav<%KnOywmBW0 z&9&G2U|Zr*kYOLibp3msR()~&y@2NGMNGVCw1?lSe6ZKZGDcy=6$D=6lQ?mez$6TB z3Lu>PcZ_vB*;gkV3ut1tpk`BxD@8kD{?52EmaUf5YZnPt4Kr?*C zw{F@0TO!8c32=Af@hUQtPD;_xjL#oaOqn;8h+;Z3t2l5f_pMOklEe?i=D4qJR>}l+eq>I`jiezG&MiAs~O?@|Aq{;0{n9t!z0^A Date: Wed, 20 May 2020 08:58:12 -0700 Subject: [PATCH 14/19] style --- .../Tests/SwiftIntegration/Credentials.swift | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/Credentials.swift b/FirebaseStorage/Tests/SwiftIntegration/Credentials.swift index 6d3e22ab325..091ae35fe9e 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/Credentials.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/Credentials.swift @@ -1,18 +1,18 @@ /* -* Copyright 2020 Google LLC -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import Foundation From dee9fee35aabed159d68f559a8d994a85ae913be Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 09:33:07 -0700 Subject: [PATCH 15/19] Try skipping once --- .../Tests/SwiftIntegration/StorageIntegration.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index c499641464f..e266b2b9652 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -40,7 +40,7 @@ class StorageIntegration: XCTestCase { signInAndWait() } - if !StorageIntegration.once { +// if !StorageIntegration.once { let setupExpectation = expectation(description: "setUp") let largeFiles = ["ios/public/1mb"] @@ -75,7 +75,7 @@ class StorageIntegration: XCTestCase { } waitForExpectations() StorageIntegration.once = true - } +// } } override func tearDown() { @@ -497,10 +497,14 @@ class StorageIntegration: XCTestCase { let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.dat") let task = ref.write(toFile: fileURL) + var failed = false // Only fail once task.observe(StorageTaskStatus.failure, handler: { snapshot in XCTAssertTrue(snapshot.description.starts(with: " Date: Wed, 20 May 2020 11:21:41 -0700 Subject: [PATCH 16/19] namespace 1mb.dat for swift --- .../SwiftIntegration/StorageIntegration.swift | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index e266b2b9652..7b5368c0cfd 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -40,10 +40,10 @@ class StorageIntegration: XCTestCase { signInAndWait() } -// if !StorageIntegration.once { + if !StorageIntegration.once { let setupExpectation = expectation(description: "setUp") - let largeFiles = ["ios/public/1mb"] + let largeFiles = ["ios/public/swift-1mb"] let emptyFiles = ["ios/public/empty", "ios/public/list/a", "ios/public/list/b", "ios/public/list/prefix/c"] setupExpectation.expectedFulfillmentCount = largeFiles.count + emptyFiles.count @@ -75,7 +75,7 @@ class StorageIntegration: XCTestCase { } waitForExpectations() StorageIntegration.once = true -// } + } } override func tearDown() { @@ -94,7 +94,7 @@ class StorageIntegration: XCTestCase { func testGetMetadata() { let expectation = self.expectation(description: #function) - let ref = storage.reference().child("ios/public/1mb") + let ref = storage.reference().child("ios/public/swift-1mb") ref.getMetadata(completion: { (metadata, error) -> Void in XCTAssertNotNil(metadata, "Metadata should not be nil") XCTAssertNil(error, "Error should be nil") @@ -124,7 +124,7 @@ class StorageIntegration: XCTestCase { "ちかてつ": "🚇", "shinkansen": "新幹線"] - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") ref.updateMetadata(meta, completion: { metadata, error in XCTAssertEqual(meta.contentType, metadata!.contentType) XCTAssertEqual(meta.customMetadata!["lol"], metadata?.customMetadata!["lol"]) @@ -356,7 +356,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetData() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") ref.getData(maxSize: 1024 * 1024, completion: { data, error in XCTAssertNotNil(data, "Data should not be nil") XCTAssertNil(error, "Error should be nil") @@ -368,7 +368,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetDataInBackgroundQueue() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") DispatchQueue.global(qos: .background).async { ref.getData(maxSize: 1024 * 1024, completion: { data, error in XCTAssertNotNil(data, "Data should not be nil") @@ -382,7 +382,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetDataTooSmall() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") ref.getData(maxSize: 1024, completion: { data, error in XCTAssertNil(data, "Data should be nil") XCTAssertNotNil(error, "Error should not be nil") @@ -395,13 +395,13 @@ class StorageIntegration: XCTestCase { func testSimpleGetDownloadURL() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") // Download URL format is // "https://firebasestorage.googleapis.com/v0/b/{bucket}/o/{path}?alt=media&token={token}" let downloadURLPattern = "^https:\\/\\/firebasestorage.googleapis.com\\/v0\\/b\\/[^\\/]*\\/o\\/" + - "ios%2Fpublic%2F1mb\\?alt=media&token=[a-z0-9-]*$" + "ios%2Fpublic%2Fswift-1mb\\?alt=media&token=[a-z0-9-]*$" ref.downloadURL(completion: { downloadURL, error in XCTAssertNil(error, "Error should be nil") @@ -493,7 +493,7 @@ class StorageIntegration: XCTestCase { func testCancelDownload() throws { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.dat") let task = ref.write(toFile: fileURL) @@ -539,7 +539,7 @@ class StorageIntegration: XCTestCase { func testUpdateMetadata2() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") let metadata = StorageMetadata() metadata.cacheControl = "cache-control" @@ -590,7 +590,7 @@ class StorageIntegration: XCTestCase { func testResumeGetFile() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") let task = ref.write(toFile: fileURL) @@ -638,7 +638,7 @@ class StorageIntegration: XCTestCase { func testResumeGetFileInBackgroundQueue() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/1mb") + let ref = storage.reference(withPath: "ios/public/swift-1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") let task = ref.write(toFile: fileURL) From 82f2d062ae4408047047559ba422a1946959e197 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 12:08:05 -0700 Subject: [PATCH 17/19] wip --- .../SwiftIntegration/StorageIntegration.swift | 22 +++---- .../Tests/Integration/Credentials.swift | 35 ++++++++++ .../Integration/StorageIntegration.swift | 64 ++++++++++++------- 3 files changed, 88 insertions(+), 33 deletions(-) create mode 100644 FirebaseStorageSwift/Tests/Integration/Credentials.swift diff --git a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift index 7b5368c0cfd..3f18b90c91a 100644 --- a/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift +++ b/FirebaseStorage/Tests/SwiftIntegration/StorageIntegration.swift @@ -94,7 +94,7 @@ class StorageIntegration: XCTestCase { func testGetMetadata() { let expectation = self.expectation(description: #function) - let ref = storage.reference().child("ios/public/swift-1mb") + let ref = storage.reference().child("ios/public/1mb") ref.getMetadata(completion: { (metadata, error) -> Void in XCTAssertNotNil(metadata, "Metadata should not be nil") XCTAssertNil(error, "Error should be nil") @@ -124,7 +124,7 @@ class StorageIntegration: XCTestCase { "ちかてつ": "🚇", "shinkansen": "新幹線"] - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") ref.updateMetadata(meta, completion: { metadata, error in XCTAssertEqual(meta.contentType, metadata!.contentType) XCTAssertEqual(meta.customMetadata!["lol"], metadata?.customMetadata!["lol"]) @@ -356,7 +356,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetData() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") ref.getData(maxSize: 1024 * 1024, completion: { data, error in XCTAssertNotNil(data, "Data should not be nil") XCTAssertNil(error, "Error should be nil") @@ -368,7 +368,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetDataInBackgroundQueue() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") DispatchQueue.global(qos: .background).async { ref.getData(maxSize: 1024 * 1024, completion: { data, error in XCTAssertNotNil(data, "Data should not be nil") @@ -382,7 +382,7 @@ class StorageIntegration: XCTestCase { func testSimpleGetDataTooSmall() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") ref.getData(maxSize: 1024, completion: { data, error in XCTAssertNil(data, "Data should be nil") XCTAssertNotNil(error, "Error should not be nil") @@ -395,13 +395,13 @@ class StorageIntegration: XCTestCase { func testSimpleGetDownloadURL() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") // Download URL format is // "https://firebasestorage.googleapis.com/v0/b/{bucket}/o/{path}?alt=media&token={token}" let downloadURLPattern = "^https:\\/\\/firebasestorage.googleapis.com\\/v0\\/b\\/[^\\/]*\\/o\\/" + - "ios%2Fpublic%2Fswift-1mb\\?alt=media&token=[a-z0-9-]*$" + "ios%2Fpublic%2F1mb\\?alt=media&token=[a-z0-9-]*$" ref.downloadURL(completion: { downloadURL, error in XCTAssertNil(error, "Error should be nil") @@ -493,7 +493,7 @@ class StorageIntegration: XCTestCase { func testCancelDownload() throws { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.dat") let task = ref.write(toFile: fileURL) @@ -539,7 +539,7 @@ class StorageIntegration: XCTestCase { func testUpdateMetadata2() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") let metadata = StorageMetadata() metadata.cacheControl = "cache-control" @@ -590,7 +590,7 @@ class StorageIntegration: XCTestCase { func testResumeGetFile() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") let task = ref.write(toFile: fileURL) @@ -638,7 +638,7 @@ class StorageIntegration: XCTestCase { func testResumeGetFileInBackgroundQueue() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/swift-1mb") + let ref = storage.reference(withPath: "ios/public/1mb") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") let task = ref.write(toFile: fileURL) diff --git a/FirebaseStorageSwift/Tests/Integration/Credentials.swift b/FirebaseStorageSwift/Tests/Integration/Credentials.swift new file mode 100644 index 00000000000..091ae35fe9e --- /dev/null +++ b/FirebaseStorageSwift/Tests/Integration/Credentials.swift @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import Foundation + +/* + Some of the Credentials needs to be populated for the Swift Tests to work. + Please follow the following steps to populate the valid Credentials + and copy it to Credentials.swift file: + + You will need to replace the following values: + $KUSER_NAME + The name of the user for Auth SignIn + $KPASSWORD + The password. + + */ + +class Credentials { + static let kUserName = KUSER_NAME + static let kPassword = KPASSWORD +} diff --git a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift index d6dd8dc96ef..869d7682685 100644 --- a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift +++ b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +import FirebaseAuth import FirebaseCore import FirebaseStorage import FirebaseStorageSwift @@ -19,8 +20,10 @@ import XCTest class StorageIntegration: XCTestCase { var app: FirebaseApp! + var auth: Auth! var storage: Storage! static var once = false + static var signedIn = false override class func setUp() { FirebaseApp.configure() @@ -31,6 +34,10 @@ class StorageIntegration: XCTestCase { app = FirebaseApp.app() storage = Storage.storage(app: app!) + if !StorageIntegration.signedIn { + signInAndWait() + } + if !StorageIntegration.once { StorageIntegration.once = true let setupExpectation = expectation(description: "setUp") @@ -74,8 +81,8 @@ class StorageIntegration: XCTestCase { super.tearDown() } - func testUnauthenticatedGetMetadata() { - let expectation = self.expectation(description: "testUnauthenticatedGetMetadata") + func testGetMetadata() { + let expectation = self.expectation(description: "testGetMetadata") let ref = storage.reference().child("ios/public/1mb") ref.getMetadata { result in self.assertResultSuccess(result) @@ -84,7 +91,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedUpdateMetadata() { + func testUpdateMetadata() { let expectation = self.expectation(description: #function) let meta = StorageMetadata() @@ -110,7 +117,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedDelete() throws { + func testDelete() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/fileToDelete") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -136,7 +143,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutData() throws { + func testSimplePutData() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/testBytesUpload") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -147,7 +154,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutSpecialCharacter() throws { + func testSimplePutSpecialCharacter() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/-._~!$'()*,=:@&+;") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -158,7 +165,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataInBackgroundQueue() throws { + func testSimplePutDataInBackgroundQueue() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/testBytesUpload") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -171,9 +178,9 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutEmptyData() { + func testSimplePutEmptyData() { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutEmptyData") + let ref = storage.reference(withPath: "ios/public/testSimplePutEmptyData") let data = Data() ref.putData(data) { result in self.assertResultSuccess(result) @@ -182,7 +189,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataUnauthorized() throws { + func testSimplePutDataUnauthorized() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/private/secretfile.txt") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -198,7 +205,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataUnauthorizedThrow() throws { + func testSimplePutDataUnauthorizedThrow() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/private/secretfile.txt") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") @@ -215,10 +222,10 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutFile() throws { + func testSimplePutFile() throws { let expectation = self.expectation(description: #function) let putFileExpectation = self.expectation(description: "putFile") - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutFile") + let ref = storage.reference(withPath: "ios/public/testSimplePutFile") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) let fileURL = tmpDirURL.appendingPathComponent("hello.txt") @@ -272,10 +279,10 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutDataNoMetadata() throws { + func testSimplePutDataNoMetadata() throws { let expectation = self.expectation(description: #function) - let ref = storage.reference(withPath: "ios/public/testUnauthenticatedSimplePutDataNoMetadata") + let ref = storage.reference(withPath: "ios/public/testSimplePutDataNoMetadata") let data = try XCTUnwrap("Hello Swift World".data(using: .utf8), "Data construction failed") ref.putData(data) { result in @@ -285,7 +292,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimplePutFileNoMetadata() throws { + func testSimplePutFileNoMetadata() throws { let expectation = self.expectation(description: #function) let fileName = "hello&+@_ .txt" @@ -301,7 +308,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetData() { + func testSimpleGetData() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -312,7 +319,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDataInBackgroundQueue() { + func testSimpleGetDataInBackgroundQueue() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -325,7 +332,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDataTooSmall() { + func testSimpleGetDataTooSmall() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -341,7 +348,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetDownloadURL() { + func testSimpleGetDownloadURL() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -372,7 +379,7 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - func testUnauthenticatedSimpleGetFile() throws { + func testSimpleGetFile() throws { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/helloworld") let tmpDirURL = URL(fileURLWithPath: NSTemporaryDirectory()) @@ -438,7 +445,7 @@ class StorageIntegration: XCTestCase { XCTAssertNil(actualMetadata.customMetadata) } - func testUpdateMetadata() { + func testUpdateMetadata2() { let expectation = self.expectation(description: #function) let ref = storage.reference(withPath: "ios/public/1mb") @@ -541,6 +548,19 @@ class StorageIntegration: XCTestCase { waitForExpectations() } + private func signInAndWait() { + let expectation = self.expectation(description: #function) + auth.signIn(withEmail: Credentials.kUserName, + password: Credentials.kPassword) { result, error in + XCTAssertNil(error) + StorageIntegration.signedIn = true + print("Successfully signed in") + expectation.fulfill() + } + waitForExpectations() + } + + private func waitForExpectations() { let kFIRStorageIntegrationTestTimeout = 60.0 waitForExpectations(timeout: kFIRStorageIntegrationTestTimeout, From de2456ed56023f5c7eb19621c36f3dc348be67c5 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 12:13:42 -0700 Subject: [PATCH 18/19] FirebaseStorageSwift also --- .github/workflows/storage.yml | 4 +++- .gitignore | 3 ++- FirebaseStorageSwift.podspec | 1 + .../Tests/Integration/StorageIntegration.swift | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/storage.yml b/.github/workflows/storage.yml index ebb3c1d36cc..290d54fecf4 100644 --- a/.github/workflows/storage.yml +++ b/.github/workflows/storage.yml @@ -31,8 +31,10 @@ jobs: run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.h.gpg \ FirebaseStorage/Tests/Integration/Credentials.h "$plist_secret" - name: Install Credentials.swift - run: scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.swift.gpg \ + run: | + scripts/decrypt_gha_secret.sh scripts/gha-encrypted/Storage/Credentials.swift.gpg \ FirebaseStorage/Tests/SwiftIntegration/Credentials.swift "$plist_secret" + cp FirebaseStorage/Tests/SwiftIntegration/Credentials.swift FirebaseStorageSwift/Tests/Integration/ - name: BuildAndTest # can be replaced with pod lib lint with CocoaPods 1.10 run: ([ -z $plist_secret ] || scripts/third_party/travis/retry.sh scripts/build.sh ${{ matrix.pod }} all) diff --git a/.gitignore b/.gitignore index f6d16893d35..b279c9475b2 100644 --- a/.gitignore +++ b/.gitignore @@ -25,8 +25,9 @@ FirebaseMessaging/Tests/IntegrationTests/Resources/GoogleService-Info.plist FirebaseMessaging/Apps/Sample/Sample/GoogleService-Info.plist # Credentials for Firebase Storage Integration Tests -FirebaseStorage/Tests/SwiftIntegration/Credentials.swift FirebaseStorage/Tests/Integration/Credentials.h +FirebaseStorage/Tests/SwiftIntegration/Credentials.swift +FirebaseStorageSwift/Tests/Integration/Credentials.swift Secrets.tar diff --git a/FirebaseStorageSwift.podspec b/FirebaseStorageSwift.podspec index 7a82cc676d7..cc31d9fef2e 100644 --- a/FirebaseStorageSwift.podspec +++ b/FirebaseStorageSwift.podspec @@ -40,5 +40,6 @@ Firebase Storage provides robust, secure file uploads and downloads from Firebas # Resources are shared with FirebaseStorage's integration tests. int_tests.resources = 'FirebaseStorage/Tests/Integration/Resources/1mb.dat', 'FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist' + int_tests.dependency 'FirebaseAuth', '~> 6.5' end end diff --git a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift index 869d7682685..e6dbef06eeb 100644 --- a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift +++ b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift @@ -32,6 +32,7 @@ class StorageIntegration: XCTestCase { override func setUp() { super.setUp() app = FirebaseApp.app() + auth = Auth.auth(app: app) storage = Storage.storage(app: app!) if !StorageIntegration.signedIn { From 02a9b2a44ba07408eaf0b13193cf5ec976895df6 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 20 May 2020 12:19:31 -0700 Subject: [PATCH 19/19] style --- FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift index e6dbef06eeb..1913c8f8e72 100644 --- a/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift +++ b/FirebaseStorageSwift/Tests/Integration/StorageIntegration.swift @@ -561,7 +561,6 @@ class StorageIntegration: XCTestCase { waitForExpectations() } - private func waitForExpectations() { let kFIRStorageIntegrationTestTimeout = 60.0 waitForExpectations(timeout: kFIRStorageIntegrationTestTimeout,