diff --git a/.autover/autover.json b/.autover/autover.json new file mode 100644 index 0000000..f3f5722 --- /dev/null +++ b/.autover/autover.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Extensions.CognitoAuthentication", + "Path": "src/Amazon.Extensions.CognitoAuthentication/Amazon.Extensions.CognitoAuthentication.csproj" + } + ], + "UseCommitsForChangelog": false, + "DefaultIncrementType": "Patch", + "ChangeFilesDetermineIncrementType": true +} \ No newline at end of file diff --git a/.github/workflows/aws-ci.yml b/.github/workflows/aws-ci.yml new file mode 100644 index 0000000..f35e624 --- /dev/null +++ b/.github/workflows/aws-ci.yml @@ -0,0 +1,46 @@ +name: AWS CI + +on: + workflow_dispatch: + pull_request: + branches: + - master + - dev + - 'feature/**' + +permissions: + id-token: write + +jobs: + run-ci: + runs-on: ubuntu-latest + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4 + with: + role-to-assume: ${{ secrets.CI_MAIN_TESTING_ACCOUNT_ROLE_ARN }} + role-duration-seconds: 7200 + aws-region: us-west-2 + - name: Invoke Load Balancer Lambda + id: lambda + shell: pwsh + run: | + aws lambda invoke response.json --function-name "${{ secrets.CI_TESTING_LOAD_BALANCER_LAMBDA_NAME }}" --cli-binary-format raw-in-base64-out --payload '{"Roles": "${{ secrets.CI_TEST_RUNNER_ACCOUNT_ROLES }}", "ProjectName": "${{ secrets.CI_TESTING_CODE_BUILD_PROJECT_NAME }}", "Branch": "${{ github.sha }}"}' + $roleArn=$(cat ./response.json) + "roleArn=$($roleArn -replace '"', '')" >> $env:GITHUB_OUTPUT + - name: Configure Test Runner Credentials + uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 #v4 + with: + role-to-assume: ${{ steps.lambda.outputs.roleArn }} + role-duration-seconds: 7200 + aws-region: us-west-2 + - name: Run Tests on AWS + id: codebuild + uses: aws-actions/aws-codebuild-run-build@v1 + with: + project-name: ${{ secrets.CI_TESTING_CODE_BUILD_PROJECT_NAME }} + - name: CodeBuild Link + shell: pwsh + run: | + $buildId = "${{ steps.codebuild.outputs.aws-build-id }}" + echo $buildId \ No newline at end of file diff --git a/.github/workflows/create-release-pr.yml b/.github/workflows/create-release-pr.yml new file mode 100644 index 0000000..2591e5f --- /dev/null +++ b/.github/workflows/create-release-pr.yml @@ -0,0 +1,101 @@ +# This GitHub Workflow will create a new release branch that contains the updated C# project versions and changelog. +# The workflow will also create a PR that targets `dev` from the release branch. +name: Create Release PR + +# This workflow is manually triggered when in preparation for a release. The workflow should be dispatched from the `dev` branch. +on: + workflow_dispatch: + inputs: + OVERRIDE_VERSION: + description: "Override Version" + type: string + required: false + +permissions: + id-token: write + +jobs: + release-pr: + name: Release PR + runs-on: ubuntu-latest + + env: + INPUT_OVERRIDE_VERSION: ${{ github.event.inputs.OVERRIDE_VERSION }} + + steps: + # Assume an AWS Role that provides access to the Access Token + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 + with: + role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }} + aws-region: us-west-2 + # Retrieve the Access Token from Secrets Manager + - name: Retrieve secret from AWS Secrets Manager + uses: aws-actions/aws-secretsmanager-get-secrets@v2 + with: + secret-ids: | + AWS_SECRET, ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_NAME }} + parse-json-secrets: true + # Checkout a full clone of the repo + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: '0' + token: ${{ env.AWS_SECRET_TOKEN }} + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer to automate versioning and changelog creation + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Create the release branch which will contain the version changes and updated changelog + - name: Create Release Branch + id: create-release-branch + run: | + branch=releases/next-release + git checkout -b $branch + echo "BRANCH=$branch" >> $GITHUB_OUTPUT + # Update the version of projects based on the change files + - name: Increment Version + run: autover version + if: env.INPUT_OVERRIDE_VERSION == '' + # Update the version of projects based on the override version + - name: Increment Version + run: autover version --use-version "$INPUT_OVERRIDE_VERSION" + if: env.INPUT_OVERRIDE_VERSION != '' + # Update the changelog based on the change files + - name: Update Changelog + run: autover changelog + # Push the release branch up as well as the created tag + - name: Push Changes + run: | + branch=${{ steps.create-release-branch.outputs.BRANCH }} + git push origin $branch + git push origin $branch --tags + # Get the release name that will be used to create a PR + - name: Read Release Name + id: read-release-name + run: | + version=$(autover changelog --release-name) + echo "VERSION=$version" >> $GITHUB_OUTPUT + # Get the changelog that will be used to create a PR + - name: Read Changelog + id: read-changelog + run: | + changelog=$(autover changelog --output-to-console) + echo "CHANGELOG<> "$GITHUB_OUTPUT" + # Create the Release PR and label it + - name: Create Pull Request + env: + GITHUB_TOKEN: ${{ env.AWS_SECRET_TOKEN }} + run: | + pr_url="$(gh pr create --title "${{ steps.read-release-name.outputs.VERSION }}" --body "${{ steps.read-changelog.outputs.CHANGELOG }}" --base dev --head ${{ steps.create-release-branch.outputs.BRANCH }})" + gh label create "Release PR" --description "A Release PR that includes versioning and changelog changes" -c "#FF0000" -f + gh pr edit $pr_url --add-label "Release PR" \ No newline at end of file diff --git a/.github/workflows/sync-main-dev.yml b/.github/workflows/sync-main-dev.yml new file mode 100644 index 0000000..e7e4a84 --- /dev/null +++ b/.github/workflows/sync-main-dev.yml @@ -0,0 +1,137 @@ +# This GitHub Workflow is designed to run automatically after the Release PR, which was created by the `Create Release PR` workflow, is closed. +# This workflow has 2 jobs. One will run if the `Release PR` is successfully merged, indicating that a release should go out. +# The other will run if the `Release PR` was closed and a release is not intended to go out. +name: Sync 'dev' and 'master' + +# The workflow will automatically be triggered when any PR is closed. +on: + pull_request: + types: [closed] + +permissions: + contents: write + id-token: write + +jobs: + # This job will check if the PR was successfully merged, it's source branch is `releases/next-release` and target branch is `dev`. + # This indicates that the merged PR was the `Release PR`. + # This job will synchronize `dev` and `master`, create a GitHub Release and delete the `releases/next-release` branch. + sync-dev-and-main: + name: Sync dev and master + if: | + github.event.pull_request.merged == true && + github.event.pull_request.head.ref == 'releases/next-release' && + github.event.pull_request.base.ref == 'dev' + runs-on: ubuntu-latest + steps: + # Assume an AWS Role that provides access to the Access Token + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@8c3f20df09ac63af7b3ae3d7c91f105f857d8497 #v4 + with: + role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }} + aws-region: us-west-2 + # Retrieve the Access Token from Secrets Manager + - name: Retrieve secret from AWS Secrets Manager + uses: aws-actions/aws-secretsmanager-get-secrets@v2 + with: + secret-ids: | + AWS_SECRET, ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_NAME }} + parse-json-secrets: true + # Checkout a full clone of the repo + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: dev + fetch-depth: 0 + token: ${{ env.AWS_SECRET_TOKEN }} + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer which is needed to retrieve information about the current release. + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Retrieve the release name which is needed for the GitHub Release + - name: Read Release Name + id: read-release-name + run: | + version=$(autover changelog --release-name) + echo "VERSION=$version" >> $GITHUB_OUTPUT + # Retrieve the tag name which is needed for the GitHub Release + - name: Read Tag Name + id: read-tag-name + run: | + tag=$(autover changelog --tag-name) + echo "TAG=$tag" >> $GITHUB_OUTPUT + # Retrieve the changelog which is needed for the GitHub Release + - name: Read Changelog + id: read-changelog + run: | + changelog=$(autover changelog --output-to-console) + echo "CHANGELOG<> "$GITHUB_OUTPUT" + # Merge dev into master in order to synchronize the 2 branches + - name: Merge dev to master + run: | + git fetch origin + git checkout master + git merge dev + git push origin master + # Create the GitHub Release + - name: Create GitHub Release + env: + GITHUB_TOKEN: ${{ env.AWS_SECRET_TOKEN }} + run: | + gh release create "${{ steps.read-tag-name.outputs.TAG }}" --title "${{ steps.read-release-name.outputs.VERSION }}" --notes "${{ steps.read-changelog.outputs.CHANGELOG }}" + # Delete the `releases/next-release` branch + - name: Clean up + run: | + git fetch origin + git push origin --delete releases/next-release + # This job will check if the PR was closed, it's source branch is `releases/next-release` and target branch is `dev`. + # This indicates that the closed PR was the `Release PR`. + # This job will delete the tag created by AutoVer and the release branch. + clean-up-closed-release: + name: Clean up closed release + if: | + github.event.pull_request.merged == false && + github.event.pull_request.head.ref == 'releases/next-release' && + github.event.pull_request.base.ref == 'dev' + runs-on: ubuntu-latest + steps: + # Checkout a full clone of the repo + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: releases/next-release + fetch-depth: 0 + # Install .NET8 which is needed for AutoVer + - name: Setup .NET 8.0 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + # Install AutoVer which is needed to retrieve information about the current release. + - name: Install AutoVer + run: dotnet tool install --global AutoVer --version 0.0.21 + # Set up a git user to be able to run git commands later on + - name: Setup Git User + run: | + git config --global user.email "github-aws-sdk-dotnet-automation@amazon.com" + git config --global user.name "aws-sdk-dotnet-automation" + # Retrieve the tag name to be deleted + - name: Read Tag Name + id: read-tag-name + run: | + tag=$(autover changelog --tag-name) + echo "TAG=$tag" >> $GITHUB_OUTPUT + # Delete the tag created by AutoVer and the release branch + - name: Clean up + run: | + git fetch origin + git push --delete origin ${{ steps.read-tag-name.outputs.TAG }} + git push origin --delete releases/next-release \ No newline at end of file diff --git a/.gitignore b/.gitignore index ecf9385..74a6106 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,8 @@ **/project.lock.json **/*.nuspec -packages \ No newline at end of file +packages + +# JetBrains Rider +.idea/ +*.sln.iml \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c832129..63bfadd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,54 +1,86 @@ -### 2.5.5 (2024-07-09) +## Release 2024-07-09 + +### Amazon.Extensions.CognitoAuthentication (2.5.5) * Added support for analytics metadata for collecting Amazon Pinpoint metrics. -### 2.5.4 (2024-05-03) +## Release 2024-05-03 + +### Amazon.Extensions.CognitoAuthentication (2.5.4) * Add ClientMetadata to InitiateAuthRequest during StartWithSrpAuthAsync. Thanks [willsmith9182](https://github.com/willsmith9182). -### 2.5.3 (2024-04-20) +## Release 2024-04-20 + +### Amazon.Extensions.CognitoAuthentication (2.5.3) * Update User-Agent string -### 2.5.2 (2023-10-03) +## Release 2023-10-03 + +### Amazon.Extensions.CognitoAuthentication (2.5.2) * Pull Request [#132](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/132) Adds code improvements to make it more idiomatic. * Pull Request [#127](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/127) Verifies the ChallengeName during SRP authentication. * Pull Request [#126](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/126) Fixes issues with the SecretHash initialization. Thanks [DmitryProskurin](https://github.com/DmitryProskurin) for the above changes. -### 2.5.1 (2023-08-30) +## Release 2023-08-30 + +### Amazon.Extensions.CognitoAuthentication (2.5.1) * Pull Request [#130](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/130) Add ConfigureAwait(false) to avoid sync context deadlocks. Thanks [Ryan Swenson](https://github.com/swensorm) -### 2.5.0 (2023-06-21) +## Release 2023-06-21 + +### Amazon.Extensions.CognitoAuthentication (2.5.0) * Pull Request [#123](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/123) add support for software MFA. Thanks [DmitryProskurin](https://github.com/DmitryProskurin) -### 2.4.2 (2023-05-18) +## Release 2023-05-18 + +### Amazon.Extensions.CognitoAuthentication (2.4.2) * Fix the binary compatibility bug introduced in 2.4.1 by restoring the public async method overloads without CancellationToken arguments. -### 2.4.1 (2023-05-12) +## Release 2023-05-12 + +### Amazon.Extensions.CognitoAuthentication (2.4.1) * Pull Request [#115](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/115), add optional CancellationToken arguments to async methods, thanks [GabrielHare](https://github.com/GabrielHare) -### 2.4.0 (2023-03-29) +## Release 2023-03-29 + +### Amazon.Extensions.CognitoAuthentication (2.4.0) * Added new ListDevicesV2Async method and obsoleted ListDevicesAsync method in CognitoUser class. -### 2.3.1 (2023-03-13) +## Release 2023-03-13 + +### Amazon.Extensions.CognitoAuthentication (2.3.1) * Pull Request [#108](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/108), add caching for determining assembly version number. Thanks [mojotheo](https://github.com/mojotheo) -### 2.3.0 (2023-02-08) +## Release 2023-02-08 + +### Amazon.Extensions.CognitoAuthentication (2.3.0) * Pull Request [#104](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/104) Allow CognitoUser to be inheritant, thanks [petrenslavik](https://github.com/petrenslavik) * Pull Request [#97](https://github.com/aws/aws-sdk-net-extensions-cognito/pull/97) Add support for CUSTOM_AUTH, thanks [konectech](https://github.com/konectech) -### 2.2.4 (2023-01-11) +## Release 2023-01-11 + +### Amazon.Extensions.CognitoAuthentication (2.2.4) * Add ClientMetadata to SRP auth flow. -### 2.2.3 (2022-09-12) +## Release 2022-09-12 + +### Amazon.Extensions.CognitoAuthentication (2.2.3) * Allow CognitoUser.RespondToCustomAuthAsync to include ClientMetadata. -### 2.2.2 (2021-07-15) +## Release 2021-07-15 + +### Amazon.Extensions.CognitoAuthentication (2.2.2) * Fixed an issue where IssuedTime and ExpirationTime for CognitoUserSession object should be in UTC when it is instantiated manually by user. * Removed check to validate CognitoSessionTokens which checks ExpirationTime for REFRESH_TOKEN Auth Flow. -### 2.2.1 (2021-04-30) +## Release 2021-04-30 + +### Amazon.Extensions.CognitoAuthentication (2.2.1) * Switch all calls to DateTime.Now to DateTime.UtcNow. -### 2.1.0 (2021-03-22) +## Release 2021-03-22 + +### Amazon.Extensions.CognitoAuthentication (2.1.0) * Added support for TOTP challenges, supports the existing way by defaulting to SMS, but also has an additional override method to allow setting the challenge type. * Make the methods of CognitoUser virtual so that mock test cases could be written for CognitoUser class. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 340546c..c6ab3ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,6 +39,49 @@ To send us a pull request, please: GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). +## Adding a `change file` to your contribution branch + +Each contribution branch should include a `change file` that contains a changelog message for each project that has been updated, as well as the type of increment to perform for those changes when versioning the project. + +A `change file` looks like the following example: +```json +{ + "Projects": [ + { + "Name": "Amazon.Extensions.CognitoAuthentication", + "Type": "Patch", + "ChangelogMessages": [ + "Fixed an issue causing a failure somewhere" + ] + } + ] +} +``` +The `change file` lists all the modified projects, the changelog message for each project as well as the increment type. + +These files are located in the repo at .autover/changes/ + +You can use the `AutoVer` tool to create the change file. You can install it using the following command: +``` +dotnet tool install -g AutoVer +``` + +You can create the `change file` using the following command: +``` +autover change --project-name "Amazon.Extensions.CognitoAuthentication" -m "Fixed an issue causing a failure somewhere +``` +Note: Make sure to run the command from the root of the repository. + +You can update the command to specify which project you are updating. +The available projects are: +* Amazon.Extensions.CognitoAuthentication + +The possible increment types are: +* Patch +* Minor +* Major + +Note: You do not need to create a new `change file` for every changelog message or project within your branch. You can create one `change file` that contains all the modified projects and the changelog messages. ## Finding contributions to work on Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/aws/aws-sdk-net-extensions-cognito/labels/help%20wanted) issues is a great place to start. diff --git a/buildtools/ci.buildspec.yml b/buildtools/ci.buildspec.yml new file mode 100644 index 0000000..4ba2cba --- /dev/null +++ b/buildtools/ci.buildspec.yml @@ -0,0 +1,16 @@ +version: 0.2 + +phases: + install: + runtime-versions: + dotnet: 8.x + build: + commands: + - dotnet test test/Amazon.Extensions.CognitoAuthentication.UnitTests/Amazon.Extensions.CognitoAuthentication.UnitTests.csproj -c Release --logger trx --results-directory ./testresults + - dotnet test test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/Amazon.Extensions.CognitoAuthentication.IntegrationTests.csproj -c Release --logger trx --results-directory ./testresults +reports: + aws-ssm-data-protection-provider-for-aspnet-tests: + file-format: VisualStudioTrx + files: + - '**/*' + base-directory: './testresults' \ No newline at end of file diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/Amazon.Extensions.CognitoAuthentication.IntegrationTests.csproj b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/Amazon.Extensions.CognitoAuthentication.IntegrationTests.csproj index 8ded8cd..100a95b 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/Amazon.Extensions.CognitoAuthentication.IntegrationTests.csproj +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/Amazon.Extensions.CognitoAuthentication.IntegrationTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + net8 @@ -12,9 +12,12 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationConfirmUserTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationConfirmUserTests.cs index 01a670f..3afebcb 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationConfirmUserTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationConfirmUserTests.cs @@ -54,7 +54,7 @@ public AuthenticationConfirmUserTests() : base() //Tests SRP authentication flow for web applications [Fact] - public async void TestGenericSrpAuthentication() + public async Task TestGenericSrpAuthentication() { string password = "PassWord1!"; @@ -62,7 +62,7 @@ public async void TestGenericSrpAuthentication() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = password - }).ConfigureAwait(false); + }); Assert.True(user.SessionTokens.IsValid()); } @@ -78,14 +78,14 @@ public async Task TestDeleteUser() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = "PassWord1!" - }).ConfigureAwait(false); + }); ListUsersRequest listUsersRequest = new ListUsersRequest() { Limit = 60, UserPoolId = pool.PoolID }; - ListUsersResponse listUsersReponse = await provider.ListUsersAsync(listUsersRequest).ConfigureAwait(false); + ListUsersResponse listUsersReponse = await provider.ListUsersAsync(listUsersRequest); foreach (UserType listUser in listUsersReponse.Users) { users.Add(listUser.Username); @@ -93,9 +93,9 @@ await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() Assert.Contains(userID, users); - await user.DeleteUserAsync().ConfigureAwait(false); + await user.DeleteUserAsync(); - listUsersReponse = await provider.ListUsersAsync(listUsersRequest).ConfigureAwait(false); + listUsersReponse = await provider.ListUsersAsync(listUsersRequest); users.Clear(); foreach(UserType listUser in listUsersReponse.Users) { diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationCreateUserTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationCreateUserTests.cs index e079052..054ca3e 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationCreateUserTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationCreateUserTests.cs @@ -57,7 +57,7 @@ public async Task TestNewPasswordRequiredFlow() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = password - }).ConfigureAwait(false); + }); Assert.Equal(context.ChallengeName, ChallengeNameType.NEW_PASSWORD_REQUIRED); @@ -65,7 +65,7 @@ await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { SessionID = context.SessionID, NewPassword = "NewPassword1!" - }).ConfigureAwait(false); + }); Assert.True(user.SessionTokens.IsValid()); } diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationSignUpUserTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationSignUpUserTests.cs index 5a394db..2267bf5 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationSignUpUserTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/AuthenticationSignUpUserTests.cs @@ -61,14 +61,14 @@ public async Task TestSignUpProcess() { CognitoConstants.UserAttrEmail, "xxx@yyy.zzz"} }; - await pool.SignUpAsync(userID, password, userAttributes, validationData).ConfigureAwait(false); + await pool.SignUpAsync(userID, password, userAttributes, validationData); ListUsersRequest listUsersRequest = new ListUsersRequest() { Limit = 2, UserPoolId = pool.PoolID }; - ListUsersResponse listUsersResponse = await provider.ListUsersAsync(listUsersRequest).ConfigureAwait(false); + ListUsersResponse listUsersResponse = await provider.ListUsersAsync(listUsersRequest); bool containsUser55 = false; foreach (UserType user in listUsersResponse.Users) @@ -84,9 +84,9 @@ public async Task TestSignUpProcess() // Tests that ConfirmSignUp reaches the proper failure point with incorrect confirmation code [Fact] - public void TestConfirmSignUpFail() + public async Task TestConfirmSignUpFail() { - Assert.ThrowsAsync(() => user.ConfirmSignUpAsync("fakeConfirmationCode", false)); + await Assert.ThrowsAsync(() => user.ConfirmSignUpAsync("fakeConfirmationCode", false)); } } } diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/CognitoAWSCredentialsTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/CognitoAWSCredentialsTests.cs index 6068177..9718c5b 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/CognitoAWSCredentialsTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/CognitoAWSCredentialsTests.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using Xunit; using Amazon; @@ -44,7 +45,7 @@ public class CognitoCredentialsTests : AuthenticationConfirmUserTests [Fact] //Tests GetCognitoAWSCredentials - public async void TestGetCognitoAWSCredentials() + public async Task TestGetCognitoAWSCredentials() { string password = "PassWord1!"; string poolRegion = user.UserPool.PoolID.Substring(0, user.UserPool.PoolID.IndexOf("_")); @@ -54,7 +55,7 @@ public async void TestGetCognitoAWSCredentials() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = password - }).ConfigureAwait(false); + }); //Create identity pool identityClient = new AmazonCognitoIdentityClient(clientCredentials, clientRegion); @@ -68,29 +69,29 @@ await identityClient.CreateIdentityPoolAsync(new CreateIdentityPoolRequest() }, IdentityPoolName = "TestIdentityPool" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), - }).ConfigureAwait(false); + }); identityPoolId = poolResponse.IdentityPoolId; //Create role for identity pool managementClient = new AmazonIdentityManagementServiceClient(clientCredentials, clientRegion); - CreateRoleResponse roleResponse = managementClient.CreateRoleAsync(new CreateRoleRequest() + CreateRoleResponse roleResponse = await managementClient.CreateRoleAsync(new CreateRoleRequest() { RoleName = "_TestRole_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), AssumeRolePolicyDocument = "{\"Version\": \"2012-10-17\",\"Statement\": [{\"Effect" + "\": \"Allow\",\"Principal\": {\"Federated\": \"cognito-identity.amazonaws.com\"}," + "\"Action\": \"sts:AssumeRoleWithWebIdentity\",\"Condition\": {\"StringEquals\": {" + "\"cognito-identity.amazonaws.com:aud\": [\"" + identityPoolId + "\"]}}}]}" - }).Result; + }); roleName = roleResponse.Role.RoleName; //Create and attach policy for role - CreatePolicyResponse policyResponse = managementClient.CreatePolicyAsync(new CreatePolicyRequest() + CreatePolicyResponse policyResponse = await managementClient.CreatePolicyAsync(new CreatePolicyRequest() { PolicyDocument = "{\"Version\": \"2012-10-17\",\"Statement\": " + "[{\"Effect\": \"Allow\",\"Action\": [\"mobileanalytics:PutEvents\",\"cog" + "nito-sync:*\",\"cognito-identity:*\",\"s3:*\"],\"Resource\": [\"*\"]}]}", PolicyName = "_Cognito_" + DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), - }).Result; + }); policyArn = policyResponse.Policy.Arn; AttachRolePolicyRequest attachRequest = new AttachRolePolicyRequest() @@ -98,7 +99,7 @@ await identityClient.CreateIdentityPoolAsync(new CreateIdentityPoolRequest() PolicyArn = policyArn, RoleName = roleName }; - AttachRolePolicyResponse attachRolePolicyResponse = managementClient.AttachRolePolicyAsync(attachRequest).Result; + AttachRolePolicyResponse attachRolePolicyResponse = await managementClient.AttachRolePolicyAsync(attachRequest); //Set the role for the identity pool await identityClient.SetIdentityPoolRolesAsync(new SetIdentityPoolRolesRequest() @@ -109,7 +110,7 @@ await identityClient.SetIdentityPoolRolesAsync(new SetIdentityPoolRolesRequest() { "authenticated", roleResponse.Role.Arn }, { "unauthenticated", roleResponse.Role.Arn } }, - }).ConfigureAwait(false); + }); //Create and test credentials CognitoAWSCredentials credentials = user.GetCognitoAWSCredentials(identityPoolId, clientRegion); @@ -122,17 +123,17 @@ await identityClient.SetIdentityPoolRolesAsync(new SetIdentityPoolRolesRequest() { try { - bucketsResponse = await client.ListBucketsAsync(new ListBucketsRequest()).ConfigureAwait(false); + bucketsResponse = await client.ListBucketsAsync(new ListBucketsRequest()); break; } - catch (Exception ex) + catch (Exception) { - System.Threading.Thread.Sleep(5000); + Thread.Sleep(5000); } } Assert.True(null != bucketsResponse, "Failed to list buckets after 5 tries"); - Assert.Equal(bucketsResponse.HttpStatusCode, System.Net.HttpStatusCode.OK); + Assert.Equal(System.Net.HttpStatusCode.OK, bucketsResponse.HttpStatusCode); } } diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/MfaAuthenticationTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/MfaAuthenticationTests.cs index bd5f393..0b75c28 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/MfaAuthenticationTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/MfaAuthenticationTests.cs @@ -15,6 +15,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Xunit; using Amazon.Runtime; @@ -35,7 +36,7 @@ public class MfaAuthenticationTests : BaseAuthenticationTestClass //Tests MFA authentication flow [Fact] - public async void TestMfaAuthenticationFlow() + public async Task TestMfaAuthenticationFlow() { string password = "PassWord1!"; @@ -43,7 +44,7 @@ public async void TestMfaAuthenticationFlow() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = password - }).ConfigureAwait(false); + }); Assert.Equal(context.ChallengeName, ChallengeNameType.SMS_MFA); @@ -51,7 +52,7 @@ await Assert.ThrowsAsync(() => user.RespondToSmsMfaAuthAs { MfaCode = "fakeMfaCode", SessionID = context.SessionID - })).ConfigureAwait(false); + })); } /// diff --git a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/SessionTests.cs b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/SessionTests.cs index acdbdee..e8e8329 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/SessionTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.IntegrationTests/SessionTests.cs @@ -27,9 +27,9 @@ public class SessionTests : AuthenticationConfirmUserTests { // Tests the ChangePassword method in CognitoUser to fail due to no valid session [Fact] - public async void TestFailedChangePassword() + public async Task TestFailedChangePassword() { - await Assert.ThrowsAsync(() => user.ChangePasswordAsync("PassWord1!", "PassWord2!")).ConfigureAwait(false); + await Assert.ThrowsAsync(() => user.ChangePasswordAsync("PassWord1!", "PassWord2!")); } // Tests that a CognitoUser object has a valid session object after being authenticated @@ -40,7 +40,7 @@ public async Task TestValidSession() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = "PassWord1!" - }).ConfigureAwait(false); + }); Assert.True(user.SessionTokens.IsValid()); } @@ -53,10 +53,10 @@ public async Task TestGetUserDetails() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = "PassWord1!" - }).ConfigureAwait(false); - GetUserResponse userDetails = await user.GetUserDetailsAsync().ConfigureAwait(false); + }); + GetUserResponse userDetails = await user.GetUserDetailsAsync(); - Assert.True(userDetails.UserAttributes.Any(x => string.Equals(x.Name, CognitoConstants.UserAttrEmail, StringComparison.Ordinal))); + Assert.Contains(userDetails.UserAttributes, x => string.Equals(x.Name, CognitoConstants.UserAttrEmail, StringComparison.Ordinal)); Assert.Empty(userDetails.MFAOptions); } @@ -68,9 +68,9 @@ public async Task TestGlobalSignOut() await user.StartWithSrpAuthAsync(new InitiateSrpAuthRequest() { Password = "PassWord1!" - }).ConfigureAwait(false); + }); - await user.GlobalSignOutAsync().ConfigureAwait(false); + await user.GlobalSignOutAsync(); Assert.Null(user.SessionTokens); } diff --git a/test/Amazon.Extensions.CognitoAuthentication.UnitTests/Amazon.Extensions.CognitoAuthentication.UnitTests.csproj b/test/Amazon.Extensions.CognitoAuthentication.UnitTests/Amazon.Extensions.CognitoAuthentication.UnitTests.csproj index d32cfe0..f952e5c 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.UnitTests/Amazon.Extensions.CognitoAuthentication.UnitTests.csproj +++ b/test/Amazon.Extensions.CognitoAuthentication.UnitTests/Amazon.Extensions.CognitoAuthentication.UnitTests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.0 + net8 @@ -14,9 +14,12 @@ - - - + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/test/Amazon.Extensions.CognitoAuthentication.UnitTests/BigIntegerExtensionsTests.cs b/test/Amazon.Extensions.CognitoAuthentication.UnitTests/BigIntegerExtensionsTests.cs index a79697f..bd25bc9 100644 --- a/test/Amazon.Extensions.CognitoAuthentication.UnitTests/BigIntegerExtensionsTests.cs +++ b/test/Amazon.Extensions.CognitoAuthentication.UnitTests/BigIntegerExtensionsTests.cs @@ -9,7 +9,7 @@ namespace Amazon.Extensions.CognitoAuthentication.UnitTests public class BigIntegerExtensionsTests { [Fact] - public void TestFromHexPositive() + public void TestFromHexPositiveTest() { TestFromHexPositive("0", 0, 0); TestFromHexPositive("1", 1, 1); @@ -53,7 +53,7 @@ private void TestFromHexPositive(string hex, int expectedFromHexPositive, int ex } [Fact] - public void TestTrueMod() + public void TestTrueModTest() { TestTrueMod(10, 3, 1); TestTrueMod(10, 5, 0); @@ -72,7 +72,7 @@ private void TestTrueMod(int numerator, int denominator, int expectedTrueMod) } [Fact] - public void TestFromBigEndianPositive() + public void TestFromBigEndianPositiveTest() { TestFromBigEndianPositive(300, new byte[] { 1, 44 }, 300); TestFromBigEndianPositive(-266, new byte[] { 254, 246 }, 65270);