Skip to content

Commit 13ffa2d

Browse files
authored
chore: kickoff release
2 parents 783b945 + 1a6056a commit 13ffa2d

File tree

4 files changed

+108
-26
lines changed

4 files changed

+108
-26
lines changed

AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/CascadeDeleteOperation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public class CascadeDeleteOperation<M: Model>: AsynchronousOperation {
161161
}
162162

163163
let modelIds = queriedModels.map { $0.identifier(schema: self.modelSchema).stringValue }
164-
logMessage("[CascadeDelete.1] Deleting \(modelSchema.name) with identifiers: \(modelIds)")
164+
logMessage("[CascadeDelete.1] Deleting \(self.modelSchema.name) with identifiers: \(modelIds)")
165165

166166
associatedModels = await self.recurseQueryAssociatedModels(modelSchema: self.modelSchema, ids: modelIds)
167167

@@ -260,7 +260,7 @@ public class CascadeDeleteOperation<M: Model>: AsynchronousOperation {
260260

261261
switch deleteResult {
262262
case .success:
263-
logMessage("[CascadeDelete.3] Local cascade delete of \(modelSchema.name) successful!")
263+
logMessage("[CascadeDelete.3] Local cascade delete of \(self.modelSchema.name) successful!")
264264
return .success(QueryAndDeleteResult(deletedModels: models,
265265
associatedModels: associatedModels))
266266
case .failure(let error):
@@ -447,7 +447,7 @@ public class CascadeDeleteOperation<M: Model>: AsynchronousOperation {
447447
syncEngine: RemoteSyncEngineBehavior,
448448
dataStoreError: DataStoreError?,
449449
completion: @escaping DataStoreCallback<Void>) {
450-
logMessage("[CascadeDelete.4] Begin syncing \(models.count) \(modelSchema.name) model for deletion")
450+
logMessage("[CascadeDelete.4] Begin syncing \(models.count) \(self.modelSchema.name) model for deletion")
451451
var graphQLFilterJSON: String?
452452
if let predicate = predicate {
453453
do {

AmplifyPlugins/DataStore/Sources/AWSDataStorePlugin/Storage/StorageEngine+SyncRequirement.swift

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ extension StorageEngine {
3434
))
3535
}
3636

37-
let authPluginRequired = StorageEngine.requiresAuthPlugin(api)
37+
let authPluginRequired = StorageEngine.requiresAuthPlugin(
38+
api,
39+
authModeStrategy: dataStoreConfiguration.authModeStrategyType
40+
)
3841
guard authPluginRequired else {
3942
syncEngine.start(api: apiGraphQL, auth: nil)
4043
return .success(.successfullyInitialized)
@@ -96,20 +99,45 @@ extension StorageEngine {
9699
}
97100
}
98101

99-
static func requiresAuthPlugin(_ apiPlugin: APICategoryPlugin) -> Bool {
102+
static func requiresAuthPlugin(
103+
_ apiPlugin: APICategoryPlugin,
104+
authModeStrategy: AuthModeStrategyType
105+
) -> Bool {
100106
let modelsRequireAuthPlugin = ModelRegistry.modelSchemas.contains { schema in
101107
guard schema.isSyncable else {
102108
return false
103109
}
104-
return StorageEngine.requiresAuthPlugin(apiPlugin, authRules: schema.authRules)
110+
return requiresAuthPlugin(apiPlugin,
111+
authRules: schema.authRules,
112+
authModeStrategy: authModeStrategy)
105113
}
106114

107115
return modelsRequireAuthPlugin
108116
}
109117

110-
static func requiresAuthPlugin(_ apiPlugin: APICategoryPlugin, authRules: [AuthRule]) -> Bool {
111-
if let rulesRequireAuthPlugin = authRules.requireAuthPlugin {
112-
return rulesRequireAuthPlugin
118+
static func requiresAuthPlugin(
119+
_ apiPlugin: APICategoryPlugin,
120+
authRules: [AuthRule],
121+
authModeStrategy: AuthModeStrategyType
122+
) -> Bool {
123+
switch authModeStrategy {
124+
case .default:
125+
if authRules.isEmpty {
126+
return false
127+
}
128+
// Only use the auth rule as determination for auth plugin requirement when there is
129+
// exactly one. If there is more than one auth rule AND multi-auth is not enabled,
130+
// then immediately fall back to using the default auth type configured on the APIPlugin because
131+
// we do not have enough information to know which provider to use to make the determination.
132+
if authRules.count == 1,
133+
let singleAuthRule = authRules.first,
134+
let ruleRequireAuthPlugin = singleAuthRule.requiresAuthPlugin {
135+
return ruleRequireAuthPlugin
136+
}
137+
case .multiAuth:
138+
if let rulesRequireAuthPlugin = authRules.requireAuthPlugin {
139+
return rulesRequireAuthPlugin
140+
}
113141
}
114142

115143
// Fall back to the endpoint's auth type if a determination cannot be made from the auth rules. This can

AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Sync/StorageEngineSyncRequirementsTests.swift

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,80 +17,91 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
1717

1818
func testRequiresAuthPluginFalseForMissingAuthRules() {
1919
let apiPlugin = MockAPICategoryPlugin()
20-
let result = StorageEngine.requiresAuthPlugin(apiPlugin)
21-
XCTAssertFalse(result)
20+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authModeStrategy: .default))
21+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authModeStrategy: .multiAuth))
2222
}
2323

2424
func testRequiresAuthPluginSingleAuthRuleAPIKey() {
2525
let apiPlugin = MockAPICategoryPlugin()
2626
let authRules = [AuthRule(allow: .owner, provider: .apiKey)]
27-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
27+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
28+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
2829
}
2930

3031
func testRequiresAuthPluginSingleAuthRuleOIDC() {
3132
let apiPlugin = MockAPICategoryPlugin()
3233
let authRules = [AuthRule(allow: .owner, provider: .oidc)]
33-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
34+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
35+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
3436
}
3537

3638
func testRequiresAuthPluginSingleAuthRuleFunction() {
3739
let apiPlugin = MockAPICategoryPlugin()
3840
let authRules = [AuthRule(allow: .private, provider: .function)]
39-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
41+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
42+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
4043
}
4144

4245
func testRequiresAuthPluginSingleAuthRuleUserPools() {
4346
let apiPlugin = MockAPICategoryPlugin()
4447
let authRules = [AuthRule(allow: .owner, provider: .userPools)]
45-
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
48+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
49+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
4650
}
4751

4852
func testRequiresAuthPluginSingleAuthRuleIAM() {
4953
let apiPlugin = MockAPICategoryPlugin()
5054
let authRules = [AuthRule(allow: .owner, provider: .iam)]
51-
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
55+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
56+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
5257
}
5358

5459
func testRequiresAuthPluginNoProvidersWithAuthTypeFunction() {
5560
let authRules = [AuthRule(allow: .owner)]
5661
let apiPlugin = MockAPIAuthInformationPlugin()
5762
apiPlugin.authType = .function
58-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
63+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
64+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
5965
}
6066

6167
func testRequiresAuthPluginNoProvidersWithAuthTypeAPIKey() {
6268
let authRules = [AuthRule(allow: .owner)]
6369
let apiPlugin = MockAPIAuthInformationPlugin()
6470
apiPlugin.authType = .apiKey
65-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
71+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
72+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
6673
}
6774

6875
func testRequiresAuthPluginNoProvidersWithAuthTypeUserPools() {
6976
let authRules = [AuthRule(allow: .owner)]
7077
let apiPlugin = MockAPIAuthInformationPlugin()
7178
apiPlugin.authType = .amazonCognitoUserPools
72-
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
79+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
80+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
7381
}
7482

7583
func testRequiresAuthPluginNoProvidersWithAuthTypeIAM() {
7684
let authRules = [AuthRule(allow: .owner)]
7785
let apiPlugin = MockAPIAuthInformationPlugin()
7886
apiPlugin.authType = .awsIAM
79-
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
87+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
88+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
8089
}
8190

8291
func testRequiresAuthPluginNoProvidersWithAuthTypeODIC() {
8392
let authRules = [AuthRule(allow: .owner)]
8493
let apiPlugin = MockAPIAuthInformationPlugin()
8594
apiPlugin.authType = .openIDConnect
86-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
95+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
96+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
8797
}
8898

8999
func testRequiresAuthPluginNoProvidersWithAuthTypeNone() {
90100
let authRules = [AuthRule(allow: .owner)]
91101
let apiPlugin = MockAPIAuthInformationPlugin()
92102
apiPlugin.authType = AWSAuthorizationType.none
93-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
103+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
104+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
94105
}
95106

96107
func testRequiresAuthPluginOIDCProvider() {
@@ -99,7 +110,41 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
99110
apiPlugin.defaultAuthTypeError = APIError.unknown("Could not get default auth type", "", nil)
100111
let oidcProvider = MockOIDCAuthProvider()
101112
apiPlugin.authProviderFactory = MockAPIAuthProviderFactory(oidcProvider: oidcProvider)
102-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
113+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
114+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
115+
}
116+
117+
func testRequiresAuthPluginOIDCProvider_MultiAuthRules() {
118+
// OIDC requires an auth provider on the API, this is added below
119+
let authRules = [AuthRule(allow: .owner, provider: .oidc),
120+
AuthRule(allow: .private, provider: .iam)]
121+
let apiPlugin = MockAPIAuthInformationPlugin()
122+
apiPlugin.defaultAuthTypeError = APIError.unknown("Could not get default auth type", "", nil)
123+
let oidcProvider = MockOIDCAuthProvider()
124+
apiPlugin.authProviderFactory = MockAPIAuthProviderFactory(oidcProvider: oidcProvider)
125+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin,
126+
authRules: authRules,
127+
authModeStrategy: .default),
128+
"Should be false since OIDC is the default auth type on the API.")
129+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin,
130+
authRules: authRules,
131+
authModeStrategy: .multiAuth),
132+
"Should be true since IAM requires auth plugin.")
133+
}
134+
135+
func testRequiresAuthPluginUserPoolProvider_MultiAuthRules() {
136+
let authRules = [AuthRule(allow: .owner, provider: .userPools),
137+
AuthRule(allow: .private, provider: .iam)]
138+
let apiPlugin = MockAPIAuthInformationPlugin()
139+
apiPlugin.authType = AWSAuthorizationType.amazonCognitoUserPools
140+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin,
141+
authRules: authRules,
142+
authModeStrategy: .default),
143+
"Should be true since UserPool is the default auth type on the API.")
144+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin,
145+
authRules: authRules,
146+
authModeStrategy: .multiAuth),
147+
"Should be true since both UserPool and IAM requires auth plugin.")
103148
}
104149

105150
func testRequiresAuthPluginFunctionProvider() {
@@ -108,14 +153,16 @@ class StorageEngineSyncRequirementsTests: XCTestCase {
108153
apiPlugin.defaultAuthTypeError = APIError.unknown("Could not get default auth type", "", nil)
109154
let functionProvider = MockFunctionAuthProvider()
110155
apiPlugin.authProviderFactory = MockAPIAuthProviderFactory(functionProvider: functionProvider)
111-
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
156+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
157+
XCTAssertFalse(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
112158
}
113159

114160
func testRequiresAuthPluginWithAuthRules() {
115161
let authRules = [AuthRule(allow: .owner)]
116162
let apiPlugin = MockAPIAuthInformationPlugin()
117163
apiPlugin.defaultAuthTypeError = APIError.unknown("Could not get default auth type", "", nil)
118-
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules))
164+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .default))
165+
XCTAssertTrue(StorageEngine.requiresAuthPlugin(apiPlugin, authRules: authRules, authModeStrategy: .multiAuth))
119166
}
120167

121168
// MARK: - AuthRules tests

AmplifyPlugins/Logging/Sources/AWSCloudWatchLoggingPlugin/Configuration/DefaultRemoteLoggingConstraintsProvider.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,14 @@ public class DefaultRemoteLoggingConstraintsProvider: RemoteLoggingConstraintsPr
5858
let loggingConstraint = try JSONDecoder().decode(LoggingConstraints.self, from: data)
5959
loggingConstraintsLocalStore.setLocalLoggingConstraints(loggingConstraints: loggingConstraint)
6060

61-
if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "If-None-Match") {
61+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match
62+
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag
63+
// the response header should only use the ETag header field in accordance with Http protocol spec
64+
// but we need to also look at `If-None-Match` due to the initial/old lambda documentation recommending to
65+
// `If-None-Match` to return the ETag
66+
if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "ETag") {
67+
loggingConstraintsLocalStore.setLocalLoggingConstraintsEtag(etag: etag)
68+
} else if let etag = (response as? HTTPURLResponse)?.value(forHTTPHeaderField: "If-None-Match") {
6269
loggingConstraintsLocalStore.setLocalLoggingConstraintsEtag(etag: etag)
6370
}
6471
return loggingConstraint

0 commit comments

Comments
 (0)