Skip to content

Implement Comprehensive Input Validation for Markets Endpoint#5

Open
HermanKoii wants to merge 4 commits into
Merango:61533bb5-fa6e-4c8a-b1fa-ab748d46e7c1from
HermanKoii:markets-input-validation-1749229867
Open

Implement Comprehensive Input Validation for Markets Endpoint#5
HermanKoii wants to merge 4 commits into
Merango:61533bb5-fa6e-4c8a-b1fa-ab748d46e7c1from
HermanKoii:markets-input-validation-1749229867

Conversation

@HermanKoii
Copy link
Copy Markdown

@HermanKoii HermanKoii commented Jun 6, 2025

Implement Comprehensive Input Validation for Markets Endpoint

Description

Task

Implement input validation for the markets endpoint

Acceptance Criteria

  • vs_currency is a required non-empty string
  • ids is an optional array of strings
  • order is restricted to predefined values
  • per_page is an integer between 1 and 250
  • page is a positive integer
  • sparkline is a boolean

Summary of Work

This pull request adds robust input validation for the markets endpoint to ensure data integrity and prevent potential security vulnerabilities.

Changes Made

  • Enhanced input validation for markets endpoint query parameters
  • Implemented comprehensive type checking and range validation
  • Added validation for all optional and required parameters

Validation Details

  1. vs_currency:

    • Required parameter
    • Must be a non-empty string
    • Prevents invalid or missing currency inputs
  2. ids (Optional):

    • Validates as an array of strings
    • Ensures type safety for cryptocurrency identifiers
    • Allows empty or undefined arrays
  3. order (Optional):

    • Restricts to predefined valid sorting orders
    • Prevents arbitrary sorting parameters
    • Supported orders: market_cap_desc, market_cap_asc, volume_desc, volume_asc, id_desc, id_asc
  4. per_page (Optional):

    • Must be an integer
    • Range limited between 1 and 250
    • Prevents excessive data retrieval and potential performance issues
  5. page (Optional):

    • Must be a positive integer
    • Ensures valid pagination parameters
  6. sparkline (Optional):

    • Must be a boolean value
    • Prevents invalid sparkline configuration

Testing Approach

  • Implemented comprehensive unit tests in validation.test.ts
  • Covered all validation scenarios:
    • Happy paths with valid inputs
    • Edge cases with boundary values
    • Invalid input type checks
    • Missing required parameters

Notes

  • Validation is implemented as a pre-processing step before route handling
  • Throws descriptive errors for easy debugging
  • Follows TypeScript type safety principles

Changes Made

  • Updated src/markets/validation.ts with comprehensive input validation
  • Added type checking for all input parameters
  • Implemented range and format validation for markets endpoint query parameters
  • Created detailed error messages for each validation scenario

Tests

  • Validate vs_currency is a non-empty string
  • Check ids is an array of strings
  • Verify order is within predefined set
  • Test per_page is an integer between 1 and 250
  • Ensure page is a positive integer
  • Confirm sparkline is a boolean

Signatures

Staking Key

3JF13GJW2UeYuTTRJQBdBD9bHP6Zj1QLMyXBMoAP2r5Y: YjraFpxS2GSHhYnZH3aEs4121RiyYTksSdHDsLXoNwHB1GPebYc5EiUQE5R5qgJKF1Fti4traceq9mVSepoxiBHcPyp6vz4BsvsJcnBKSoebTYnkvLnCYZZogTCq91LVtZFSWem9mbv3Mg5DkQQDYqNeQYXwv184zMehiwBzdVwwvitX3LEwSH5j6PimKCpRwKN9RXwumBF3GcLGhUR58a24ub4vSXpJZefvbtFHFLdHue4jiAnBc9VXizjHM8ToRSPCg7eUpJxv64VpZ4TPrCyarNXq2McnW5xAS4KyfwEWVcsnt7qw85yLnUnmEe3SWbVnCLWmB3Spo16VT5BAWS3w4oV237Y8reF22ztfpjSXPzoQsaWwEtj2TQgDPnR8YcgKxRUnEGdigxQUoCRXL2VRd7nQqgUcCk

Public Key

H2j8Cz7zKCeuDTs73vtjDtBmtytQX1JyaQqvYwwQWE6p: YZKa2pT392msYmxJiMcNxG7AYiSqf6XimXKM8YFy8ABmsu6uFN7KFdTs7QrukfPkufcLtMJhwJDzzpqSVsCE2Jkgej3dDCFp5K8a1A4DdpoqA5eH4eykLbavs6o2kCYfYqvH58fWXNWhhFjbD5n2LsBJ5FZdZ2cLyQvFBZv596zmLByjg2ow6Yo7vB3bRWBcZPRQGMy2xrcjPz7b1X4fAw6gmJyMmpAiXxtSxfAcn9mDQkgd41rv94mUfGaTu296nfM7PFiCARamCf5NvSHFsDLRXH4KHPvjh9rWWZmKScpjHLWGv6scPePHDLiWSPUf5pHoccGtyuDJhygEcdnVJ2Wdob9D1SZfrNk5ReLG8LtrMwrCi1d2JFTxJifZfaeX1jdS9ZGCaUSoD7KNgdJ9VeHn4yEHgGqXqN

@HermanKoii HermanKoii changed the title [WIP] Implement Robust Input Validation for Markets Endpoint Implement Comprehensive Input Validation for Markets Endpoint Jun 6, 2025
@HermanKoii HermanKoii marked this pull request as ready for review June 6, 2025 17:13
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.

1 participant