Skip to content

Commit

Permalink
Merge pull request #317 from amarlankri/fix/context-parsing
Browse files Browse the repository at this point in the history
fix(redirect-url): fix wrong parsing of callbackUrl containing params
  • Loading branch information
KhadijaBenAmmar authored Nov 4, 2021
2 parents 5de98b3 + e30608b commit da80dbf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/aggregator/services/aggregator.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,39 @@ describe('AggregatorService', () => {
it('should not try to re-create an item when there is one already', async () => {
// TODO
});

it('should extract correct context when callbackUrl contains query params', async () => {
const registerSpy = jest.spyOn(client, 'register').mockResolvedValueOnce({
uuid: '79c8961c-bdf7-11e5-88a3-4f2c2aec0665',
resource_type: 'user',
resource_uri: '/v2/users/79c8961c-bdf7-11e5-88a3-4f2c2aec0665',
email: 'john.doe@email.com',
});
const authenticateSpy = jest.spyOn(client, 'authenticate').mockResolvedValueOnce({
access_token: 'access-token',
expires_at: '2019-05-06T11:08:25.040Z',
user: {
uuid: 'c2a26c9e-dc23-4f67-b887-bbae0f26c415',
resource_uri: '/v2/users/c2a26c9e-dc23-4f67-b887-bbae0f26c415',
resource_type: 'user',
email: 'john.doe@email.com',
},
});
const connectItemSpy = jest.spyOn(client, 'connectItem').mockResolvedValueOnce({
redirect_url: 'https://bridge/redirection-url',
});

await service.generateRedirectUrl(
customerMock.id,
'https://domain.com/call-back?param=1',
);
expect(connectItemSpy).toHaveBeenCalledWith(
'access-token',
"callzback",
undefined,
undefined,
);
});
});

it('should refresh an item', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/aggregator/services/aggregator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export class AggregatorService {
if (splittedCbUrl === undefined) {
throw new Error('No callbackUrl provided');
}
const uuid: string = splittedCbUrl[splittedCbUrl.length - 1].replace(/-/g, 'z');

const lastUrlSegment: string = splittedCbUrl[splittedCbUrl.length - 1];
const lastUrlSegmentWithoutQueryParams: string = lastUrlSegment.split('?')[0];
const uuid: string = lastUrlSegmentWithoutQueryParams.replace(/-/g, 'z');

const redirectResponse = await this.bridgeClient.connectItem(
authenticationResponse.access_token,
Expand Down

0 comments on commit da80dbf

Please sign in to comment.