feat: add non-secure variant nanoid_non_secure() #21#25
Conversation
3a6d759 to
1825b39
Compare
1825b39 to
4a15c8d
Compare
23364e1 to
080212a
Compare
|
@coderabbitai full review |
✅ Action performedFull review finished. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds ChangesNon-secure Nano ID
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
dev/test/unit_tests.sql (1)
144-161: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd negative-path coverage for
nanoid_non_secure's validation.The happy-path tests look correct, but the new
size/alphabetvalidation innanoid.sql(lines 151-157) has no test exercising the rejection branches, unlike the analogous exception coverage that exists fornanoid()elsewhere in this file.✅ Suggested addition
-- Non-secure variant: invalid size and alphabet are rejected BEGIN PERFORM nanoid_non_secure(0); ASSERT FALSE, 'Size 0 was not rejected for nanoid_non_secure'; EXCEPTION WHEN assert_failure THEN RAISE; WHEN raise_exception THEN NULL; -- expected rejection END; BEGIN PERFORM nanoid_non_secure(21, ''); ASSERT FALSE, 'Empty alphabet was not rejected for nanoid_non_secure'; EXCEPTION WHEN assert_failure THEN RAISE; WHEN raise_exception THEN NULL; -- expected rejection END;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dev/test/unit_tests.sql` around lines 144 - 161, Add negative-path tests alongside the existing nanoid_non_secure cases to verify its validation rejects size 0 and an empty alphabet. Use separate exception-handling blocks around nanoid_non_secure calls, fail the test if no exception occurs, and re-raise assertion failures while accepting the expected validation exception.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@dev/test/unit_tests.sql`:
- Around line 144-161: Add negative-path tests alongside the existing
nanoid_non_secure cases to verify its validation rejects size 0 and an empty
alphabet. Use separate exception-handling blocks around nanoid_non_secure calls,
fail the test if no exception occurs, and re-raise assertion failures while
accepting the expected validation exception.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1597b7d5-835e-4bb7-aac9-52cf4a5b0ec2
📒 Files selected for processing (4)
README.mddev/test/regression_tests.sqldev/test/unit_tests.sqlnanoid.sql
|
@coderabbitai Added the negative-path tests in dev/test/unit_tests.sql: size 0 and an empty alphabet are now asserted to be rejected by nanoid_non_secure(), using the same exception-block pattern as the existing over-256-symbol rejection test for nanoid(). Verified green on all supported PostgreSQL versions (9.6 through 18). |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
fd unit_tests.sql
echo "---"
rg -n "nanoid_non_secure" dev/test/unit_tests.sql -A5 -B2Length of output: 1993 The negative-path tests look correct — matching the existing exception-block pattern used for the over-256-symbol rejection test on |
Port the nanoid/non-secure module of the original JavaScript library. nanoid_non_secure() uses PostgreSQL's built-in random() generator, so it works without the pgcrypto extension and generates IDs about 2.4 times faster than nanoid() (benchmark: 100k default IDs on PostgreSQL 17, 0.63s vs 1.49s). The generated IDs are predictable; the README documents that it must not be used for security-relevant identifiers. The function is declared PARALLEL UNSAFE like nanoid() and nanoid_optimized(): PL/pgSQL advances the command counter and takes new snapshots when evaluating volatile expressions, which is forbidden in parallel mode (issue #16). PARALLEL RESTRICTED is not enough, verified by the added regression test that runs the issue #16 CTAS shape over nanoid_non_secure().
The full nanoid.sql still creates the pgcrypto extension for nanoid(), so the README now explains how to get nanoid_non_secure() on a host without pgcrypto. Adds unit tests for multi-byte and single-symbol alphabets on the non-secure variant.
080212a to
b9c3b58
Compare
83f00d9 to
99ddbe7
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. You're currently rate limited under our Fair Usage Limits Policy. Your recent PR review activity is in the 95th percentile or higher among CodeRabbit users, so adaptive limits apply. Your next review will be available in 8 minutes. |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
# Conflicts: # dev/test/regression_tests.sql
|
Closing unmerged. We decided not to port the non-secure variant: there is no current use case that justifies it in this port. Can be revisited if a concrete need comes up. |
Summary
Ports the
nanoid/non-securemodule of the original JavaScript library.nanoid_non_secure(size, alphabet)generates ids from PostgreSQL's built-inrandom(), so it works without the pgcrypto extension and benchmarks about 2.4 times faster thannanoid()(100k default ids on PostgreSQL 17: 0.63s vs 1.49s). The ids are predictable; the README section documents the variant with a clear warning against security-relevant use.The function is declared
PARALLEL UNSAFEfor the same reason asnanoid()(#16).PARALLEL RESTRICTEDis not sufficient: the added regression test (the #16 CTAS shape overnanoid_non_secure()) fails with "cannot start commands during a parallel operation" under a RESTRICTED declaration and passes with UNSAFE.Verification
COSTfor more parallel operations? #16 parallel CTAS shapeCloses #21
Summary by CodeRabbit
New Features
nanoid_non_secure()to generate IDs using a non-cryptographic random source.Documentation
nanoid_non_secure()“non-secure variant,” including performance notes, predictability considerations, and recommended/non-recommended use cases and examples.Tests