Skip to content

Commit

Permalink
chore: kickoff release
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh62 authored Jun 25, 2024
2 parents b9a7baa + 3abc90b commit 6f65406
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,21 @@ class FetchAuthSessionOperationHelper: DefaultLogger {
authStateMachine: AuthStateMachine,
forceRefresh: Bool) async throws -> AuthSession {

var event: AuthorizationEvent
if forceRefresh || !credentials.areValid() {
if case .identityPoolWithFederation(
let federatedToken,
let identityId,
_
) = credentials {
event = AuthorizationEvent(
eventType: .startFederationToIdentityPool(federatedToken, identityId)
)
} else {
var event: AuthorizationEvent
switch credentials {
case .identityPoolWithFederation(let federatedToken, let identityId, _):
event = AuthorizationEvent(eventType: .startFederationToIdentityPool(federatedToken, identityId))
case .noCredentials:
event = AuthorizationEvent(eventType: .fetchUnAuthSession)
case .userPoolOnly, .identityPoolOnly, .userPoolAndIdentityPool:
event = AuthorizationEvent(eventType: .refreshSession(forceRefresh))
}
await authStateMachine.send(event)
return try await listenForSession(authStateMachine: authStateMachine)
} else {
return credentials.cognitoSession
}
return credentials.cognitoSession
}

func listenForSession(authStateMachine: AuthStateMachine) async throws -> AuthSession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,59 @@ class AWSAuthFetchSignInSessionOperationTests: BaseAuthorizationTests {
}
}

/// Test fetch session with authorization in error state
///
/// - Given: An auth plugin with signedOut state
/// - When:
/// - I invoke fetchAuthSession and mock notSignedIn for getTokens
/// - Then:
/// - I should get an a valid session with the following details:
/// - isSignedIn = false
/// - aws credentails = valid values
/// - identity id = valid values
/// - cognito tokens = signedOut
///
func testFetchSessionWithAuthorizationInErrorState() async throws {

let initialState = AuthState.configured(
AuthenticationState.signedOut(.testData),
AuthorizationState.error(.sessionError(.service(AuthError.unknown("error")), .noCredentials)))

let getId: MockIdentity.MockGetIdResponse = { _ in
return .init(identityId: "mockIdentityId")
}

let getCredentials: MockIdentity.MockGetCredentialsResponse = { _ in
let credentials = CognitoIdentityClientTypes.Credentials(accessKeyId: "accessKey",
expiration: Date(),
secretKey: "secret",
sessionToken: "session")
return .init(credentials: credentials, identityId: "responseIdentityID")
}

let plugin = configurePluginWith(identityPool: {
MockIdentity(mockGetIdResponse: getId,
mockGetCredentialsResponse: getCredentials) },
initialState: initialState)

let session = try await plugin.fetchAuthSession(options: AuthFetchSessionRequest.Options())
XCTAssertFalse(session.isSignedIn)

let creds = try? (session as? AuthAWSCredentialsProvider)?.getAWSCredentials().get()
XCTAssertNotNil(creds?.accessKeyId)
XCTAssertNotNil(creds?.secretAccessKey)

let identityId = try? (session as? AuthCognitoIdentityProvider)?.getIdentityId().get()
XCTAssertNotNil(identityId)

let tokensResult = (session as? AuthCognitoTokensProvider)?.getCognitoTokens()
guard case .failure(let error) = tokensResult,
case .signedOut = error else {
XCTFail("Should return signed out error")
return
}
}

/// Test signedOut state credential refresh
///
/// - Given: Given an auth plugin with signedOut state and expired AWS credentials
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
try await clearDataStore()
var snapshots = [DataStoreQuerySnapshot<Post>]()
let snapshotWithIsSynced = expectation(description: "query snapshot with isSynced true")
snapshotWithIsSynced.assertForOverFulfill = false
Amplify.Publisher.create(Amplify.DataStore.observeQuery(for: Post.self)).sink { completed in
switch completed {
case .finished:
Expand Down Expand Up @@ -130,6 +131,7 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
var isObserveQueryReadyForTest = false
let observeQueryReadyForTest = expectation(description: "received query snapshot with .isSynced true")
let snapshotWithPost = expectation(description: "received first snapshot")
snapshotWithPost.assertForOverFulfill = false
let post = Post(title: "title", content: "content", createdAt: .now())
Amplify.Publisher.create(Amplify.DataStore.observeQuery(for: Post.self)).sink { completed in
switch completed {
Expand Down Expand Up @@ -339,6 +341,7 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
try await clearDataStore()

let snapshotWithIsSynced = expectation(description: "query snapshot with isSynced true")
snapshotWithIsSynced.assertForOverFulfill = false
var snapshots = [DataStoreQuerySnapshot<Post>]()

Amplify.Publisher.create(Amplify.DataStore.observeQuery(for: Post.self)).sink { completed in
Expand All @@ -363,7 +366,6 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
await fulfillment(of: [snapshotWithIsSynced], timeout: 30)
XCTAssertTrue(snapshots.count >= 2)
XCTAssertFalse(snapshots[0].isSynced)
XCTAssertEqual(1, snapshots.filter({ $0.isSynced }).count)

let theSyncedSnapshot = snapshots.first(where: { $0.isSynced })
XCTAssertNotNil(theSyncedSnapshot)
Expand Down
4 changes: 0 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,6 @@ let package = Package(
name: "AWSPluginsCore",
targets: ["AWSPluginsCore"]
),
.library(
name: "InternalAmplifyCredentials",
targets: ["InternalAmplifyCredentials"]
),
.library(
name: "AWSAPIPlugin",
targets: ["AWSAPIPlugin"]
Expand Down
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,17 @@ of the library.

Applications that evaluate all members of an enumeration using a `switch` statement can add a `default` case to prevent new cases from causing compile warnings or errors.

#### Semantic versioning and dependencies update

We follow [semantic versioning for updating our dependencies](https://semver.org/#what-should-i-do-if-i-update-my-own-dependencies-without-changing-the-public-api).

## License

This library is licensed under the Apache 2.0 License.

## Installation

Amplify requires the following Xcode versions, according to the targeted platform:

| Platform | Xcode Version |
| -------------:| ------------: |
| iOS | 15.0+ |
| macOS | 15.0+ |
| tvOS | 15.0+ |
| watchOS | 15.0+ |
| visionOS | 15 beta 2+ |
Amplify requires Xcode 15.0 or later for all the supported platforms.

| For more detailed instructions, follow the getting started guides in our [documentation site](https://docs.amplify.aws/lib/q/platform/ios) |
|-------------------------------------------------|
Expand Down

0 comments on commit 6f65406

Please sign in to comment.