Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BEEEP][SM-893] Add the ability to run SM integration tests as a service account #3187

Merged
merged 14 commits into from Mar 29, 2024

Conversation

Thomas-Avery
Copy link
Contributor

@Thomas-Avery Thomas-Avery commented Aug 11, 2023

Type of change

- [ ] Bug fix
- [X] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

The purpose of this PR is to add the ability to run SM integration tests as a service account.

Introducing a LoginHelper to house the duplicate logic in the integration tests that were setting client authorization headers.

Code changes

  • test/Api.IntegrationTest/Factories/ApiApplicationFactory.cs:
    Added a method to login via client secret (API key) that returns the authentication access token.

  • test/Api.IntegrationTest/SecretsManager/Helpers/LoginHelper.cs:
    Adding a helper that provides methods to login via email and Api key which will:

  • Call the application factory methods to call the identity factory to login and fetch authentication tokens
  • Set those authentication tokens on the HTTP client authorization request headers
  • test/Api.IntegrationTest/SecretsManager/Controllers/AccessPoliciesControllerTests.cs:
    Migrate to using the LoginHelper

  • test/Api.IntegrationTest/SecretsManager/Controllers/ProjectsControllerTests.cs:
    Migrate to using the LoginHelper

  • test/Api.IntegrationTest/SecretsManager/Controllers/SecretsControllerTests.cs:
    Migrate to using the LoginHelper.
    Demonstrate using the new service account login method.

  • test/Api.IntegrationTest/SecretsManager/Controllers/SecretsManagerPortingControllerTests.cs:
    Migrate to using the LoginHelper

  • test/Api.IntegrationTest/SecretsManager/Controllers/SecretsTrashControllerTests.cs:
    Migrate to using the LoginHelper

  • test/Api.IntegrationTest/SecretsManager/Controllers/ServiceAccountsControllerTests.cs:
    Migrate to using the LoginHelper

  • test/Api.IntegrationTest/SecretsManager/Enums/PermissionType.cs:
    Add running as a service account with permission into the testing enum.

  • test/Api.IntegrationTest/SecretsManager/SecretsManagerOrganizationHelper.cs:
    Add a helper method for creating a service account and API key/access token for the service account.

  • test/IntegrationTestCommon/Factories/IdentityApplicationFactory.cs:
    Add a method for logging in with a service account access token (API key).

Before you submit

  • Please check for formatting errors (dotnet format --verify-no-changes) (required)
  • If making database changes - make sure you also update Entity Framework queries and/or migrations
  • Please add unit tests where it makes sense to do so (encouraged but not required)
  • If this change requires a documentation update - notify the documentation team
  • If this change has particular deployment requirements - notify the DevOps team

@bitwarden-bot
Copy link

bitwarden-bot commented Aug 11, 2023

Logo
Checkmarx One – Scan Summary & Details28227e59-4f50-444d-9080-22d4df385a5f

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 270 Attack Vector
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 270 Attack Vector
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 212 Attack Vector
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 212 Attack Vector
MEDIUM Privacy_Violation /src/Api/Controllers/DevicesController.cs: 155 Attack Vector
MEDIUM Privacy_Violation /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 683 Attack Vector
MEDIUM Privacy_Violation /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 630 Attack Vector
LOW Log_Forging /src/Api/Vault/Controllers/CiphersController.cs: 220 Attack Vector
LOW Log_Forging /src/Api/Controllers/DevicesController.cs: 146 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 595 Attack Vector
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationsController.cs: 658 Attack Vector

Fixed Issues

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 315
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 315
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 156
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 147
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 187
MEDIUM CSRF /src/Api/Controllers/CollectionsController.cs: 196
MEDIUM CSRF /src/Api/AdminConsole/Public/Controllers/MembersController.cs: 147
MEDIUM Privacy_Violation /src/Core/Auth/UserFeatures/UserMasterPassword/SetInitialMasterPasswordCommand.cs: 59
LOW Log_Forging /src/Api/Auth/Controllers/AccountsController.cs: 313

@Thomas-Avery Thomas-Avery changed the title [BEEEP][SM-893] Add helper to run SM integration tests as a service account [BEEEP][SM-893] Add the ability to run SM integration tests as a service account Oct 6, 2023
@Thomas-Avery Thomas-Avery self-assigned this Oct 6, 2023
@Thomas-Avery Thomas-Avery marked this pull request as ready for review October 6, 2023 20:43
@Thomas-Avery Thomas-Avery requested review from a team as code owners October 6, 2023 20:43
@Thomas-Avery Thomas-Avery requested a review from a team October 6, 2023 20:44
cd-bitwarden
cd-bitwarden previously approved these changes Oct 9, 2023
Copy link
Contributor

@cd-bitwarden cd-bitwarden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, glad we are adding this, thanks Thomas!

@Thomas-Avery Thomas-Avery marked this pull request as draft March 8, 2024 21:10
@Thomas-Avery Thomas-Avery removed request for a team March 8, 2024 21:10
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.73%. Comparing base (e2cb406) to head (6afab31).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3187      +/-   ##
==========================================
+ Coverage   36.58%   36.73%   +0.15%     
==========================================
  Files        1174     1174              
  Lines       56627    56627              
  Branches     5425     5425              
==========================================
+ Hits        20716    20803      +87     
+ Misses      34944    34859      -85     
+ Partials      967      965       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Thomas-Avery Thomas-Avery requested a review from a team March 11, 2024 21:11
@Thomas-Avery Thomas-Avery marked this pull request as ready for review March 11, 2024 21:11
Copy link
Member

@coltonhurst coltonhurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I like the addition of LoginHelper. Thanks!

@Thomas-Avery Thomas-Avery merged commit 97c4d83 into main Mar 29, 2024
51 checks passed
@Thomas-Avery Thomas-Avery deleted the sm/sm-893-beeep branch March 29, 2024 16:00
cyprain-okeke pushed a commit that referenced this pull request Apr 1, 2024
…ice account (#3187)

* Add the ability to run SM integration tests as a service account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants