keyshade-xyz / keyshade

Realtime secret and configuration management tool, with the best in class security and seamless integration support
https://keyshade.xyz
Mozilla Public License 2.0
196 stars 96 forks source link

feat(cli): Secret scan feature merge #422

Closed Sambit003 closed 2 weeks ago

Sambit003 commented 2 weeks ago

User description

Description

Give a summary of the change that you have made

Fixes #[ISSUENO]

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Add screenshots of relevant screens

Developer's checklist

If changes are made in the code:

Documentation Update


PR Type

enhancement, tests, documentation


Description


Changes walkthrough ๐Ÿ“

Relevant files
Tests
8 files
project.e2e.spec.ts
Enhance project e2e tests with new scenarios and fixes.   

apps/api/src/project/project.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for project creation, update, and deletion.
  • Introduced tests for project access levels and forking functionality.
  • Resolved merge conflicts and improved test coverage.
  • +632/-281
    secret.e2e.spec.ts
    Enhance secret e2e tests with new scenarios and fixes.     

    apps/api/src/secret/secret.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for secret creation, update, and deletion.
  • Introduced tests for secret versioning and rollback functionality.
  • Resolved merge conflicts and improved test coverage.
  • +946/-178
    environment.e2e.spec.ts
    Enhance environment e2e tests with new scenarios and fixes.

    apps/api/src/environment/environment.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for environment creation, update, and deletion.
  • Introduced tests for fetching environments and handling errors.
  • Resolved merge conflicts and improved test coverage.
  • +380/-247
    workspace.e2e.spec.ts
    Enhanced workspace tests with new scenarios and imports. 

    apps/api/src/workspace/workspace.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for workspace creation, update, and deletion.
  • Introduced tests for workspace event creation and role association.
  • Resolved merge conflicts and added new test scenarios.
  • +673/-398
    variable.e2e.spec.ts
    Enhanced variable tests with new scenarios and imports.   

    apps/api/src/variable/variable.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for variable creation, update, and deletion.
  • Introduced tests for variable event creation and version management.
  • Resolved merge conflicts and added new test scenarios.
  • +728/-176
    workspace-role.e2e.spec.ts
    Enhanced workspace role tests with new scenarios and imports.

    apps/api/src/workspace-role/workspace-role.e2e.spec.ts
  • Updated import paths to use alias notation.
  • Added new test cases for workspace role creation, update, and
    deletion.
  • Introduced tests for role event creation and authority checks.
  • Resolved merge conflicts and added new test scenarios.
  • +758/-188
    workspace-membership.e2e.spec.ts
    Add end-to-end tests for workspace membership features     

    apps/api/src/workspace-membership/workspace-membership.e2e.spec.ts
  • Added end-to-end tests for workspace membership functionalities.
  • Tested scenarios for changing ownership, inviting, removing, and
    updating members.
  • Included tests for accepting, declining, and canceling invitations.
  • Verified event creation for membership actions.
  • +1075/-0
    integration.e2e.spec.ts
    Update integration tests with slug usage and conflict resolution

    apps/api/src/integration/integration.e2e.spec.ts
  • Updated imports to use alias paths.
  • Replaced workspace and project IDs with slugs in test cases.
  • Added tests for integration creation, update, and deletion.
  • Resolved merge conflicts in the integration tests.
  • +474/-414
    Documentation
    1 files
    admin.guard.ts
    Add documentation comments to AdminGuard class.                   

    apps/api/src/auth/guard/admin/admin.guard.ts - Added JSDoc comments to the `AdminGuard` class.
    +8/-0     
    Enhancement
    5 files
    integration.service.ts
    Enhanced integration service with slug handling and pagination.

    apps/api/src/integration/service/integration.service.ts
  • Updated import paths to use alias notation.
  • Added detailed JSDoc comments for integration service methods.
  • Enhanced integration creation and update logic with slug handling.
  • Introduced pagination and metadata for integration retrieval.
  • +204/-67
    workspace-membership.module.ts
    Introduced workspace membership module with services.       

    apps/api/src/workspace-membership/workspace-membership.module.ts
  • Added a new module for workspace membership.
  • Defined providers and controllers for the module.
  • +9/-0     
    workspace-membership.service.ts
    Implement workspace membership management service               

    apps/api/src/workspace-membership/service/workspace-membership.service.ts
  • Implemented service methods for managing workspace memberships.
  • Added functionality for transferring ownership and managing
    invitations.
  • Included role updates and membership checks.
  • Utilized Prisma for database interactions.
  • +1011/-0
    workspace.service.ts
    Enhance workspace service with slug-based operations         

    apps/api/src/workspace/service/workspace.service.ts
  • Enhanced workspace service with CRUD operations using slugs.
  • Added global search functionality within a workspace.
  • Improved error handling and authority checks.
  • Refactored for better code organization and readability.
  • +312/-328
    twilio.ts
    Add Twilio secret detection rules with test cases               

    packages/secret-scan/src/rules/twilio.ts
  • Added regex patterns to detect Twilio Account SID and Auth Token.
  • Included test cases to validate the regex patterns.
  • Implemented a function to return regex patterns for Twilio secrets.
  • +36/-0   
    Additional files (token-limit)
    101 files
    secret.service.ts
    ...                                                                                                           

    apps/api/src/secret/service/secret.service.ts ...
    +348/-102
    variable.service.ts
    ...                                                                                                           

    apps/api/src/variable/service/variable.service.ts ...
    +322/-99
    event.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/event/event.e2e.spec.ts ...
    +300/-52
    project.service.ts
    ...                                                                                                           

    apps/api/src/project/service/project.service.ts ...
    +299/-50
    authority-checker.service.ts
    ...                                                                                                           

    apps/api/src/common/authority-checker.service.ts ...
    +162/-140
    private_key.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/private_key.ts ...
    +167/-0 
    api-key.e2e.spec.ts
    ...                                                                                                           

    apps/api/src/api-key/api-key.e2e.spec.ts ...
    +281/-167
    workspace-role.service.ts
    ...                                                                                                           

    apps/api/src/workspace-role/service/workspace-role.service.ts ...
    +193/-48
    environment.service.ts
    ...                                                                                                           

    apps/api/src/environment/service/environment.service.ts ...
    +207/-38
    secret.test.ts
    ...                                                                                                           

    packages/secret-scan/src/test/secret.test.ts ...
    +317/-0 
    api-key.service.ts
    ...                                                                                                           

    apps/api/src/api-key/service/api-key.service.ts ...
    +139/-48
    workspace.controller.ts
    ...                                                                                                           

    apps/api/src/workspace/controller/workspace.controller.ts ...
    +32/-146
    secret.spec.ts
    ...                                                                                                           

    packages/api-client/tests/secret.spec.ts ...
    +255/-0 
    index.tsx
    ...                                                                                                           

    apps/web/src/components/pricing/card/index.tsx ...
    +178/-0 
    variable.spec.ts
    ...                                                                                                           

    packages/api-client/tests/variable.spec.ts ...
    +229/-0 
    project.spec.ts
    ...                                                                                                           

    packages/api-client/tests/project.spec.ts ...
    +287/-0 
    environment.spec.ts
    ...                                                                                                           

    packages/api-client/tests/environment.spec.ts ...
    +232/-0 
    run.command.ts
    ...                                                                                                           

    apps/cli/src/commands/run.command.ts ...
    +233/-0 
    grafana.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/grafana.ts ...
    +83/-0   
    authress.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/authress.ts ...
    +98/-0   
    change-notifier.socket.ts
    ...                                                                                                           

    apps/api/src/socket/change-notifier.socket.ts ...
    +74/-55 
    scan.command.ts
    ...                                                                                                           

    apps/cli/src/commands/scan.command.ts ...
    +179/-0 
    project.controller.ts
    ...                                                                                                           

    apps/api/src/project/controller/project.controller.ts ...
    +35/-27 
    jwt.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/jwt.ts ...
    +77/-0   
    workspace-membership.controller.ts
    ...                                                                                                           

    apps/api/src/workspace-membership/controller/workspace-membership.controller.ts ...
    +163/-0 
    integration.spec.ts
    ...                                                                                                           

    packages/api-client/tests/integration.spec.ts ...
    +178/-0 
    command.tsx
    ...                                                                                                           

    apps/platform/src/components/ui/command.tsx ...
    +30/-29 
    base.command.ts
    ...                                                                                                           

    apps/cli/src/commands/base.command.ts ...
    +158/-0 
    discord.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/discord.ts ...
    +86/-0   
    slug-generator.ts
    ...                                                                                                           

    apps/api/src/common/slug-generator.ts ...
    +150/-0 
    auth.service.ts
    ...                                                                                                           

    apps/api/src/auth/service/auth.service.ts ...
    +44/-6   
    project.ts
    ...                                                                                                           

    packages/api-client/src/controllers/project.ts ...
    +149/-0 
    event.spec.ts
    ...                                                                                                           

    packages/api-client/tests/event.spec.ts ...
    +149/-0 
    secret.controller.ts
    ...                                                                                                           

    apps/api/src/secret/controller/secret.controller.ts ...
    +56/-19 
    variable.controller.ts
    ...                                                                                                           

    apps/api/src/variable/controller/variable.controller.ts ...
    +58/-20 
    denylist.ts
    ...                                                                                                           

    packages/secret-scan/src/denylist.ts ...
    +215/-0 
    project.types.d.ts
    ...                                                                                                           

    packages/api-client/src/types/project.types.d.ts ...
    +178/-0 
    environment.ts
    ...                                                                                                           

    packages/api-client/src/controllers/environment.ts ...
    +114/-0 
    index.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/index.ts ...
    +141/-0 
    create.profile.ts
    ...                                                                                                           

    apps/cli/src/commands/profile/create.profile.ts ...
    +140/-0 
    workspace-role.controller.ts
    ...                                                                                                           

    apps/api/src/workspace-role/controller/workspace-role.controller.ts ...
    +20/-20 
    auth.guard.ts
    ...                                                                                                           

    apps/api/src/auth/guard/auth/auth.guard.ts ...
    +26/-6   
    util.ts
    ...                                                                                                           

    apps/api/src/common/util.ts ...
    +105/-0 
    integration.controller.ts
    ...                                                                                                           

    apps/api/src/integration/controller/integration.controller.ts ...
    +27/-15 
    user.controller.ts
    ...                                                                                                           

    apps/api/src/user/controller/user.controller.ts ...
    +5/-64   
    page.tsx
    ...                                                                                                           

    apps/platform/src/app/(main)/project/[project]/@secret/page.tsx ...
    +123/-0 
    cloudflare.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/cloudflare.ts ...
    +70/-0   
    pricing.ts
    ...                                                                                                           

    apps/web/src/constants/pricing.ts ...
    +113/-0 
    client.ts
    ...                                                                                                           

    packages/api-client/src/client.ts ...
    +116/-0 
    api-key.controller.ts
    ...                                                                                                           

    apps/api/src/api-key/controller/api-key.controller.ts ...
    +35/-15 
    user.service.ts
    ...                                                                                                           

    apps/api/src/user/service/user.service.ts ...
    +46/-11 
    secret.ts
    ...                                                                                                           

    packages/api-client/src/controllers/secret.ts ...
    +101/-0 
    environment.controller.ts
    ...                                                                                                           

    apps/api/src/environment/controller/environment.controller.ts ...
    +28/-16 
    variable.ts
    ...                                                                                                           

    packages/api-client/src/controllers/variable.ts ...
    +100/-0 
    integration.types.d.ts
    ...                                                                                                           

    packages/api-client/src/types/integration.types.d.ts ...
    +134/-0 
    page.tsx
    ...                                                                                                           

    apps/platform/src/app/(main)/page.tsx ...
    +10/-42 
    list.profile.ts
    ...                                                                                                           

    apps/cli/src/commands/profile/list.profile.ts ...
    +102/-0 
    pypi.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/pypi.ts ...
    +38/-0   
    animated-tabs.tsx
    ...                                                                                                           

    apps/web/src/components/ui/animated-tabs.tsx ...
    +68/-0   
    bitbucket.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/bitbucket.ts ...
    +62/-0   
    paginate.ts
    ...                                                                                                           

    apps/api/src/common/paginate.ts ...
    +84/-0   
    secret.types.d.ts
    ...                                                                                                           

    packages/api-client/src/types/secret.types.d.ts ...
    +124/-0 
    openAI.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/openAI.ts ...
    +59/-0   
    configuration.ts
    ...                                                                                                           

    apps/cli/src/util/configuration.ts ...
    +84/-0   
    page.tsx
    ...                                                                                                           

    apps/web/src/app/(main)/pricing/page.tsx ...
    +68/-0   
    init.command.ts
    ...                                                                                                           

    apps/cli/src/commands/init.command.ts ...
    +109/-0 
    integration.ts
    ...                                                                                                           

    packages/api-client/src/controllers/integration.ts ...
    +84/-0   
    variable.types.d.ts
    ...                                                                                                           

    packages/api-client/src/types/variable.types.d.ts ...
    +124/-0 
    environment.ts
    ...                                                                                                           

    apps/api/src/common/environment.ts ...
    +62/-2   
    event.service.ts
    ...                                                                                                           

    apps/api/src/event/service/event.service.ts ...
    +47/-8   
    update.profile.ts
    ...                                                                                                           

    apps/cli/src/commands/profile/update.profile.ts ...
    +93/-0   
    enums.ts
    ...                                                                                                           

    packages/schema/src/enums.ts ...
    +88/-0   
    workspace.spec.ts
    ...                                                                                                           

    packages/schema/tests/workspace.spec.ts ...
    +83/-0   
    artifactory.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/artifactory.ts ...
    +42/-0   
    projects.ts
    ...                                                                                                           

    apps/platform/src/lib/api-functions/projects.ts ...
    +77/-0   
    collective-authorities.ts
    ...                                                                                                           

    apps/api/src/common/collective-authorities.ts ...
    +95/-0   
    npm.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/npm.ts ...
    +65/-0   
    create.environment.ts
    ...                                                                                                           

    apps/cli/src/commands/environment/create.environment.ts ...
    +99/-0   
    app.module.ts
    ...                                                                                                           

    apps/api/src/app/app.module.ts ...
    +23/-16 
    index.ts
    ...                                                                                                           

    apps/platform/src/types/index.ts ...
    +38/-5   
    user.ts
    ...                                                                                                           

    apps/api/src/common/user.ts ...
    +76/-0   
    layout.tsx
    ...                                                                                                           

    apps/platform/src/app/(main)/project/[project]/layout.tsx ...
    +35/-9   
    cryptography.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.ts ...
    +83/-0   
    event.ts
    ...                                                                                                           

    apps/api/src/common/event.ts ...
    +46/-6   
    facebook.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/facebook.ts ...
    +50/-0   
    ip_public.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/ip_public.ts ...
    +36/-0   
    confluent.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/confluent.ts ...
    +54/-0   
    atlassian.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/atlassian.ts ...
    +66/-0   
    accordion.tsx
    ...                                                                                                           

    apps/platform/src/components/ui/accordion.tsx ...
    +56/-0   
    project.spec.ts
    ...                                                                                                           

    packages/schema/tests/project.spec.ts ...
    +68/-0   
    shopify.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/shopify.ts ...
    +55/-0   
    harness.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/harness.ts ...
    +50/-0   
    workspace-role.spec.ts
    ...                                                                                                           

    packages/schema/tests/workspace-role.spec.ts ...
    +64/-0   
    integration.spec.ts
    ...                                                                                                           

    packages/schema/tests/integration.spec.ts ...
    +66/-0   
    variable.spec.ts
    ...                                                                                                           

    packages/schema/tests/variable.spec.ts ...
    +59/-0   
    encrypt-text.tsx
    ...                                                                                                           

    apps/web/src/components/ui/encrypt-text.tsx ...
    +22/-10 
    planetscale.ts
    ...                                                                                                           

    packages/secret-scan/src/rules/planetscale.ts ...
    +44/-0   
    cryptography.spec.ts
    ...                                                                                                           

    apps/api/src/common/cryptography.spec.ts ...
    +59/-0   
    update.environment.ts
    ...                                                                                                           

    apps/cli/src/commands/environment/update.environment.ts ...
    +80/-0   
    api-key.guard.ts
    ...                                                                                                           

    apps/api/src/auth/guard/api-key/api-key.guard.ts ...
    +22/-3   
    Additional 246 files not shown
    ...                                                                                                           

    Additional 246 files not shown ...
    Additional files (token-limit)extra_file_yaml =
    1 files
    environment.types.d.ts
    ...                                                                                                           

    packages/api-client/src/types/environment.types.d.ts ...
    +85/-0   

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-free[bot] commented 2 weeks ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review: 4 ๐Ÿ”ต๐Ÿ”ต๐Ÿ”ต๐Ÿ”ตโšช
    ๐Ÿงช PR contains tests
    ๐Ÿ”’ No security concerns identified
    โšก Key issues to review

    Merge Conflict
    There are unresolved merge conflicts in this file that need to be addressed. API Changes
    Several API endpoints have been updated to use slugs instead of IDs. This change needs to be carefully reviewed for consistency and potential impacts on other parts of the system. Test Coverage
    New tests have been added for variable operations. These should be reviewed to ensure they cover all necessary scenarios and edge cases.
    codiumai-pr-agent-free[bot] commented 2 weeks ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Resolve merge conflict by selecting the appropriate code ___ **Resolve the merge conflict by choosing the appropriate code and removing the
    conflict markers. This will ensure the code can be properly executed and maintained.** [apps/api/src/secret/secret.e2e.spec.ts [960-964]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-598db59202ce7ecc8d2fb84528577afd14eac8275a30e174d704d6fc2b7f5c3bR960-R964) ```diff -<<<<<<< HEAD - await secretService.updateSecret(user1, secret1.slug, { -======= - expect(response.statusCode).toBe(404) -}) +await secretService.updateSecret(user1, secret1.slug, { -it('should have created a SECRET_UPDATED event', async () => { - ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 10 Why: Resolving merge conflicts is crucial for ensuring the code can be properly executed and maintained, making this suggestion highly important.
    10
    Merge conflict
    Resolve merge conflict by selecting the updated import statements ___ **Remove the merge conflict markers and resolve the conflict by choosing the
    appropriate code.** [apps/api/src/project/project.e2e.spec.ts [28-48]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-f1b22baab0b4173d825570c9030ef014582bc75bb67ef2e544f0dd879ff941a2R28-R48) ```diff -<<<<<<< HEAD import { WorkspaceService } from '@/workspace/service/workspace.service' import { WorkspaceMembershipService } from '@/workspace-membership/service/workspace-membership.service' import { UserService } from '@/user/service/user.service' import { WorkspaceModule } from '@/workspace/workspace.module' import { WorkspaceMembershipModule } from '@/workspace-membership/workspace-membership.module' import { UserModule } from '@/user/user.module' import { WorkspaceRoleModule } from '@/workspace-role/workspace-role.module' import { WorkspaceRoleService } from '@/workspace-role/service/workspace-role.service' import { EnvironmentService } from '@/environment/service/environment.service' import { SecretService } from '@/secret/service/secret.service' import { VariableService } from '@/variable/service/variable.service' import { VariableModule } from '@/variable/variable.module' import { SecretModule } from '@/secret/secret.module' import { EnvironmentModule } from '@/environment/environment.module' import { QueryTransformPipe } from '@/common/pipes/query.transform.pipe' import { fetchEvents } from '@/common/event' -======= -import { WorkspaceService } from '../workspace/service/workspace.service' -import { UserService } from '../user/service/user.service' -import { WorkspaceModule } from '../workspace/workspace.module' ->>>>>>> 6ac6f14 (Revert "Fix: merge conflicts") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: The suggestion correctly identifies and resolves the merge conflict by selecting the updated import statements, which is crucial for the code to compile and function correctly.
    9
    Resolve merge conflict in the 'Create Project Tests' section ___ **Remove the merge conflict markers and resolve the conflict by choosing the
    appropriate code for the 'Create Project Tests' section.** [apps/api/src/project/project.e2e.spec.ts [179-195]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-f1b22baab0b4173d825570c9030ef014582bc75bb67ef2e544f0dd879ff941a2R179-R195) ```diff -<<<<<<< HEAD describe('Create Project Tests', () => { it('should allow workspace member to create a project', async () => { const response = await app.inject({ method: 'POST', url: `/project/${workspace1.slug}`, payload: { name: 'Project 3', description: 'Project 3 description', storePrivateKey: true }, headers: { 'x-e2e-user-email': user1.email -======= -it('should allow workspace member to create a project', async () => { - const response = await app.inject({ - method: 'POST', + } + }) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: The suggestion accurately resolves the merge conflict in the 'Create Project Tests' section, ensuring the test case is complete and functional.
    9
    Resolve merge conflict in the 'Key Tests' section ___ **Remove the merge conflict markers and resolve the conflict by choosing the
    appropriate code for the 'Key Tests' section.** [apps/api/src/project/project.e2e.spec.ts [805-819]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-f1b22baab0b4173d825570c9030ef014582bc75bb67ef2e544f0dd879ff941a2R805-R819) ```diff -<<<<<<< HEAD describe('Key Tests', () => { it('should not store the private key if storePrivateKey is false', async () => { const response = await app.inject({ method: 'POST', url: `/project/${workspace1.slug}`, payload: { name: 'Project 2', description: 'Project 2 description', storePrivateKey: false }, headers: { 'x-e2e-user-email': user1.email -======= -it('should generate new key-pair if regenerateKeyPair is true and and the project stores the private key or a private key is specified', async () => { - const response = await app.inject({ - method: 'PUT', + } + }) + expect(response.statusCode).toBe(201) + + const projectId = response.json().id + + project2 = await prisma.project.findUnique({ + where: { + id: projectId + } + }) + + expect(project2).toBeDefined() + expect(project2.privateKey).toBeNull() + }) + + it('should generate new key-pair if regenerateKeyPair is true and and the project stores the private key or a private key is specified', async () => { + const response = await app.inject({ + method: 'PUT', + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 9 Why: The suggestion effectively resolves the merge conflict in the 'Key Tests' section, maintaining the integrity and functionality of the test cases.
    9
    Best practice
    Remove unused variable to improve code cleanliness ___ **Remove the unused variable response to improve code cleanliness and avoid potential
    linting issues.** [apps/api/src/secret/secret.e2e.spec.ts [1106-1107]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-598db59202ce7ecc8d2fb84528577afd14eac8275a30e174d704d6fc2b7f5c3bR1106-R1107) ```diff -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const response = await app.inject({ +await app.inject({ ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Removing an unused variable helps avoid potential linting issues and improves code cleanliness, which is a good practice for maintainability.
    8
    Use a more descriptive variable name for better code readability ___ **Use a more descriptive variable name instead of versions to improve code
    readability. Consider using secretVersions or secretRevisions.** [apps/api/src/secret/secret.e2e.spec.ts [1095]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-598db59202ce7ecc8d2fb84528577afd14eac8275a30e174d704d6fc2b7f5c3bR1095-R1095) ```diff -let versions: SecretVersion[] +let secretVersions: SecretVersion[] ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: The suggestion to use a more descriptive variable name like `secretVersions` improves code readability and maintainability, but it is a minor improvement.
    6
    Use more descriptive variable names for test users ___ **Consider using a more descriptive name for the user1, user2, and user3 variables.
    For example, you could use names like adminUser, memberUser, and nonMemberUser to
    better reflect their roles in the tests.** [apps/api/src/workspace/workspace.e2e.spec.ts [78]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-7a691e843fbdae323f1cabe7a12508154fbc917a1a738e5a67a1747fb7c581eaR78-R78) ```diff -let user1: User, user2: User, user3: User +let adminUser: User, memberUser: User, nonMemberUser: User ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: The suggestion improves code readability by using descriptive variable names, which helps in understanding the roles of the users in the tests. However, it is not crucial for functionality.
    6
    Use specific HTTP status code constants in assertions ___ **Consider using a more specific assertion for the response status code. Instead of
    expect(response.statusCode).toBe(201), you could use
    expect(response.statusCode).toBe(HttpStatus.CREATED) to make the expected status
    code more explicit.** [apps/api/src/workspace/workspace.e2e.spec.ts [200]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-7a691e843fbdae323f1cabe7a12508154fbc917a1a738e5a67a1747fb7c581eaR200-R200) ```diff -expect(response.statusCode).toBe(201) +expect(response.statusCode).toBe(HttpStatus.CREATED) ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 5 Why: Using HTTP status code constants can improve code readability and maintainability by making the expected status more explicit. However, it is a minor improvement and not essential for the test's correctness.
    5
    Enhancement
    Add a test case for invalid workspace creation input ___ **Consider adding a test case to verify that a user cannot create a workspace with an
    empty name or description. This would help ensure that the API properly validates
    input data.** [apps/api/src/workspace/workspace.e2e.spec.ts [187-199]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-7a691e843fbdae323f1cabe7a12508154fbc917a1a738e5a67a1747fb7c581eaR187-R199) ```diff it('should be able to create a new workspace', async () => { const response = await app.inject({ method: 'POST', headers: { 'x-e2e-user-email': user1.email }, url: '/workspace', payload: { name: 'Workspace 1', description: 'Workspace 1 description' } }) +it('should not be able to create a workspace with empty name or description', async () => { + const response = await app.inject({ + method: 'POST', + headers: { + 'x-e2e-user-email': user1.email + }, + url: '/workspace', + payload: { + name: '', + description: '' + } + }) + + expect(response.statusCode).toBe(HttpStatus.BAD_REQUEST) +}) + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Adding a test case for invalid input enhances the test coverage and ensures that the API properly validates input data, which is important for robustness and security.
    8
    Maintainability
    Remove commented-out code to improve code cleanliness ___ **Remove the commented-out code to improve code cleanliness and maintainability. If
    the code is needed for future reference, consider adding a TODO comment instead.** [apps/api/src/secret/secret.e2e.spec.ts [1115-1124]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-598db59202ce7ecc8d2fb84528577afd14eac8275a30e174d704d6fc2b7f5c3bR1115-R1124) ```diff -// expect(response.statusCode).toBe(200) -// expect(response.json().count).toEqual(2) +// TODO: Implement assertion for response status and secret versions count -// versions = await prisma.secretVersion.findMany({ -// where: { -// secretId: secret1.id -// } -// }) - -// expect(versions.length).toBe(1) - ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Removing commented-out code enhances code cleanliness and maintainability, and replacing it with a TODO comment is a good practice for future reference.
    7
    Error handling
    Add error handling for the fetchEvents function call ___ **Consider adding error handling and validation for the fetchEvents function call.
    It's good practice to handle potential errors that might occur during API calls or
    data fetching.** [apps/api/src/workspace/workspace.e2e.spec.ts [363-368]](https://github.com/keyshade-xyz/keyshade/pull/422/files#diff-7a691e843fbdae323f1cabe7a12508154fbc917a1a738e5a67a1747fb7c581eaR363-R368) ```diff -const response = await fetchEvents( - eventService, - user1, - workspace1.slug, - EventSource.WORKSPACE -) +let response; +try { + response = await fetchEvents( + eventService, + user1, + workspace1.slug, + EventSource.WORKSPACE + ); +} catch (error) { + console.error('Error fetching events:', error); + throw error; +} +expect(response).toBeDefined(); + ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 7 Why: Incorporating error handling improves the robustness of the test by ensuring that potential errors during API calls are managed, but it is not critical for the test's primary functionality.
    7