From 6e4586379f29c54a38f15f17c3f12beaef1a4fe3 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Thu, 1 Oct 2020 13:57:56 +0100 Subject: [PATCH 1/5] Make some methods on RLMApp properties --- .../SwiftObjectServerTests.swift | 90 +++++++++---------- .../ObjectServerTests/SwiftSyncTestCase.swift | 2 +- Realm/RLMApp.h | 32 +++---- 3 files changed, 60 insertions(+), 64 deletions(-) diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index a926d34022..c65d7b7834 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -720,10 +720,10 @@ class SwiftObjectServerTests: SwiftSyncTestCase { func testAppInit() { let appWithNoConfig = App(id: appName) - XCTAssertEqual(appWithNoConfig.allUsers().count, 0) + XCTAssertEqual(appWithNoConfig.allUsers.count, 0) let appWithConfig = App(id: appName, configuration: appConfig()) - XCTAssertEqual(appWithConfig.allUsers().count, 0) + XCTAssertEqual(appWithConfig.allUsers.count, 0) } func testAppLogin() { @@ -733,7 +733,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -750,8 +750,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [loginEx], timeout: 4.0) - XCTAssertEqual(syncUser?.id, app.currentUser()?.id) - XCTAssertEqual(app.allUsers().count, 1) + XCTAssertEqual(syncUser?.id, app.currentUser?.id) + XCTAssertEqual(app.allUsers.count, 1) } func testAppSwitchAndRemove() { @@ -764,12 +764,12 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUser1Ex = expectation(description: "Register user 1") let registerUser2Ex = expectation(description: "Register user 2") - app.emailPasswordAuth().registerUser(email: email1, password: password1) { (error) in + app.emailPasswordAuth.registerUser(email: email1, password: password1) { (error) in XCTAssertNil(error) registerUser1Ex.fulfill() } - app.emailPasswordAuth().registerUser(email: email2, password: password2) { (error) in + app.emailPasswordAuth.registerUser(email: email2, password: password2) { (error) in XCTAssertNil(error) registerUser2Ex.fulfill() } @@ -798,12 +798,12 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [login2Ex], timeout: 4.0) - XCTAssertEqual(app.allUsers().count, 2) + XCTAssertEqual(app.allUsers.count, 2) - XCTAssertEqual(syncUser2!.id, app.currentUser()!.id) + XCTAssertEqual(syncUser2!.id, app.currentUser!.id) app.switch(to: syncUser1!) - XCTAssertTrue(syncUser1!.id == app.currentUser()?.id) + XCTAssertTrue(syncUser1!.id == app.currentUser?.id) let removeEx = expectation(description: "Remove user 1") @@ -814,8 +814,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [removeEx], timeout: 4.0) - XCTAssertEqual(syncUser2!.id, app.currentUser()!.id) - XCTAssertEqual(app.allUsers().count, 1) + XCTAssertEqual(syncUser2!.id, app.currentUser!.id) + XCTAssertEqual(app.allUsers.count, 1) } func testAppLinkUser() { @@ -825,7 +825,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -854,7 +854,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [linkEx], timeout: 4.0) - XCTAssertEqual(syncUser?.id, app.currentUser()?.id) + XCTAssertEqual(syncUser?.id, app.currentUser?.id) XCTAssertEqual(syncUser?.identities().count, 2) } @@ -867,7 +867,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -875,7 +875,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let confirmUserEx = expectation(description: "Confirm user") - app.emailPasswordAuth().confirmUser("atoken", tokenId: "atokenid") { (error) in + app.emailPasswordAuth.confirmUser("atoken", tokenId: "atokenid") { (error) in XCTAssertNotNil(error) confirmUserEx.fulfill() } @@ -883,7 +883,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let resendEmailEx = expectation(description: "Resend email confirmation") - app.emailPasswordAuth().resendConfirmationEmail("atoken") { (error) in + app.emailPasswordAuth.resendConfirmationEmail("atoken") { (error) in XCTAssertNotNil(error) resendEmailEx.fulfill() } @@ -891,7 +891,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let resendResetPasswordEx = expectation(description: "Resend reset password email") - app.emailPasswordAuth().sendResetPasswordEmail("atoken") { (error) in + app.emailPasswordAuth.sendResetPasswordEmail("atoken") { (error) in XCTAssertNotNil(error) resendResetPasswordEx.fulfill() } @@ -899,14 +899,14 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let resetPasswordEx = expectation(description: "Reset password email") - app.emailPasswordAuth().resetPassword(to: "password", token: "atoken", tokenId: "tokenId") { (error) in + app.emailPasswordAuth.resetPassword(to: "password", token: "atoken", tokenId: "tokenId") { (error) in XCTAssertNotNil(error) resetPasswordEx.fulfill() } wait(for: [resetPasswordEx], timeout: 4.0) let callResetFunctionEx = expectation(description: "Reset password function") - app.emailPasswordAuth().callResetPasswordFunction(email: email, + app.emailPasswordAuth.callResetPasswordFunction(email: email, password: randomString(10), args: [[:]]) { (error) in XCTAssertNotNil(error) @@ -922,7 +922,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -996,7 +996,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -1038,7 +1038,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -1055,14 +1055,14 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerDeviceExpectation = expectation(description: "Register Device") let client = app.pushClient(serviceName: "gcm") - client.registerDevice(token: "some-token", user: app.currentUser()!) { error in + client.registerDevice(token: "some-token", user: app.currentUser!) { error in XCTAssertNil(error) registerDeviceExpectation.fulfill() } wait(for: [registerDeviceExpectation], timeout: 4.0) let dergisterDeviceExpectation = expectation(description: "Deregister Device") - client.deregisterDevice(user: app.currentUser()!, completion: { error in + client.deregisterDevice(user: app.currentUser!, completion: { error in XCTAssertNil(error) dergisterDeviceExpectation.fulfill() }) @@ -1075,7 +1075,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) { (error) in + app.emailPasswordAuth.registerUser(email: email, password: password) { (error) in XCTAssertNil(error) registerUserEx.fulfill() } @@ -1108,8 +1108,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { } wait(for: [refreshDataEx], timeout: 4.0) - XCTAssertEqual(app.currentUser()?.customData?["favourite_colour"], .string("green")) - XCTAssertEqual(app.currentUser()?.customData?["apples"], .int64(10)) + XCTAssertEqual(app.currentUser?.customData?["favourite_colour"], .string("green")) + XCTAssertEqual(app.currentUser?.customData?["apples"], .int64(10)) } // MARK: - Mongo Client @@ -2048,7 +2048,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { var cancellable = Set() let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { result in if case .failure = result { XCTFail("Should register") @@ -2060,7 +2060,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [registerUserEx], timeout: 4.0) let confirmUserEx = expectation(description: "Confirm user") - app.emailPasswordAuth().confirmUser("atoken", tokenId: "atokenid") + app.emailPasswordAuth.confirmUser("atoken", tokenId: "atokenid") .sink(receiveCompletion: { result in if case .failure = result { confirmUserEx.fulfill() @@ -2072,7 +2072,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [confirmUserEx], timeout: 4.0) let resendEmailEx = expectation(description: "Resend email confirmation") - app.emailPasswordAuth().resendConfirmationEmail(email: "atoken") + app.emailPasswordAuth.resendConfirmationEmail(email: "atoken") .sink(receiveCompletion: { result in if case .failure = result { resendEmailEx.fulfill() @@ -2084,7 +2084,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [resendEmailEx], timeout: 4.0) let sendResetPasswordEx = expectation(description: "Send reset password email") - app.emailPasswordAuth().sendResetPasswordEmail(email: "atoken") + app.emailPasswordAuth.sendResetPasswordEmail(email: "atoken") .sink(receiveCompletion: { result in if case .failure = result { sendResetPasswordEx.fulfill() @@ -2096,7 +2096,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [sendResetPasswordEx], timeout: 4.0) let resetPasswordEx = expectation(description: "Reset password email") - app.emailPasswordAuth().resetPassword(to: "password", token: "atoken", tokenId: "tokenId") + app.emailPasswordAuth.resetPassword(to: "password", token: "atoken", tokenId: "tokenId") .sink(receiveCompletion: { result in if case .failure = result { resetPasswordEx.fulfill() @@ -2108,7 +2108,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [resetPasswordEx], timeout: 4.0) let callResetFunctionEx = expectation(description: "Reset password function") - app.emailPasswordAuth().callResetPasswordFunction(email: email, password: randomString(10), args: [[:]]) + app.emailPasswordAuth.callResetPasswordFunction(email: email, password: randomString(10), args: [[:]]) .sink(receiveCompletion: { result in if case .failure = result { callResetFunctionEx.fulfill() @@ -2126,7 +2126,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let password = randomString(10) let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { result in if case .failure = result { XCTFail("Should register") @@ -2145,11 +2145,11 @@ class CombineObjectServerTests: SwiftSyncTestCase { } }, receiveValue: { user in loginEx.fulfill() - XCTAssertEqual(user.id, self.app.currentUser()?.id) + XCTAssertEqual(user.id, self.app.currentUser?.id) }) .store(in: &cancellable) wait(for: [loginEx], timeout: 4.0) - XCTAssertEqual(self.app.allUsers().count, 1) + XCTAssertEqual(self.app.allUsers.count, 1) } func testRefreshCustomDataCombine() { @@ -2158,7 +2158,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { var cancellable = Set() let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { result in if case .failure = result { XCTFail("Should register") @@ -2205,8 +2205,8 @@ class CombineObjectServerTests: SwiftSyncTestCase { .store(in: &cancellable) wait(for: [refreshDataEx], timeout: 4.0) - XCTAssertEqual(app.currentUser()?.customData?["favourite_colour"], .string("green")) - XCTAssertEqual(app.currentUser()?.customData?["apples"], .int64(10)) + XCTAssertEqual(app.currentUser?.customData?["favourite_colour"], .string("green")) + XCTAssertEqual(app.currentUser?.customData?["apples"], .int64(10)) } func testMongoCollectionInsertCombine() { @@ -2775,7 +2775,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { var cancellable = Set() let regEx = expectation(description: "Should register") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { result in if case .failure = result { XCTFail("Should register") @@ -2843,7 +2843,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let password = randomString(10) let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { _ in }, receiveValue: { _ in registerUserEx.fulfill() }) .store(in: &cancellable) @@ -2945,7 +2945,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let password = randomString(10) let registerUserEx = expectation(description: "Register user") - app.emailPasswordAuth().registerUser(email: email, password: password) + app.emailPasswordAuth.registerUser(email: email, password: password) .sink(receiveCompletion: { _ in }, receiveValue: { _ in registerUserEx.fulfill() }) .store(in: &cancellable) @@ -2960,7 +2960,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let registerDeviceExpectation = expectation(description: "Register Device") let client = app.pushClient(serviceName: "gcm") - client.registerDevice(token: "some-token", user: app.currentUser()!) + client.registerDevice(token: "some-token", user: app.currentUser!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should register device") @@ -2972,7 +2972,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [registerDeviceExpectation], timeout: 4.0) let dergisterDeviceExpectation = expectation(description: "Deregister Device") - client.deregisterDevice(user: app.currentUser()!) + client.deregisterDevice(user: app.currentUser!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should deregister device") diff --git a/Realm/ObjectServerTests/SwiftSyncTestCase.swift b/Realm/ObjectServerTests/SwiftSyncTestCase.swift index 0e0012e606..f197ed2f72 100644 --- a/Realm/ObjectServerTests/SwiftSyncTestCase.swift +++ b/Realm/ObjectServerTests/SwiftSyncTestCase.swift @@ -36,7 +36,7 @@ class SwiftSyncTestCase: RLMSyncTestCase { let password = "abcdef" let credentials = Credentials(email: username, password: password) let ex = expectation(description: "Should register in the user properly") - app.emailPasswordAuth().registerUser(email: username, password: password, completion: { error in + app.emailPasswordAuth.registerUser(email: username, password: password, completion: { error in XCTAssertNil(error) ex.fulfill() }) diff --git a/Realm/RLMApp.h b/Realm/RLMApp.h index 4287713ff6..e680a4adc5 100644 --- a/Realm/RLMApp.h +++ b/Realm/RLMApp.h @@ -98,6 +98,20 @@ Create a new Realm App configuration. /// The `RLMSyncManager` for this Realm app. @property (nonatomic, readonly) RLMSyncManager *syncManager; +/// Get a dictionary containing all users keyed on id. +@property (nonatomic, strong) NSDictionary *allUsers; + +/// Get the current user logged into the Realm app. +@property (nonatomic, strong, nullable) RLMUser *currentUser; + +/** + A client for the email/password authentication provider which + can be used to obtain a credential for logging in. + + Used to perform requests specifically related to the email/password provider. +*/ +@property (nonatomic, strong) RLMEmailPasswordAuth *emailPasswordAuth; + /** Get an application with a given appId and configuration. @@ -114,24 +128,6 @@ Create a new Realm App configuration. + (instancetype)appWithId:(NSString *)appId configuration:(nullable RLMAppConfiguration *)configuration; -/** - Get a dictionary containing all users keyed on id. - */ -- (NSDictionary *)allUsers; - -/** - Get the current user logged into the Realm app. - */ -- (nullable RLMUser *)currentUser; - -/** - A client for the email/password authentication provider which - can be used to obtain a credential for logging in. - - Used to perform requests specifically related to the email/password provider. -*/ -- (RLMEmailPasswordAuth *)emailPasswordAuth; - /** Login to a user for the Realm app. From 4f4e524ae98d7c4bcff4318fd6dfd63f369c4899 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Thu, 1 Oct 2020 14:15:54 +0100 Subject: [PATCH 2/5] Change some methods on RLMUser to properties --- .../SwiftObjectServerTests.swift | 26 +++++++++---------- Realm/RLMApp.h | 6 ++--- Realm/RLMUser.h | 14 ++++------ 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index c65d7b7834..a5419a071e 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -855,7 +855,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [linkEx], timeout: 4.0) XCTAssertEqual(syncUser?.id, app.currentUser?.id) - XCTAssertEqual(syncUser?.identities().count, 2) + XCTAssertEqual(syncUser?.identities.count, 2) } // MARK: - Provider Clients @@ -943,7 +943,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { let createAPIKeyEx = expectation(description: "Create user api key") var apiKey: UserAPIKey? - syncUser?.apiKeysAuth().createAPIKey(named: "my-api-key") { (key, error) in + syncUser?.apiKeysAuth.createAPIKey(named: "my-api-key") { (key, error) in XCTAssertNotNil(key) XCTAssertNil(error) apiKey = key @@ -952,7 +952,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [createAPIKeyEx], timeout: 4.0) let fetchAPIKeyEx = expectation(description: "Fetch user api key") - syncUser?.apiKeysAuth().fetchAPIKey(apiKey!.objectId) { (key, error) in + syncUser?.apiKeysAuth.fetchAPIKey(apiKey!.objectId) { (key, error) in XCTAssertNotNil(key) XCTAssertNil(error) fetchAPIKeyEx.fulfill() @@ -960,7 +960,7 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [fetchAPIKeyEx], timeout: 4.0) let fetchAPIKeysEx = expectation(description: "Fetch user api keys") - syncUser?.apiKeysAuth().fetchAPIKeys(completion: { (keys, error) in + syncUser?.apiKeysAuth.fetchAPIKeys(completion: { (keys, error) in XCTAssertNotNil(keys) XCTAssertEqual(keys!.count, 1) XCTAssertNil(error) @@ -969,21 +969,21 @@ class SwiftObjectServerTests: SwiftSyncTestCase { wait(for: [fetchAPIKeysEx], timeout: 4.0) let disableKeyEx = expectation(description: "Disable API key") - syncUser?.apiKeysAuth().disableAPIKey(apiKey!.objectId) { (error) in + syncUser?.apiKeysAuth.disableAPIKey(apiKey!.objectId) { (error) in XCTAssertNil(error) disableKeyEx.fulfill() } wait(for: [disableKeyEx], timeout: 4.0) let enableKeyEx = expectation(description: "Enable API key") - syncUser?.apiKeysAuth().enableAPIKey(apiKey!.objectId) { (error) in + syncUser?.apiKeysAuth.enableAPIKey(apiKey!.objectId) { (error) in XCTAssertNil(error) enableKeyEx.fulfill() } wait(for: [enableKeyEx], timeout: 4.0) let deleteKeyEx = expectation(description: "Delete API key") - syncUser?.apiKeysAuth().deleteAPIKey(apiKey!.objectId) { (error) in + syncUser?.apiKeysAuth.deleteAPIKey(apiKey!.objectId) { (error) in XCTAssertNil(error) deleteKeyEx.fulfill() } @@ -2862,7 +2862,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let createAPIKeyEx = expectation(description: "Create user api key") var apiKey: UserAPIKey? - syncUser?.apiKeysAuth().createAPIKey(named: "my-api-key") + syncUser?.apiKeysAuth.createAPIKey(named: "my-api-key") .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should create user api key") @@ -2876,7 +2876,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let fetchAPIKeyEx = expectation(description: "Fetch user api key") var objId: ObjectId? = try? ObjectId(string: apiKey!.objectId.stringValue) - syncUser?.apiKeysAuth().fetchAPIKey(objId!) + syncUser?.apiKeysAuth.fetchAPIKey(objId!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should fetch user api key") @@ -2889,7 +2889,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [fetchAPIKeyEx], timeout: 4.0) let fetchAPIKeysEx = expectation(description: "Fetch user api keys") - syncUser?.apiKeysAuth().fetchAPIKeys() + syncUser?.apiKeysAuth.fetchAPIKeys() .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should fetch user api keys") @@ -2903,7 +2903,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { let disableKeyEx = expectation(description: "Disable API key") objId = try? ObjectId(string: apiKey!.objectId.stringValue) - syncUser?.apiKeysAuth().disableAPIKey(objId!) + syncUser?.apiKeysAuth.disableAPIKey(objId!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should disable user api key") @@ -2915,7 +2915,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [disableKeyEx], timeout: 4.0) let enableKeyEx = expectation(description: "Enable API key") - syncUser?.apiKeysAuth().enableAPIKey(objId!) + syncUser?.apiKeysAuth.enableAPIKey(objId!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should enable user api key") @@ -2927,7 +2927,7 @@ class CombineObjectServerTests: SwiftSyncTestCase { wait(for: [enableKeyEx], timeout: 4.0) let deleteKeyEx = expectation(description: "Delete API key") - syncUser?.apiKeysAuth().deleteAPIKey(objId!) + syncUser?.apiKeysAuth.deleteAPIKey(objId!) .sink(receiveCompletion: { (result) in if case .failure = result { XCTFail("Should delete user api key") diff --git a/Realm/RLMApp.h b/Realm/RLMApp.h index e680a4adc5..b22818fc0a 100644 --- a/Realm/RLMApp.h +++ b/Realm/RLMApp.h @@ -99,10 +99,10 @@ Create a new Realm App configuration. @property (nonatomic, readonly) RLMSyncManager *syncManager; /// Get a dictionary containing all users keyed on id. -@property (nonatomic, strong) NSDictionary *allUsers; +@property (nonatomic, strong, readonly) NSDictionary *allUsers; /// Get the current user logged into the Realm app. -@property (nonatomic, strong, nullable) RLMUser *currentUser; +@property (nonatomic, strong, readonly, nullable) RLMUser *currentUser; /** A client for the email/password authentication provider which @@ -110,7 +110,7 @@ Create a new Realm App configuration. Used to perform requests specifically related to the email/password provider. */ -@property (nonatomic, strong) RLMEmailPasswordAuth *emailPasswordAuth; +@property (nonatomic, strong, readonly) RLMEmailPasswordAuth *emailPasswordAuth; /** Get an application with a given appId and configuration. diff --git a/Realm/RLMUser.h b/Realm/RLMUser.h index 3a64ec05b1..9e72af10de 100644 --- a/Realm/RLMUser.h +++ b/Realm/RLMUser.h @@ -68,10 +68,8 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nullable, nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id); -/** - Returns an array of identities currently linked to a user. -*/ -- (NSArray *)identities; +/// Returns an array of identities currently linked to a user. +@property (nonatomic, strong, readonly) NSArray *identities; /** The user's refresh token used to access the Realm Applcation. @@ -118,10 +116,8 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable RLMSyncSession *)sessionForPartitionValue:(id)partitionValue; -/** - Retrieve all the valid sessions belonging to this user. - */ -- (NSArray *)allSessions; +/// Retrieve all the valid sessions belonging to this user. +@property (nonatomic, strong, readonly) NSArray *allSessions; #pragma mark - Custom Data @@ -175,7 +171,7 @@ NS_ASSUME_NONNULL_BEGIN This client should only be used by an authenticated user. */ -- (RLMAPIKeyAuth *)apiKeysAuth; +@property (nonatomic, strong, readonly) RLMAPIKeyAuth *apiKeysAuth; /// A client for interacting with a remote MongoDB instance /// @param serviceName The name of the MongoDB service From 024e69f1c653b717d42e6411d8622dee023d5591 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Thu, 1 Oct 2020 14:33:44 +0100 Subject: [PATCH 3/5] Remove nullable from some properties --- Realm/ObjectServerTests/SwiftObjectServerTests.swift | 8 ++++---- Realm/RLMUser.h | 9 ++++----- Realm/RLMUser.mm | 8 ++++---- RealmSwift/Sync.swift | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Realm/ObjectServerTests/SwiftObjectServerTests.swift b/Realm/ObjectServerTests/SwiftObjectServerTests.swift index a5419a071e..193d6970bb 100644 --- a/Realm/ObjectServerTests/SwiftObjectServerTests.swift +++ b/Realm/ObjectServerTests/SwiftObjectServerTests.swift @@ -1108,8 +1108,8 @@ class SwiftObjectServerTests: SwiftSyncTestCase { } wait(for: [refreshDataEx], timeout: 4.0) - XCTAssertEqual(app.currentUser?.customData?["favourite_colour"], .string("green")) - XCTAssertEqual(app.currentUser?.customData?["apples"], .int64(10)) + XCTAssertEqual(app.currentUser?.customData["favourite_colour"], .string("green")) + XCTAssertEqual(app.currentUser?.customData["apples"], .int64(10)) } // MARK: - Mongo Client @@ -2205,8 +2205,8 @@ class CombineObjectServerTests: SwiftSyncTestCase { .store(in: &cancellable) wait(for: [refreshDataEx], timeout: 4.0) - XCTAssertEqual(app.currentUser?.customData?["favourite_colour"], .string("green")) - XCTAssertEqual(app.currentUser?.customData?["apples"], .int64(10)) + XCTAssertEqual(app.currentUser?.customData["favourite_colour"], .string("green")) + XCTAssertEqual(app.currentUser?.customData["apples"], .int64(10)) } func testMongoCollectionInsertCombine() { diff --git a/Realm/RLMUser.h b/Realm/RLMUser.h index 9e72af10de..856ea2cf26 100644 --- a/Realm/RLMUser.h +++ b/Realm/RLMUser.h @@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN The unique MongoDB Realm string identifying this user. Note this is different from an identitiy: A user may have multiple identities but has a single indentifier. See RLMUserIdentity. */ -@property (nullable, nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id); +@property (nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id); /// Returns an array of identities currently linked to a user. @property (nonatomic, strong, readonly) NSArray *identities; @@ -77,8 +77,7 @@ NS_ASSUME_NONNULL_BEGIN This is required to make HTTP requests to the Realm App's REST API for functionality not exposed natively. It should be treated as sensitive data. */ -@property (nullable, nonatomic, readonly) NSString *refreshToken; - +@property (nonatomic, readonly) NSString *refreshToken; /** The user's refresh token used to access the Realm Application. @@ -86,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN This is required to make HTTP requests to MongoDB Realm's REST API for functionality not exposed natively. It should be treated as sensitive data. */ -@property (nullable, nonatomic, readonly) NSString *accessToken; +@property (nonatomic, readonly) NSString *accessToken; /** The current state of the user. @@ -125,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN The custom data of the user. This is configured in your MongoDB Realm App. */ -@property (nullable, nonatomic, readonly) NSDictionary *customData NS_REFINED_FOR_SWIFT; +@property (nonatomic, readonly) NSDictionary *customData NS_REFINED_FOR_SWIFT; /** Refresh a user's custom data. This will, in effect, refresh the user's auth session. diff --git a/Realm/RLMUser.mm b/Realm/RLMUser.mm index 632eeb8cfc..2d6347d27a 100644 --- a/Realm/RLMUser.mm +++ b/Realm/RLMUser.mm @@ -129,7 +129,7 @@ - (nullable RLMSyncSession *)sessionForPartitionValue:(id)partitionValu - (NSString *)identifier { if (!_user) { - return nil; + return @""; } return @(_user->identity().c_str()); } @@ -243,21 +243,21 @@ + (void)_setUpBindingContextFactory { - (NSString *)refreshToken { if (!_user) { - return nil; + return @""; } return @(_user->refresh_token().c_str()); } - (NSString *)accessToken { if (!_user) { - return nil; + return @""; } return @(_user->access_token().c_str()); } - (NSDictionary *)customData { if (!_user || !_user->custom_data()) { - return nil; + return @{}; } return (NSDictionary *)RLMConvertBsonToRLMBSON(*_user->custom_data()); diff --git a/RealmSwift/Sync.swift b/RealmSwift/Sync.swift index 62e6a88cce..30499e7952 100644 --- a/RealmSwift/Sync.swift +++ b/RealmSwift/Sync.swift @@ -356,11 +356,11 @@ public extension User { The custom data of the user. This is configured in your MongoDB Realm App. */ - var customData: Document? { + var customData: Document { guard let rlmCustomData = self.__customData as RLMBSON?, let anyBSON = ObjectiveCSupport.convert(object: rlmCustomData), case let .document(customData) = anyBSON else { - return nil + return [:] } return customData From cbd6202d89b2e8293aa2049695d9cc1a451af3b9 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Thu, 1 Oct 2020 17:26:36 +0100 Subject: [PATCH 4/5] Remove strong attribute --- Realm/RLMApp.h | 6 +++--- Realm/RLMUser.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Realm/RLMApp.h b/Realm/RLMApp.h index b22818fc0a..05621cf430 100644 --- a/Realm/RLMApp.h +++ b/Realm/RLMApp.h @@ -99,10 +99,10 @@ Create a new Realm App configuration. @property (nonatomic, readonly) RLMSyncManager *syncManager; /// Get a dictionary containing all users keyed on id. -@property (nonatomic, strong, readonly) NSDictionary *allUsers; +@property (nonatomic, readonly) NSDictionary *allUsers; /// Get the current user logged into the Realm app. -@property (nonatomic, strong, readonly, nullable) RLMUser *currentUser; +@property (nonatomic, readonly, nullable) RLMUser *currentUser; /** A client for the email/password authentication provider which @@ -110,7 +110,7 @@ Create a new Realm App configuration. Used to perform requests specifically related to the email/password provider. */ -@property (nonatomic, strong, readonly) RLMEmailPasswordAuth *emailPasswordAuth; +@property (nonatomic, readonly) RLMEmailPasswordAuth *emailPasswordAuth; /** Get an application with a given appId and configuration. diff --git a/Realm/RLMUser.h b/Realm/RLMUser.h index 856ea2cf26..de7f6453fc 100644 --- a/Realm/RLMUser.h +++ b/Realm/RLMUser.h @@ -69,7 +69,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) NSString *identifier NS_SWIFT_NAME(id); /// Returns an array of identities currently linked to a user. -@property (nonatomic, strong, readonly) NSArray *identities; +@property (nonatomic, readonly) NSArray *identities; /** The user's refresh token used to access the Realm Applcation. @@ -116,7 +116,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable RLMSyncSession *)sessionForPartitionValue:(id)partitionValue; /// Retrieve all the valid sessions belonging to this user. -@property (nonatomic, strong, readonly) NSArray *allSessions; +@property (nonatomic, readonly) NSArray *allSessions; #pragma mark - Custom Data @@ -170,7 +170,7 @@ NS_ASSUME_NONNULL_BEGIN This client should only be used by an authenticated user. */ -@property (nonatomic, strong, readonly) RLMAPIKeyAuth *apiKeysAuth; +@property (nonatomic, readonly) RLMAPIKeyAuth *apiKeysAuth; /// A client for interacting with a remote MongoDB instance /// @param serviceName The name of the MongoDB service From 04ac481041f37108c04995c6f6f966cd6f98adc7 Mon Sep 17 00:00:00 2001 From: Lee Maguire Date: Thu, 1 Oct 2020 18:33:18 +0100 Subject: [PATCH 5/5] Add CHANGELOG entry, check access & refresh token for empty string --- CHANGELOG.md | 16 ++++++++++++++++ Realm/RLMUser.h | 4 ++-- Realm/RLMUser.mm | 8 ++++---- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b3c4ccd7f..480c86c09a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,22 @@ x.y.z Release notes (yyyy-MM-dd) ### Enhancements * None. +### Breaking Changes +* Change the following methods on RLMUser to properties: + - `[RLMUser emailPasswordAuth]` => `RLMUser.emailPasswordAuth` + - `[RLMUser identities]` => `RLMUser.identities` + - `[RLMUser allSessions]` => `RLMUser.allSessions` + - `[RLMUser apiKeysAuth]` => `RLMUser.apiKeysAuth` + +* Other changes to RLMUser: + - `nullable` has been removed from `RLMUser.identifier` + - `nullable` has been removed from `RLMUser.customData` + +* Change the following methods on RLMApp to properties: + - `[RLMApp allUsers]` => `RLMApp.allUsers` + - `[RLMApp currentUser]` => `RLMApp.currentUser` + - `[RLMApp emailPasswordAuth]` => `RLMApp.emailPasswordAuth` + ### Fixed * ([#????](https://github.com/realm/realm-cocoa/issues/????), since v?.?.?) * None. diff --git a/Realm/RLMUser.h b/Realm/RLMUser.h index de7f6453fc..26a236771e 100644 --- a/Realm/RLMUser.h +++ b/Realm/RLMUser.h @@ -77,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN This is required to make HTTP requests to the Realm App's REST API for functionality not exposed natively. It should be treated as sensitive data. */ -@property (nonatomic, readonly) NSString *refreshToken; +@property (nullable, nonatomic, readonly) NSString *refreshToken; /** The user's refresh token used to access the Realm Application. @@ -85,7 +85,7 @@ NS_ASSUME_NONNULL_BEGIN This is required to make HTTP requests to MongoDB Realm's REST API for functionality not exposed natively. It should be treated as sensitive data. */ -@property (nonatomic, readonly) NSString *accessToken; +@property (nullable, nonatomic, readonly) NSString *accessToken; /** The current state of the user. diff --git a/Realm/RLMUser.mm b/Realm/RLMUser.mm index 2d6347d27a..7f7c35ff60 100644 --- a/Realm/RLMUser.mm +++ b/Realm/RLMUser.mm @@ -242,15 +242,15 @@ + (void)_setUpBindingContextFactory { } - (NSString *)refreshToken { - if (!_user) { - return @""; + if (!_user || _user->refresh_token().empty()) { + return nil; } return @(_user->refresh_token().c_str()); } - (NSString *)accessToken { - if (!_user) { - return @""; + if (!_user || _user->access_token().empty()) { + return nil; } return @(_user->access_token().c_str()); }