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

CU-86b2gwt48_PW-2040: Update IBAN (BBAN) validation data to July 2024 release #212

Merged
merged 3 commits into from
Nov 15, 2024

Conversation

ptorres-prowide
Copy link
Contributor

@ptorres-prowide ptorres-prowide commented Nov 15, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated BBAN validation data file to align with the IBAN REGISTRY July 2024 release.
    • Added IBAN validation for 88 supported countries, enhancing the existing functionality.
  • Bug Fixes

    • Corrected the enum constant name for invalid check digits to ensure accurate validation results.
    • Updated test cases to reflect correct IBAN configurations and validation results.
  • Tests

    • Expanded test coverage with over 60 new valid IBAN formats for various countries.
  • Documentation

    • Updated the changelog to include version 9.4.19 - SNAPSHOT and document the new features and changes.

Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Caution

Review failed

The pull request is closed.

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces several updates related to IBAN validation. It adds a new entry in the CHANGELOG.md for version 9.4.19 - SNAPSHOT, documenting the update of the BBAN validation data file to align with the IBAN REGISTRY July 2024 release. The IbanValidationResult enum has a typo corrected, and the IbanValidationUtils class references the corrected enum constant. Significant modifications to BbanStructureValidations.json include updates to country codes and validation rules. Test cases in IbanValidatorTest and IBANTest have been updated or added to ensure proper validation of IBANs.

Changes

File Path Change Summary
CHANGELOG.md Added entry for version 9.4.19 - SNAPSHOT with BBAN validation data update.
src/main/java/com/prowidesoftware/swift/model/IbanValidationResult.java Renamed enum constant IVALID_CHECK_DIGITS to INVALID_CHECK_DIGITS.
src/main/java/com/prowidesoftware/swift/model/IbanValidationUtils.java Updated reference from IbanValidationResult.IVALID_CHECK_DIGITS to IbanValidationResult.INVALID_CHECK_DIGITS.
src/main/resources/BbanStructureValidations.json Updated multiple country codes and validation rules, including entry types and lengths.
src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java Updated IBAN in testMissingBbanConfiguration and corrected expected result in testInvalidCheckDigits.
src/test/java/com/prowidesoftware/swift/model/IBANTest.java Added over 60 new valid IBAN test cases and adjusted parameter order in assertIbanOk.
src/main/resources/BbanStructureValidations.json.info Added metadata line indicating last update associated with IBAN REGISTRY July 2024.

Possibly related PRs

Warning

Rate limit exceeded

@zubri has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 94977c8 and 5e06892.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Outside diff range comments (4)
src/main/java/com/prowidesoftware/swift/model/IbanValidationResult.java (2)

Line range hint 82-117: Consider refactoring to make the enum immutable.

The current implementation uses mutable state through the vars map and setter methods, which is an anti-pattern for enums. Enums should be immutable to ensure thread-safety and prevent unexpected state changes.

Consider refactoring to a builder pattern or message template approach:

public enum IbanValidationResult {
-   private final Map<String, String> vars = new HashMap<>();
+   private final String message;
+   private final Map<String, String> vars;

    IbanValidationResult(final String message) {
        this.message = message;
+       this.vars = new HashMap<>();
    }

+   public static IbanValidationResult withVars(IbanValidationResult result, Map<String, String> vars) {
+       IbanValidationResult newResult = result;
+       newResult.vars.putAll(vars);
+       return newResult;
+   }

-   void setFound(final String found) {
-       this.vars.put("found", found);
-   }
    // Remove other setter methods similarly

Line range hint 63-67: Potential security vulnerability in message templating.

The message() method uses direct string replacement which could be vulnerable to injection if the input values aren't properly sanitized. While escapeEcmaScript is used, it may not cover all cases.

Consider using a proper templating library or implementing stricter validation:

public String message() {
    String msg = this.message;
    for (Entry<String, String> e : vars.entrySet()) {
-       msg = msg.replace("${" + e.getKey() + "}", escapeEcmaScript(e.getValue()));
+       // Validate key against whitelist
+       if (!ALLOWED_KEYS.contains(e.getKey())) {
+           throw new IllegalArgumentException("Invalid template key: " + e.getKey());
+       }
+       // Apply stricter escaping and validation
+       String value = strictEscape(e.getValue());
+       msg = msg.replace("${" + e.getKey() + "}", value);
    }
    return msg;
}
src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java (1)

Line range hint 171-180: Consider implementing the disabled test case.

There's a TODO comment indicating that a test case for invalid characters validation is needed. Since this PR addresses IBAN validation problems, it might be worth implementing this test case now.

Would you like me to help implement this test case or create a GitHub issue to track this task? I can analyze the validation logic to suggest appropriate test inputs that would trigger the INVALID_CHARACTERS result.

src/main/resources/BbanStructureValidations.json (1)

Line range hint 1-1643: Consider adding schema validation

Given the complexity and size of this configuration file, consider adding JSON schema validation to ensure:

  1. Consistent structure across all country entries
  2. Valid character types ('n', 'a', 'c')
  3. Required fields are present
  4. Length values are positive integers

Example schema structure:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "required": ["country_code", "validation_rules"],
    "properties": {
      "country_code": {
        "type": "string",
        "pattern": "^[A-Z]{2}$"
      },
      "validation_rules": {
        "type": "array",
        "items": {
          "type": "object",
          "required": ["entry_type", "length", "character_type"],
          "properties": {
            "entry_type": {
              "type": "string",
              "enum": ["bank_code", "branch_code", "account_number", "national_check_digit", "account_type", "currency"]
            },
            "length": {
              "type": "integer",
              "minimum": 1
            },
            "character_type": {
              "type": "string",
              "enum": ["n", "a", "c"]
            }
          }
        }
      }
    }
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 69557a4 and 8fb2a67.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • src/main/java/com/prowidesoftware/swift/model/IbanValidationResult.java (1 hunks)
  • src/main/java/com/prowidesoftware/swift/model/IbanValidationUtils.java (1 hunks)
  • src/main/resources/BbanStructureValidations.json (34 hunks)
  • src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java (2 hunks)
  • src/test/java/com/prowidesoftware/swift/model/IBANTest.java (1 hunks)
🧰 Additional context used
🪛 Markdownlint
CHANGELOG.md

3-3: Expected: h2; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


4-4: Expected: 0; Actual: 2
Unordered list indentation

(MD007, ul-indent)


4-4: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


3-3: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


4-4: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

🔇 Additional comments (8)
src/main/java/com/prowidesoftware/swift/model/IbanValidationResult.java (1)

45-45: LGTM! Typo fix improves code clarity.

The rename from IVALID_CHECK_DIGITS to INVALID_CHECK_DIGITS is a good correction that improves code readability and maintains consistency.

src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java (1)

184-184: LGTM! Verify enum constant usage.

The fix for the typo in the enum constant (IVALID → INVALID) is correct.

Let's verify that this enum constant is consistently used across the codebase:

✅ Verification successful

Enum constant usage is consistent across the codebase

The search results confirm that:

  • No instances of the old IVALID_CHECK_DIGITS remain in the codebase
  • The new INVALID_CHECK_DIGITS constant is consistently used in both the enum definition and all its usages
  • The related constant INVALID_CHECK_DIGITS_FORMAT is also properly used
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining instances of the old enum constant name
# and verify consistent usage of the new name

# Check for any remaining instances of the old constant
echo "Checking for any remaining instances of IVALID_CHECK_DIGITS..."
rg "IVALID_CHECK_DIGITS"

# Verify consistent usage of the new constant
echo "Verifying usage of INVALID_CHECK_DIGITS..."
rg "INVALID_CHECK_DIGITS"

Length of output: 1311

src/test/java/com/prowidesoftware/swift/model/IBANTest.java (2)

265-266: LGTM! Valid Israeli IBAN test case added.

The test case follows the correct format and pattern for Israeli IBANs.


362-362: LGTM! Improved assertion parameter order.

The change follows JUnit best practices by putting the expected value first in the assertion, which provides clearer error messages on test failures.

src/main/resources/BbanStructureValidations.json (3)

1331-1333: ⚠️ Potential issue

Unique validation rule for currency field

The SC (Seychelles) country code includes a unique 'currency' entry type that isn't present in other country validations. This inconsistency might indicate:

  1. A special case that needs documentation
  2. A potential error in the validation rules
#!/bin/bash
# Description: Check for currency field usage

echo "Searching for currency validation usage..."
rg -l 'currency.*validation'

echo "Checking for currency-related tests..."
rg -l 'test.*currency.*SC'

Please verify if this is intentional and add documentation explaining the special case for Seychelles.


16-19: 🛠️ Refactor suggestion

Inconsistent character type usage for account numbers

Some countries use different character types ('n' vs 'c') for account numbers without clear justification:

  • AD: uses 'c' (alphanumeric)
  • BY: uses 'c' (alphanumeric)
  • LV: uses 'c' (alphanumeric)

This inconsistency might lead to validation issues.

#!/bin/bash
# Description: Analyze character type consistency across account numbers

echo "Analyzing account number character types..."
rg -A 2 '"entry_type":\s*"account_number"' | rg '"character_type":\s*"[^"]+"'

Consider:

  1. Documenting the rationale for different character types
  2. Standardizing character types where possible
  3. Adding comments for cases that require specific character types

Also applies to: 231-234, 907-909


3-3: ⚠️ Potential issue

Verify the impact of country code changes

Multiple country codes have been reorganized (e.g., AL→AD, AD→AL, BH→BA). These changes could potentially break existing implementations that rely on specific country codes.

Consider:

  1. Adding a migration guide for these changes
  2. Documenting the rationale for country code reorganization
  3. Ensuring all test cases are updated to reflect these changes

Also applies to: 38-38, 83-83

✅ Verification successful

Based on the comprehensive analysis of the codebase, I can now provide the final response:

Country code changes are part of a planned enhancement for IBAN validation

The changes to country codes (AD, AL, BA, BH) are part of a documented enhancement (PW-2040) that adds IBAN validation support for 88 countries. This is a deliberate improvement, not an error, as evidenced by:

  1. The changelog entry: "Added IBAN validation for the 88 supported countries"
  2. Comprehensive test coverage in IbanValidatorTest.java for country code validation
  3. Well-structured validation rules in the JSON file for each country

The changes are properly implemented with:

  • Complete validation rules for each country
  • Consistent format and structure
  • Proper test coverage for validation scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for country code usage in the codebase to assess impact
# Look for direct references to the changed country codes

echo "Searching for country code references..."
rg -l 'country(?:_code)?\s*(?:==|equals|:)\s*["\'](?:AD|AL|BA|BH)["\']'

echo "Searching for test cases..."
rg -l 'test.*(?:AD|AL|BA|BH).*IBAN'

Length of output: 7319


Script:

#!/bin/bash
# Let's try a different approach to find country code references

# First, let's check the git history for this file
echo "Checking git history for BbanStructureValidations.json..."
git log -p src/main/resources/BbanStructureValidations.json

# Look for any Java/source files that might use these country codes
echo -e "\nSearching for source files with IBAN validation..."
fd -e java -e kt -e scala | xargs rg -l "IBAN|CountryCode|BbanStructure"

# Get the full content of the validation file to analyze the changes
echo -e "\nGetting current validation rules..."
cat src/main/resources/BbanStructureValidations.json

Length of output: 91229


Script:

#!/bin/bash
# Let's check for any IBAN validation tests or implementation code that might be affected

# Look for test files containing IBAN country code tests
echo "Searching for IBAN test files..."
rg -l "AD|AL|BA|BH" src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java

# Check the implementation code for country code handling
echo -e "\nChecking IBAN validation implementation..."
rg -A 5 "country(?:_?code)?\s*=|getCountry" src/main/java/com/prowidesoftware/swift/constraints/IbanValidator.java

# Look for any documentation about IBAN validation
echo -e "\nChecking for documentation..."
fd -e md -e txt | xargs rg -l "IBAN|country.*code"

Length of output: 615


Script:

#!/bin/bash
# Let's examine the specific test cases and documentation

# Check the test cases for these country codes
echo "Checking IBAN validator test cases..."
rg -A 10 "(?:AD|AL|BA|BH)" src/test/java/com/prowidesoftware/swift/constraints/IbanValidatorTest.java

# Look at the changelog for any related changes
echo -e "\nChecking changelog for IBAN changes..."
rg -A 5 -i "iban|country.*code" CHANGELOG.md

# Check README for IBAN validation documentation
echo -e "\nChecking README for IBAN documentation..."
rg -A 5 -i "iban|country.*code" README.md

Length of output: 13318

CHANGELOG.md (1)

3-5: LGTM! The changelog entry is clear and follows the project conventions.

The entry properly documents:

  • The version number (9.4.19-SNAPSHOT)
  • The ticket reference (PW-2040)
  • The feature addition (IBAN validation for 88 countries)
🧰 Tools
🪛 Markdownlint

3-3: Expected: h2; Actual: h4
Heading levels should only increment by one level at a time

(MD001, heading-increment)


4-4: Expected: 0; Actual: 2
Unordered list indentation

(MD007, ul-indent)


4-4: Expected: 0 or 2; Actual: 1
Trailing spaces

(MD009, no-trailing-spaces)


3-3: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines

(MD022, blanks-around-headings)


4-4: null
Lists should be surrounded by blank lines

(MD032, blanks-around-lists)

@zubri zubri merged commit 82ec241 into main Nov 15, 2024
1 of 3 checks passed
@zubri zubri deleted the CU-86b2gwt48_PW-2040--IBAN-validation-problem branch November 15, 2024 19:44
@zubri zubri changed the title CU-86b2gwt48_PW-2040--IBAN-validation-problem CU-86b2gwt48_PW-2040: Update IBAN (BBAN) validation data to July 2024 release Nov 15, 2024
This was referenced Nov 15, 2024
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.

2 participants