-
Notifications
You must be signed in to change notification settings - Fork 930
WEB-112: Sanitize GSIM fields before calculateLoanSchedule to avoid NPE #3569
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
Open
deepaksoni47
wants to merge
1
commit into
openMF:dev
Choose a base branch
from
deepaksoni47:WEB-112-fix-gsim-schedule-sanitization
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { TestBed } from '@angular/core/testing'; | ||
| import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; | ||
| import { provideHttpClient } from '@angular/common/http'; | ||
| import { LoansService } from './loans.service'; | ||
| import { SettingsService } from 'app/settings/settings.service'; | ||
| import { Dates } from 'app/core/utils/dates'; | ||
|
|
||
| describe('LoansService', () => { | ||
| let service: LoansService; | ||
| let httpMock: HttpTestingController; | ||
|
|
||
| beforeEach(() => { | ||
| const mockSettings: Partial<SettingsService> = { | ||
| language: { name: 'English', code: 'en' }, | ||
| dateFormat: 'yyyy-MM-dd', | ||
| businessDate: new Date(), | ||
| maxFutureDate: new Date() | ||
| }; | ||
| const mockDates: Partial<Dates> = { | ||
| formatDate: (d: any) => d, | ||
| formatDateAsString: (d: any) => String(d) | ||
| } as any; | ||
|
|
||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| LoansService, | ||
| provideHttpClient(), | ||
| provideHttpClientTesting(), | ||
| { provide: SettingsService, useValue: mockSettings }, | ||
| { provide: Dates, useValue: mockDates }] | ||
| }); | ||
| service = TestBed.inject(LoansService); | ||
| httpMock = TestBed.inject(HttpTestingController); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| httpMock.verify(); | ||
| }); | ||
|
|
||
| it('should sanitize all GSIM fields before posting calculateLoanSchedule', () => { | ||
| const payload = { | ||
| principal: 1000, | ||
| linkAccountId: 42, | ||
| linkAccountOwnerName: 'Alice', | ||
| linkedSavingsAccount: { id: 5 }, | ||
| nested: { | ||
| linkAccountOwnerId: 7, | ||
| linkAccountOwnerName: 'Bob', | ||
| ok: 'keep' | ||
| }, | ||
| members: [ | ||
| { id: 1, linkAccountId: 99 }, | ||
| { id: 2, name: 'foo', linkedSavingsAccount: { id: 9 } } | ||
| ] | ||
| } as any; | ||
|
|
||
| const original = JSON.parse(JSON.stringify(payload)); | ||
|
|
||
| service.calculateLoanSchedule(payload).subscribe(() => {}); | ||
|
|
||
| const req = httpMock.expectOne('/loans?command=calculateLoanSchedule'); | ||
| expect(req.request.method).toBe('POST'); | ||
|
|
||
| const body = req.request.body; | ||
|
|
||
| // All forbidden keys should be removed at every depth | ||
| expect(body.linkAccountId).toBeUndefined(); | ||
| expect(body.linkAccountOwnerName).toBeUndefined(); | ||
| expect(body.linkedSavingsAccount).toBeUndefined(); | ||
| expect(body.nested.linkAccountOwnerId).toBeUndefined(); | ||
| expect(body.nested.linkAccountOwnerName).toBeUndefined(); | ||
| expect(body.members[0].linkAccountId).toBeUndefined(); | ||
| expect(body.members[1].linkedSavingsAccount).toBeUndefined(); | ||
|
|
||
| // Allowed keys should be preserved | ||
| expect(body.principal).toBe(1000); | ||
| expect(body.nested.ok).toBe('keep'); | ||
| expect(body.members[1].name).toBe('foo'); | ||
|
|
||
| // Original caller payload must remain unmutated | ||
| expect(payload).toEqual(original); | ||
|
|
||
| req.flush({}); | ||
| }); | ||
|
|
||
| it('should keep non-object primitives intact', () => { | ||
| const payload = { value: 1, text: 'abc' }; | ||
| service.calculateLoanSchedule(payload).subscribe(() => {}); | ||
| const req = httpMock.expectOne('/loans?command=calculateLoanSchedule'); | ||
| expect(req.request.body.value).toBe(1); | ||
| expect(req.request.body.text).toBe('abc'); | ||
| req.flush({}); | ||
| }); | ||
| }); |
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.
what if a person requires to disburse a loan to a linked savings account?
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.
@IOhacker Thanks for pointing this out.
The intention here is only to sanitize payloads for the
calculateLoanSchedule()flow, which is used for repayment schedule preview/calculation and does not perform actual loan disbursement operations.Actual disbursement to linked savings accounts goes through separate actions/endpoints such as
disburseanddisbursetosavings, so those flows remain unaffected by this change.The issue I observed was specific to the schedule calculation endpoint, where the backend was throwing an NPE when GSIM-linked fields were included in the calculation payload. Since these fields are not required for repayment schedule computation itself, this change removes them only for that calculation request as a temporary defensive workaround until the backend-side validation is addressed.
Please let me know if there's a specific disbursement scenario that uses
calculateLoanSchedule()that I may have missed.