Skip to content

Commit 534a919

Browse files
Add test for undefined railsEnv redaction (fail-closed coverage)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fb4d148 commit 534a919

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/react-on-rails-pro/tests/injectRSCPayload.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,27 @@ describe('injectRSCPayload', () => {
519519
expect(resultStr).not.toContain('renderingError');
520520
});
521521

522+
it('redacts renderingError when railsEnv is not provided (undefined)', async () => {
523+
const mockRSC = createMockRSCStreamWithMetadata('{"test": "data"}', {
524+
hasErrors: true,
525+
renderingError: {
526+
message: 'Database connection refused at 10.0.3.42:5432',
527+
stack: 'Error: Database connection refused\n at Pool (/app/lib/db.ts:18:11)',
528+
},
529+
});
530+
const mockHTML = createMockHTMLStream(['<html><body><div>Hello, world!</div></body></html>']);
531+
const { rscRequestTracker, domNodeId } = setupTest(mockRSC);
532+
533+
const result = injectRSCPayload(mockHTML, rscRequestTracker, domNodeId);
534+
const resultStr = await collectStreamData(result);
535+
536+
expect(resultStr).toContain('"hasErrors":true');
537+
expect(resultStr).not.toContain('Database connection refused');
538+
expect(resultStr).not.toContain('10.0.3.42');
539+
expect(resultStr).not.toContain('db.ts');
540+
expect(resultStr).not.toContain('renderingError');
541+
});
542+
522543
it('forces hasErrors:true in production even when metadata has hasErrors:false with renderingError signal', async () => {
523544
const mockRSC = createMockRSCStreamWithMetadata('{"test": "data"}', {
524545
hasErrors: false,

0 commit comments

Comments
 (0)