-
Notifications
You must be signed in to change notification settings - Fork 56
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
Test that we can decrypt history messages #1933
base: main
Are you sure you want to change the base?
Conversation
Warning Rate limit exceeded@lawrence-forooghian has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 10 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📒 Files selected for processing (3)
WalkthroughThe pull request introduces new functionalities to the testing framework for encrypted messages. It adds an asynchronous function Changes
Possibly related PRs
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
test/common/modules/shared_helper.js (1)
486-494
: Consider enhancing the waitFor helper with additional error handling and configuration options.The implementation could be more robust with the following improvements:
- Add parameter validation for condition function and remaining time
- Add try-catch around condition function call
- Make the delay interval configurable
- Add a timeout error message
Consider this enhanced implementation:
- async waitFor(condition, remaining) { - const success = await condition(); - if (success || remaining <= 0) { - return success; - } - await this.setTimeoutAsync(100); - return this.waitFor(condition, remaining - 100); - } + async waitFor(condition, remaining, options = { interval: 100 }) { + if (typeof condition !== 'function') { + throw new Error('condition must be a function'); + } + if (remaining < 0) { + throw new Error('remaining time must be >= 0'); + } + + try { + const success = await condition(); + if (success || remaining <= 0) { + return success; + } + } catch (error) { + throw new Error(`Error in condition function: ${error.message}`); + } + + await this.setTimeoutAsync(options.interval); + return this.waitFor(condition, remaining - options.interval, options); + }test/realtime/crypto.test.js (1)
776-799
: Consider enhancing test coverage and maintainability.The test could be improved in several ways:
- Extract magic number 10_000 to a named constant
- Add more assertions to verify encryption-related properties
- Consider testing edge cases (empty messages, special characters)
Consider this enhanced implementation:
+ const HISTORY_TIMEOUT = 10_000; + const TEST_MESSAGES = [ + { name: 'event0', data: 'Test message' }, + { name: 'event1', data: '' }, // empty message + { name: 'event2', data: '🔑\n\t' } // special characters + ]; + it('encrypted history', async function () { if (!Crypto) { done(new Error('Encryption not supported')); return; } const helper = this.test.helper, rest = helper.AblyRest(), channelName = 'encrypted_history', - messageText = 'Test message'; + key = await Crypto.generateRandomKey(); - const key = await Crypto.generateRandomKey(); const channel = rest.channels.get(channelName, { cipher: { key: key } }); - await channel.publish('event0', messageText); + + // Publish test messages + await Promise.all(TEST_MESSAGES.map(msg => + channel.publish(msg.name, msg.data) + )); + let items; await helper.waitFor(async () => { items = (await channel.history()).items; - return items.length > 0; - }, 10_000); - expect(items[0].data).to.equal(messageText); + return items.length === TEST_MESSAGES.length; + }, HISTORY_TIMEOUT); + + // Verify all messages + items.forEach((item, index) => { + const expectedMsg = TEST_MESSAGES[index]; + expect(item.name).to.equal(expectedMsg.name); + expect(item.data).to.equal(expectedMsg.data); + expect(item.encoding).to.contain('cipher'); // verify encryption + }); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
test/browser/modular.test.js
(2 hunks)test/common/modules/shared_helper.js
(1 hunks)test/realtime/crypto.test.js
(1 hunks)
🔇 Additional comments (1)
test/browser/modular.test.js (1)
559-573
: LGTM! Well-structured test configuration.
The test configuration properly handles both BaseRest and BaseRealtime clients with appropriate plugins and settings.
Test failures are unrelated to this change; have asked in https://ably-real-time.slack.com/archives/CURL4U2FP/p1733420816469159. |
This was previously untested. The new test in `crypto.test.js` is taken from a test Simon added in #1923, but I wanted to separate this test from all the other work that’s being done in that PR. I’ve also copied this new test to create a similar test for the modular variant of the library. Co-authored-by: Simon Woolf <[email protected]>
e64820d
to
9b6a416
Compare
Note: This PR is based on top of #1935; please review that one first.
This was previously untested.
The new test in
crypto.test.js
is taken from a test Simon added in #1923, but I wanted to separate this test from all the other work that’s being done in that PR. I’ve also copied this new test to create a similar test for the modular variant of the library.Summary by CodeRabbit
New Features
Tests