From 14249921684d0237d20e2efc68759d549843edf9 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 7 Nov 2022 10:27:03 +0300 Subject: [PATCH 1/6] Add frameNonce to Networking.Site --- Fakes/Fakes/Networking.generated.swift | 1 + .../Model/Copiable/Models+Copiable.generated.swift | 3 +++ Networking/Networking/Model/Site.swift | 7 +++++++ .../Model/Mocks/Graphs/ScreenshotsObjectGraph.swift | 1 + .../Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift | 1 + 5 files changed, 13 insertions(+) diff --git a/Fakes/Fakes/Networking.generated.swift b/Fakes/Fakes/Networking.generated.swift index f5cb263ad3f..0873c9ef972 100644 --- a/Fakes/Fakes/Networking.generated.swift +++ b/Fakes/Fakes/Networking.generated.swift @@ -1510,6 +1510,7 @@ extension Networking.Site { url: .fake(), adminURL: .fake(), loginURL: .fake(), + frameNonce: .fake(), plan: .fake(), isJetpackThePluginInstalled: .fake(), isJetpackConnected: .fake(), diff --git a/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift b/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift index deb5e0f1182..1d2abc1cacd 100644 --- a/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift +++ b/Networking/Networking/Model/Copiable/Models+Copiable.generated.swift @@ -1785,6 +1785,7 @@ extension Networking.Site { url: CopiableProp = .copy, adminURL: CopiableProp = .copy, loginURL: CopiableProp = .copy, + frameNonce: CopiableProp = .copy, plan: CopiableProp = .copy, isJetpackThePluginInstalled: CopiableProp = .copy, isJetpackConnected: CopiableProp = .copy, @@ -1800,6 +1801,7 @@ extension Networking.Site { let url = url ?? self.url let adminURL = adminURL ?? self.adminURL let loginURL = loginURL ?? self.loginURL + let frameNonce = frameNonce ?? self.frameNonce let plan = plan ?? self.plan let isJetpackThePluginInstalled = isJetpackThePluginInstalled ?? self.isJetpackThePluginInstalled let isJetpackConnected = isJetpackConnected ?? self.isJetpackConnected @@ -1816,6 +1818,7 @@ extension Networking.Site { url: url, adminURL: adminURL, loginURL: loginURL, + frameNonce: frameNonce, plan: plan, isJetpackThePluginInstalled: isJetpackThePluginInstalled, isJetpackConnected: isJetpackConnected, diff --git a/Networking/Networking/Model/Site.swift b/Networking/Networking/Model/Site.swift index 92eb81225b9..3c75ac1498d 100644 --- a/Networking/Networking/Model/Site.swift +++ b/Networking/Networking/Model/Site.swift @@ -29,6 +29,8 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable { /// public let loginURL: String + public let frameNonce: String + /// Short name for site's plan. /// public let plan: String @@ -82,6 +84,7 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable { let gmtOffset = try optionsContainer.decode(Double.self, forKey: .gmtOffset) let adminURL = try optionsContainer.decode(String.self, forKey: .adminURL) let loginURL = try optionsContainer.decode(String.self, forKey: .loginURL) + let frameNonce = try optionsContainer.decode(String.self, forKey: .frameNonce) self.init(siteID: siteID, name: name, @@ -89,6 +92,7 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable { url: url, adminURL: adminURL, loginURL: loginURL, + frameNonce: frameNonce, plan: String(), // Not created on init. Added in supplementary API request. isJetpackThePluginInstalled: isJetpackThePluginInstalled, isJetpackConnected: isJetpackConnected, @@ -107,6 +111,7 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable { url: String, adminURL: String, loginURL: String, + frameNonce: String, plan: String, isJetpackThePluginInstalled: Bool, isJetpackConnected: Bool, @@ -121,6 +126,7 @@ public struct Site: Decodable, Equatable, GeneratedFakeable, GeneratedCopiable { self.url = url self.adminURL = adminURL self.loginURL = loginURL + self.frameNonce = frameNonce self.plan = plan self.isJetpackThePluginInstalled = isJetpackThePluginInstalled self.isJetpackConnected = isJetpackConnected @@ -163,6 +169,7 @@ private extension Site { case jetpackConnectionActivePlugins = "jetpack_connection_active_plugins" case adminURL = "admin_url" case loginURL = "login_url" + case frameNonce = "frame_nonce" } enum PlanKeys: String, CodingKey { diff --git a/Yosemite/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift b/Yosemite/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift index 675e7253f64..13ba5e460ee 100644 --- a/Yosemite/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift +++ b/Yosemite/Yosemite/Model/Mocks/Graphs/ScreenshotsObjectGraph.swift @@ -39,6 +39,7 @@ struct ScreenshotObjectGraph: MockObjectGraph { url: i18n.DefaultSite.url, adminURL: i18n.DefaultSite.adminURL, loginURL: i18n.DefaultSite.loginURL, + frameNonce: "", plan: "", isJetpackThePluginInstalled: true, isJetpackConnected: true, diff --git a/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift b/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift index d9a33124ee2..ca6c99bd597 100644 --- a/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift +++ b/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift @@ -34,6 +34,7 @@ extension Storage.Site: ReadOnlyConvertible { url: url ?? "", adminURL: adminURL ?? "", loginURL: loginURL ?? "", + frameNonce: "", plan: plan ?? "", isJetpackThePluginInstalled: isJetpackThePluginInstalled, isJetpackConnected: isJetpackConnected, From ab9171d34de6e5acfeb34de6f1355094a3280afa Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 7 Nov 2022 10:27:03 +0300 Subject: [PATCH 2/6] Add frameNonce to Storage.Site --- Storage/Storage.xcodeproj/project.pbxproj | 4 +- Storage/Storage/Model/MIGRATIONS.md | 4 + .../Model/Site+CoreDataProperties.swift | 1 + .../.xccurrentversion | 2 +- .../Model 77.xcdatamodel/contents | 838 ++++++++++++++++++ .../ManagedObjectModelsInventoryTests.swift | 3 +- .../CoreData/MigrationTests.swift | 28 + .../Storage/Site+ReadOnlyConvertible.swift | 3 +- 8 files changed, 879 insertions(+), 4 deletions(-) create mode 100644 Storage/Storage/Model/WooCommerce.xcdatamodeld/Model 77.xcdatamodel/contents diff --git a/Storage/Storage.xcodeproj/project.pbxproj b/Storage/Storage.xcodeproj/project.pbxproj index 15d73b35f2a..1ad48dcea91 100644 --- a/Storage/Storage.xcodeproj/project.pbxproj +++ b/Storage/Storage.xcodeproj/project.pbxproj @@ -392,6 +392,7 @@ 9302E3AB220E1CE900DA5018 /* CoreDataIterativeMigratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataIterativeMigratorTests.swift; sourceTree = ""; }; 933A272F2222344D00C2143A /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = ""; }; A3821B262583F14863740A37 /* Pods-Storage.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Storage.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Storage/Pods-Storage.debug.xcconfig"; sourceTree = ""; }; + AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 77.xcdatamodel"; sourceTree = ""; }; AE93BE8F272C0E9F001B55EA /* GeneralStoreSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GeneralStoreSettings.swift; sourceTree = ""; }; AEC4481B290853C300BAA299 /* Model 76.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 76.xcdatamodel"; sourceTree = ""; }; B505255320EE6914008090F5 /* StorageType+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StorageType+Extensions.swift"; sourceTree = ""; }; @@ -1814,6 +1815,7 @@ DEC51AA4275B41BE009F3DF4 /* WooCommerce.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */, AEC4481B290853C300BAA299 /* Model 76.xcdatamodel */, 688908A328F8EB360081A07E /* Model 75.xcdatamodel */, 6889088D28F668330081A07E /* Model 74.xcdatamodel */, @@ -1891,7 +1893,7 @@ DEC51ADE275B41BE009F3DF4 /* Model 47.xcdatamodel */, DEC51ADF275B41BE009F3DF4 /* Model 19.xcdatamodel */, ); - currentVersion = AEC4481B290853C300BAA299 /* Model 76.xcdatamodel */; + currentVersion = AE7DF9FA2919023100C4D1ED /* Model 77.xcdatamodel */; path = WooCommerce.xcdatamodeld; sourceTree = ""; versionGroupType = wrapper.xcdatamodel; diff --git a/Storage/Storage/Model/MIGRATIONS.md b/Storage/Storage/Model/MIGRATIONS.md index 033e5493823..82a0cebc394 100644 --- a/Storage/Storage/Model/MIGRATIONS.md +++ b/Storage/Storage/Model/MIGRATIONS.md @@ -2,6 +2,10 @@ This file documents changes in the WCiOS Storage data model. Please explain any changes to the data model as well as any custom migrations. +## Model 77 (Release 11.2.0.0) +- @ealeksandrov 2022-11-07 + - Added `frameNonce` attribute to `Site` entity. + ## Model 76 (Release 11.0.0.0) - @ealeksandrov 2022-10-26 - Added `loginURL` attribute to `Site` entity. diff --git a/Storage/Storage/Model/Site+CoreDataProperties.swift b/Storage/Storage/Model/Site+CoreDataProperties.swift index a80e78665a1..3aeff41a441 100644 --- a/Storage/Storage/Model/Site+CoreDataProperties.swift +++ b/Storage/Storage/Model/Site+CoreDataProperties.swift @@ -13,6 +13,7 @@ extension Site { @NSManaged public var url: String? @NSManaged public var adminURL: String? @NSManaged public var loginURL: String? + @NSManaged public var frameNonce: String? @NSManaged public var plan: String? @NSManaged public var isWooCommerceActive: NSNumber? @NSManaged public var isWordPressStore: NSNumber? diff --git a/Storage/Storage/Model/WooCommerce.xcdatamodeld/.xccurrentversion b/Storage/Storage/Model/WooCommerce.xcdatamodeld/.xccurrentversion index 4d5aca11a5b..ec15daa0b7b 100644 --- a/Storage/Storage/Model/WooCommerce.xcdatamodeld/.xccurrentversion +++ b/Storage/Storage/Model/WooCommerce.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - Model 76.xcdatamodel + Model 77.xcdatamodel diff --git a/Storage/Storage/Model/WooCommerce.xcdatamodeld/Model 77.xcdatamodel/contents b/Storage/Storage/Model/WooCommerce.xcdatamodeld/Model 77.xcdatamodel/contents new file mode 100644 index 00000000000..7ac40febf92 --- /dev/null +++ b/Storage/Storage/Model/WooCommerce.xcdatamodeld/Model 77.xcdatamodel/contents @@ -0,0 +1,838 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Storage/StorageTests/CoreData/ManagedObjectModelsInventoryTests.swift b/Storage/StorageTests/CoreData/ManagedObjectModelsInventoryTests.swift index cb597a6403f..15f34c701cd 100644 --- a/Storage/StorageTests/CoreData/ManagedObjectModelsInventoryTests.swift +++ b/Storage/StorageTests/CoreData/ManagedObjectModelsInventoryTests.swift @@ -104,7 +104,8 @@ final class ManagedObjectModelsInventoryTests: XCTestCase { "Model 73", "Model 74", "Model 75", - "Model 76" + "Model 76", + "Model 77" ] // When diff --git a/Storage/StorageTests/CoreData/MigrationTests.swift b/Storage/StorageTests/CoreData/MigrationTests.swift index 604feb0a1fa..98fc0674468 100644 --- a/Storage/StorageTests/CoreData/MigrationTests.swift +++ b/Storage/StorageTests/CoreData/MigrationTests.swift @@ -1468,6 +1468,34 @@ final class MigrationTests: XCTestCase { let newLoginURL = try XCTUnwrap(migratedSite.value(forKey: "loginURL") as? String) XCTAssertEqual(newLoginURL, loginURL) } + + func test_migrating_from_75_to_76_adds_frameNonce_attribute() throws { + // Given + let sourceContainer = try startPersistentContainer("Model 76") + let sourceContext = sourceContainer.viewContext + + let site = insertSite(to: sourceContainer.viewContext) + try sourceContext.save() + + XCTAssertNil(site.entity.attributesByName["frameNonce"]) + + // When + let targetContainer = try migrate(sourceContainer, to: "Model 77") + let targetContext = targetContainer.viewContext + + let migratedSite = try XCTUnwrap(targetContext.first(entityName: "Site")) + let defaultFrameNonce = migratedSite.value(forKey: "frameNonce") + + let frameNonce = "e7bfd785f0" + migratedSite.setValue(frameNonce, forKey: "frameNonce") + + // Then + // Default value is nil. + XCTAssertNil(defaultFrameNonce) + + let newFrameNonce = try XCTUnwrap(migratedSite.value(forKey: "frameNonce") as? String) + XCTAssertEqual(newFrameNonce, frameNonce) + } } // MARK: - Persistent Store Setup and Migrations diff --git a/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift b/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift index ca6c99bd597..3de08512173 100644 --- a/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift +++ b/Yosemite/Yosemite/Model/Storage/Site+ReadOnlyConvertible.swift @@ -15,6 +15,7 @@ extension Storage.Site: ReadOnlyConvertible { url = site.url adminURL = site.adminURL loginURL = site.loginURL + frameNonce = site.frameNonce // plan = site.plan // We're not assigning the plan here because it's not sent on the intial API request. isJetpackThePluginInstalled = site.isJetpackThePluginInstalled isJetpackConnected = site.isJetpackConnected @@ -34,7 +35,7 @@ extension Storage.Site: ReadOnlyConvertible { url: url ?? "", adminURL: adminURL ?? "", loginURL: loginURL ?? "", - frameNonce: "", + frameNonce: frameNonce ?? "", plan: plan ?? "", isJetpackThePluginInstalled: isJetpackThePluginInstalled, isJetpackConnected: isJetpackConnected, From 312ef263e2fab219df0d451dfd8663f4b6118671 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 7 Nov 2022 10:27:03 +0300 Subject: [PATCH 3/6] Add frameNonce to AccountMapperTests --- Networking/NetworkingTests/Mapper/AccountMapperTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Networking/NetworkingTests/Mapper/AccountMapperTests.swift b/Networking/NetworkingTests/Mapper/AccountMapperTests.swift index bd83b8c1b4f..3f55ab49f42 100644 --- a/Networking/NetworkingTests/Mapper/AccountMapperTests.swift +++ b/Networking/NetworkingTests/Mapper/AccountMapperTests.swift @@ -35,6 +35,7 @@ final class AccountMapperTests: XCTestCase { XCTAssertEqual(first.url, "https://some-testing-url.testing.blog") XCTAssertEqual(first.adminURL, "https://some-testing-url.here/wp-admin/") XCTAssertEqual(first.loginURL, "https://some-testing-url.here/wp-login.php") + XCTAssertEqual(first.frameNonce, "73ae7163d8") XCTAssertFalse(first.isJetpackCPConnected) XCTAssertTrue(first.isJetpackConnected) XCTAssertTrue(first.isJetpackThePluginInstalled) @@ -52,6 +53,7 @@ final class AccountMapperTests: XCTestCase { XCTAssertEqual(second.url, "https://thoughts.testing.blog") XCTAssertEqual(second.adminURL, "https://thoughts.testing.blog/wp-admin/") XCTAssertEqual(second.loginURL, "https://thoughts.testing.blog/wp-login.php") + XCTAssertEqual(second.frameNonce, "e7bfd785f0") XCTAssertTrue(second.isJetpackCPConnected) XCTAssertTrue(second.isJetpackConnected) XCTAssertFalse(second.isJetpackThePluginInstalled) From 8a436677e3b16cb99c58b7d20341e41ba172f844 Mon Sep 17 00:00:00 2001 From: Evgeny Aleksandrov Date: Mon, 7 Nov 2022 10:27:03 +0300 Subject: [PATCH 4/6] Add frame_nonce to sites query --- Networking/Networking/Remote/AccountRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Networking/Networking/Remote/AccountRemote.swift b/Networking/Networking/Remote/AccountRemote.swift index 8a4b488b635..1ddbf03745f 100644 --- a/Networking/Networking/Remote/AccountRemote.swift +++ b/Networking/Networking/Remote/AccountRemote.swift @@ -85,7 +85,7 @@ public class AccountRemote: Remote, AccountRemoteProtocol { let path = "me/sites" let parameters = [ "fields": "ID,name,description,URL,options,jetpack,jetpack_connection", - "options": "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset,jetpack_connection_active_plugins,admin_url,login_url" + "options": "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset,jetpack_connection_active_plugins,admin_url,login_url,frame_nonce" ] let request = DotcomRequest(wordpressApiVersion: .mark1_1, method: .get, path: path, parameters: parameters) From 8026886c55f8a11b9f927a5ae76028d13a68c47e Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Mon, 7 Nov 2022 15:34:32 +0000 Subject: [PATCH 5/6] Update test name for migration to Model 77 --- Storage/StorageTests/CoreData/MigrationTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Storage/StorageTests/CoreData/MigrationTests.swift b/Storage/StorageTests/CoreData/MigrationTests.swift index 98fc0674468..32dbcfd3da8 100644 --- a/Storage/StorageTests/CoreData/MigrationTests.swift +++ b/Storage/StorageTests/CoreData/MigrationTests.swift @@ -1469,7 +1469,7 @@ final class MigrationTests: XCTestCase { XCTAssertEqual(newLoginURL, loginURL) } - func test_migrating_from_75_to_76_adds_frameNonce_attribute() throws { + func test_migrating_from_76_to_77_adds_frameNonce_attribute() throws { // Given let sourceContainer = try startPersistentContainer("Model 76") let sourceContext = sourceContainer.viewContext From 78be945645847e72e980504230d4dabcbe87c6e1 Mon Sep 17 00:00:00 2001 From: rachelmcr Date: Mon, 7 Nov 2022 20:28:52 +0000 Subject: [PATCH 6/6] Update UI test mocks to include frame_nonce option --- .../Mocks/mappings/me/rest_v11_me_sites.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/WooCommerce/WooCommerceUITests/Mocks/mappings/me/rest_v11_me_sites.json b/WooCommerce/WooCommerceUITests/Mocks/mappings/me/rest_v11_me_sites.json index 021bbfde11d..f3b7c93afee 100644 --- a/WooCommerce/WooCommerceUITests/Mocks/mappings/me/rest_v11_me_sites.json +++ b/WooCommerce/WooCommerceUITests/Mocks/mappings/me/rest_v11_me_sites.json @@ -7,7 +7,7 @@ "equalTo": "ID,name,description,URL,options,jetpack,jetpack_connection" }, "options": { - "equalTo": "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset,jetpack_connection_active_plugins,admin_url,login_url" + "equalTo": "timezone,is_wpcom_store,woocommerce_is_active,gmt_offset,jetpack_connection_active_plugins,admin_url,login_url,frame_nonce" } } }, @@ -38,7 +38,8 @@ "wp_max_memory_limit": "268435456", "is_multi_network": false, "is_multi_site": false, - "file_mod_disabled": ["wp_auto_update_core_disabled"] + "file_mod_disabled": ["wp_auto_update_core_disabled"], + "frame_nonce": "e7bfd785f0" } } ]