Skip to content

Commit

Permalink
chore: kickoff release
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 authored Sep 28, 2023
2 parents 1368007 + 7d9e3da commit 025dd35
Show file tree
Hide file tree
Showing 24 changed files with 1,841 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
- name: Dependency Review
uses: actions/dependency-review-action@7d90b4f05fea31dde1c4a1fb3fa787e197ea93ab # v3.0.7
with:
config-file: aws-amplify/amplify-ci-support/.github/dependency-review-config.yml@main
config-file: amazon-ospo/dependency-review-config/default/dependency-review-config.yml@main
5 changes: 5 additions & 0 deletions .github/workflows/integ_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ jobs:
needs: prepare-for-test
uses: ./.github/workflows/integ_test_storage.yml
secrets: inherit

logging-test:
needs: prepare-for-test
uses: ./.github/workflows/integ_test_logging.yml
secrets: inherit
90 changes: 90 additions & 0 deletions .github/workflows/integ_test_logging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Integration Tests | Logging
on:
workflow_dispatch:
workflow_call:

permissions:
id-token: write
contents: read

jobs:
logging-integration-test-iOS:
runs-on: macos-12
environment: IntegrationTest
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
persist-credentials: false

- name: Make directory
run: mkdir -p ~/.aws-amplify/amplify-ios/testconfiguration/

- name: Copy integration test resouces
uses: ./.github/composite_actions/download_test_configuration
with:
resource_subfolder: logging
aws_role_to_assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws_region: ${{ secrets.AWS_REGION }}
aws_s3_bucket: ${{ secrets.AWS_S3_BUCKET_INTEG_V2 }}

- name: Run Integration test
uses: ./.github/composite_actions/run_xcodebuild_test
with:
project_path: ./AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginHostApp
scheme: AWSCloudWatchLoggingPluginIntegrationTests

logging-integration-test-tvOS:
runs-on: macos-13
environment: IntegrationTest
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
persist-credentials: false

- name: Make directory
run: mkdir -p ~/.aws-amplify/amplify-ios/testconfiguration/

- name: Copy integration test resouces
uses: ./.github/composite_actions/download_test_configuration
with:
resource_subfolder: logging
aws_role_to_assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws_region: ${{ secrets.AWS_REGION }}
aws_s3_bucket: ${{ secrets.AWS_S3_BUCKET_INTEG_V2 }}

- name: Run Integration test
uses: ./.github/composite_actions/run_xcodebuild_test
with:
project_path: ./AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginHostApp
scheme: AWSCloudWatchLoggingPluginIntegrationTests
destination: platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest
sdk: appletvsimulator
xcode_path: '/Applications/Xcode_14.3.app'

logging-integration-test-watchOS:
runs-on: macos-13
environment: IntegrationTest
steps:
- uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b
with:
persist-credentials: false

- name: Make directory
run: mkdir -p ~/.aws-amplify/amplify-ios/testconfiguration/

- name: Copy integration test resouces
uses: ./.github/composite_actions/download_test_configuration
with:
resource_subfolder: logging
aws_role_to_assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
aws_region: ${{ secrets.AWS_REGION }}
aws_s3_bucket: ${{ secrets.AWS_S3_BUCKET_INTEG_V2 }}

- name: Run Integration test
uses: ./.github/composite_actions/run_xcodebuild_test
with:
project_path: ./AmplifyPlugins/Logging/Tests/AWSCloudWatchLoggingPluginHostApp
scheme: AWSCloudWatchLoggingPluginIntegrationTestsWatch
destination: platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest
sdk: watchsimulator
xcode_path: '/Applications/Xcode_14.3.app'
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ final class InitialSyncOperation: AsynchronousOperation {
switch result {
case .failure(let apiError):
if self.isAuthSignedOutError(apiError: apiError) {
self.dataStoreConfiguration.errorHandler(DataStoreError.api(apiError))
self.log.error("Sync for \(self.modelSchema.name) failed due to signed out error \(apiError.errorDescription)")
}

// TODO: Retry query on error
self.finish(result: .failure(DataStoreError.api(apiError)))
let error = DataStoreError.api(apiError)
self.dataStoreConfiguration.errorHandler(error)
self.finish(result: .failure(error))
case .success(let graphQLResult):
self.handleQueryResults(lastSyncTime: lastSyncTime, graphQLResult: graphQLResult)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ final class AWSInitialSyncOrchestrator: InitialSyncOrchestrator {
allMessages.joined(separator: "\n"),
underlyingError
)

return .failure(syncError)
}

Expand Down Expand Up @@ -208,7 +209,7 @@ extension AWSInitialSyncOrchestrator {
return errorTypeValue
}

private func isUnauthorizedError(_ error: DataStoreError) -> Bool {
func isUnauthorizedError(_ error: DataStoreError) -> Bool {
guard case let .sync(_, _, underlyingError) = error,
let datastoreError = underlyingError as? DataStoreError
else {
Expand Down Expand Up @@ -245,6 +246,22 @@ extension AWSInitialSyncOrchestrator {
case .unauthorized = AppSyncErrorType(errorTypeValue) {
return true
}

// Check is API error is of unauthorized type
if case let .api(amplifyError, _) = datastoreError,
let apiError = amplifyError as? APIError {
if case .operationError(let errorDescription, _, _) = apiError,
errorDescription.range(of: "Unauthorized",
options: .caseInsensitive) != nil {
return true
}

if case .httpStatusError(let statusCode, _) = apiError,
(statusCode == 401 || statusCode == 403) {
return true
}
}

return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import XCTest
import Foundation

@testable import Amplify
@testable import AmplifyTestCommon
Expand Down Expand Up @@ -101,7 +102,7 @@ class InitialSyncOrchestratorTests: XCTestCase {
Amplify.Hub.removeListener(hubListener)
sink.cancel()
}

/// - Given: An InitialSyncOrchestrator with a model dependency graph, API is expected to return an error for certain models
/// - When:
/// - The orchestrator starts up
Expand Down Expand Up @@ -200,7 +201,7 @@ class InitialSyncOrchestratorTests: XCTestCase {
Amplify.Hub.removeListener(hubListener)
sink.cancel()
}

/// - Given: An InitialSyncOrchestrator with a model dependency graph containing no associations
/// - When:
/// - The orchestrator starts up
Expand Down Expand Up @@ -409,4 +410,47 @@ class InitialSyncOrchestratorTests: XCTestCase {
sink.cancel()
}

/// - Given:
/// An InitialSyncOrchestrator with a model dependency graph
/// - When:
/// isUnauthorized() is called with an API Error with status code 401, 403 or "Unauthorized" description
/// and return false for other cases
/// - Then:
/// - It should return true for unauthorized cases and false for other cases
func testIsUnauthorized() {
let apiPlugin = MockAPICategoryPlugin()
let storageAdapter = MockSQLiteStorageEngineAdapter()
let reconciliationQueue = MockReconciliationQueue()

let orchestrator =
AWSInitialSyncOrchestrator(dataStoreConfiguration: .default,
authModeStrategy: AWSDefaultAuthModeStrategy(),
api: apiPlugin,
reconciliationQueue: reconciliationQueue,
storageAdapter: storageAdapter)

let error1 = DataStoreError.api(APIError.httpStatusError(401, HTTPURLResponse(url: URL(string: "https://aws.amazon.com")!,
statusCode: 401,
httpVersion: nil,
headerFields: nil)!))
XCTAssertTrue(orchestrator.isUnauthorizedError(DataStoreError.sync("", "", error1)))

let error2 = DataStoreError.api(APIError.httpStatusError(403, HTTPURLResponse(url: URL(string: "https://aws.amazon.com")!,
statusCode: 403,
httpVersion: nil,
headerFields: nil)!))
XCTAssertTrue(orchestrator.isUnauthorizedError(DataStoreError.sync("", "", error2)))

let error3 = DataStoreError.api(APIError.httpStatusError(404, HTTPURLResponse(url: URL(string: "https://aws.amazon.com")!,
statusCode: 404,
httpVersion: nil,
headerFields: nil)!))
XCTAssertFalse(orchestrator.isUnauthorizedError(DataStoreError.sync("", "", error3)))

let error4 = DataStoreError.api(APIError.operationError("Unauthorized error", "", nil))
XCTAssertTrue(orchestrator.isUnauthorizedError(DataStoreError.sync("", "", error4)))

let error5 = DataStoreError.api(APIError.operationError("An error occurred", "", nil))
XCTAssertFalse(orchestrator.isUnauthorizedError(DataStoreError.sync("", "", error5)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class AWSCloudWatchLoggingPlugin: LoggingCategoryPlugin {
localStore.reset()
}

DispatchQueue.main.async {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(500)) {
self.loggingClient.takeUserIdentifierFromCurrentUser()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import AWSCloudWatchLogs

class AWSCloudWatchClientHelper {
static func getFilterLogEventCount(client: CloudWatchLogsClientProtocol?, filterPattern: String?, startTime: Date?, endTime: Date?, logGroupName: String?) async throws -> [CloudWatchLogsClientTypes.FilteredLogEvent]? {
let filterEventInput = FilterLogEventsInput(endTime: endTime?.epochMilliseconds, filterPattern: filterPattern, logGroupName: logGroupName, startTime: startTime?.epochMilliseconds)
let response = try await client?.filterLogEvents(input: filterEventInput)
return response?.events
}
}

extension Date {
var epochMilliseconds: Int {
Int(self.timeIntervalSince1970 * 1_000)
}
}
Loading

0 comments on commit 025dd35

Please sign in to comment.