Skip to content

[CLIENT-3518]: Validate username/password length - #1187

Merged
juliannguyen4 merged 3 commits into
devfrom
CLIENT-3518-validate-usrpwdlen
Aug 5, 2026
Merged

[CLIENT-3518]: Validate username/password length#1187
juliannguyen4 merged 3 commits into
devfrom
CLIENT-3518-validate-usrpwdlen

Conversation

@diparthaspike

@diparthaspike diparthaspike commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Fixes CLIENT-3518. The Python client silently ignores as_config_set_user()'s return value when config["user"]/config["password"] (or the positional args to client.connect()) are too long, so an oversized username/password gets silently truncated by the C client with no error surfaced to the caller.

Changes

  • src/main/client/type.c — in the aerospike.client(config) constructor, validate username/password length against AS_USER_SIZE/AS_PASSWORD_SIZE before calling as_config_set_user. Raises ParamError with a precise message ("Username/Password length exceeds the maximum of 63 characters") if either is too long.
  • src/main/client/connect.c — same validation added to client.connect(username, password).
  • src/main/aerospike.c — exposed aerospike.USER_SIZE and aerospike.PASSWORD_SIZE (both 64, the raw C buffer size including the null terminator) as public module constants, following the existing module_constants[] pattern, so callers can introspect the limit.
  • aerospike-stubs/aerospike.pyi — added type stub entries for the two new constants.
  • test/new_tests/test_connect.py — added test coverage (see below).

Why this approach

  • We deliberately validate length in Python before calling into the C client, rather than only relying on as_config_set_user's bool return value — this makes the fix self-contained and not dependent on the separate aerospike-client-c fix (atomic reject) landing first.
  • AS_USER_SIZE/AS_PASSWORD_SIZE are used directly from the C header (already transitively included via as_config.h) for the validation itself; the new module constants are for external callers who want to introspect the limit, not used internally for the check.

Testing

  • test_connect_invalid_configs — added two new parametrized cases (username too long, password too long) covering the constructor path.
  • test_connect_call_with_too_long_credentials — new parametrized test covering the client.connect(username, password) path.
  • test_user_and_password_size_constants — asserts aerospike.USER_SIZE == 64 and aerospike.PASSWORD_SIZE == 64.
  • Verified manually against a live server: 64-char username/password each raise the expected ParamError; the 63-char boundary is accepted without a false-positive rejection.
  • Full test_connect.py suite passes (25 passed, 2 pre-existing skips) with no regressions.

@codecov-commenter

codecov-commenter commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.43%. Comparing base (285f8f1) to head (dca5e5c).
⚠️ Report is 3 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1187      +/-   ##
==========================================
+ Coverage   85.39%   85.43%   +0.03%     
==========================================
  Files         101      101              
  Lines       14614    14654      +40     
==========================================
+ Hits        12479    12519      +40     
  Misses       2135     2135              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@juliannguyen4 juliannguyen4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just one point I wanted to mention, but otherwise LGTM!

Comment thread aerospike-stubs/aerospike.pyi Outdated
OP_MAP_CREATE: Literal[1144]
OP_MAP_SET_POLICY: Literal[1101]
OP_MAP_SIZE: Literal[1106]
PASSWORD_SIZE: Literal[64]

@juliannguyen4 juliannguyen4 Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We might not need to expose the max PASSWORD_SIZE and USER_SIZE if we can just document the max length in the API docs. Here's the current documentation for client config's "user" and "password" options: https://aerospike-python-client.readthedocs.io/en/latest/aerospike.html#:~:text=server’s%20CA%20certificate.-,user,-(str

I think it would help to add the max lengths for those options' descriptions. They're in doc/aerospike.rst

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, that is not required, have removed that.

@juliannguyen4
juliannguyen4 merged commit 9cd02d1 into dev Aug 5, 2026
43 checks passed
@juliannguyen4
juliannguyen4 deleted the CLIENT-3518-validate-usrpwdlen branch August 5, 2026 16:01
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.

3 participants