-
Notifications
You must be signed in to change notification settings - Fork 0
Fix governance feed and IPv6 masternode search #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| jest.mock('../services/rpcClient', () => ({ | ||
| client: { callRpc: jest.fn() }, | ||
| rpcServices: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('../lib/securityLog', () => ({ | ||
| event: jest.fn(), | ||
| })); | ||
|
|
||
| const { rpcServices } = require('../services/rpcClient'); | ||
| const securityLog = require('../lib/securityLog'); | ||
| const governanceRoute = require('../routes/governance'); | ||
|
|
||
| function buildApp() { | ||
| const app = express(); | ||
| app.use(governanceRoute); | ||
| return app; | ||
| } | ||
|
|
||
| function mockGObjectList(value) { | ||
| rpcServices.mockReturnValue({ | ||
| gObject_list: () => ({ | ||
| call: jest.fn().mockResolvedValue(value), | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
| describe('POST /govlist', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| test('skips malformed DataString entries without failing the whole feed', async () => { | ||
| mockGObjectList({ | ||
| valid: { | ||
| Hash: 'valid-hash', | ||
| CollateralHash: 'collateral', | ||
| ObjectType: 1, | ||
| CreationTime: 123, | ||
| AbsoluteYesCount: 9, | ||
| YesCount: 10, | ||
| NoCount: 1, | ||
| AbstainCount: 0, | ||
| fBlockchainValidity: true, | ||
| IsValidReason: '', | ||
| fCachedValid: true, | ||
| fCachedFunding: true, | ||
| fCachedDelete: false, | ||
| fCachedEndorsed: false, | ||
| DataString: JSON.stringify({ name: 'valid proposal' }), | ||
| }, | ||
| malformed: { | ||
| Hash: 'bad-hash', | ||
| AbsoluteYesCount: 99, | ||
| DataString: '{not json', | ||
| }, | ||
| }); | ||
|
|
||
| const res = await request(buildApp()).post('/govlist').send({}); | ||
|
|
||
| expect(res.status).toBe(200); | ||
| expect(res.body).toHaveLength(1); | ||
| expect(res.body[0]).toMatchObject({ | ||
| Key: 'valid', | ||
| Hash: 'valid-hash', | ||
| name: 'valid proposal', | ||
| }); | ||
| expect(securityLog.event).toHaveBeenCalledWith( | ||
| 'govlist.malformed_data_string', | ||
| expect.objectContaining({ | ||
| key: 'malformed', | ||
| hash: 'bad-hash', | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| test('still returns a generic 500 when the RPC call itself fails', async () => { | ||
| rpcServices.mockReturnValue({ | ||
| gObject_list: () => ({ | ||
| call: jest.fn().mockRejectedValue(new Error('rpc down')), | ||
| }), | ||
| }); | ||
|
|
||
| const res = await request(buildApp()).post('/govlist').send({}); | ||
|
|
||
| expect(res.status).toBe(500); | ||
| expect(res.body).toEqual({ error: 'internal' }); | ||
| expect(securityLog.event).toHaveBeenCalledWith( | ||
| 'govlist.rpc_failed', | ||
| expect.objectContaining({ message: 'rpc down' }) | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When a user searches with an unbracketed IPv6 endpoint that includes a port (for example, copy/pasting
2001:db8::1:18370from the address column),querykeeps the port while each masternode address is normalized withstripUnbracketedIpv6Port: true, so the exact IPv6 comparison can never match. This makes valid IPv6 entries unsearchable in that common input path; normalize the query with the same port-stripping rule (or compare endpoint-to-endpoint consistently) before theaddressHost === querycheck.Useful? React with 👍 / 👎.