@contrail/flexplm 1.7.1-alpha.a7e0d3c → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -183,7 +183,13 @@ class BaseEntityProcessor {
183
183
  return undefined;
184
184
  }
185
185
  const entityReference = identityEntity.entityReference;
186
+ if (typeof entityReference !== 'string' || !entityReference.includes(':')) {
187
+ throw new Error(`Invalid identity entityReference: ${String(entityReference)}`);
188
+ }
186
189
  const firstColonIndex = entityReference.indexOf(':');
190
+ if (firstColonIndex === 0 || firstColonIndex === entityReference.length - 1) {
191
+ throw new Error('Invalid identity entityReference: ' + entityReference);
192
+ }
187
193
  const entityName = entityReference.slice(0, firstColonIndex);
188
194
  const id = entityReference.slice(firstColonIndex + 1);
189
195
  const entity = await this.entities.get({
@@ -617,5 +617,50 @@ describe('BaseEntityProcessor', () => {
617
617
  id: 'e5g8ugusNWOuCvdw:nju12Jw2jGFvcQSf'
618
618
  });
619
619
  });
620
+ it('should throw error when entityReference has no colon', async () => {
621
+ mockEntitiesGet.mockResolvedValue([{ entityReference: 'item1' }]);
622
+ await expect(btep.getEntityUsingIdentityService({
623
+ poolKey: 'item',
624
+ propertyName: 'itemNumber',
625
+ propertyValue: '12345'
626
+ })).rejects.toThrow('Invalid identity entityReference: item1');
627
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
628
+ });
629
+ it('should throw error when entityReference is not a string', async () => {
630
+ mockEntitiesGet.mockResolvedValue([{ entityReference: 12345 }]);
631
+ await expect(btep.getEntityUsingIdentityService({
632
+ poolKey: 'item',
633
+ propertyName: 'itemNumber',
634
+ propertyValue: '12345'
635
+ })).rejects.toThrow('Invalid identity entityReference: 12345');
636
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
637
+ });
638
+ it('should throw error when entityReference is undefined', async () => {
639
+ mockEntitiesGet.mockResolvedValue([{}]);
640
+ await expect(btep.getEntityUsingIdentityService({
641
+ poolKey: 'item',
642
+ propertyName: 'itemNumber',
643
+ propertyValue: '12345'
644
+ })).rejects.toThrow('Invalid identity entityReference: undefined');
645
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
646
+ });
647
+ it('should throw error when entityReference starts with a colon (missing entityName)', async () => {
648
+ mockEntitiesGet.mockResolvedValue([{ entityReference: ':1' }]);
649
+ await expect(btep.getEntityUsingIdentityService({
650
+ poolKey: 'item',
651
+ propertyName: 'itemNumber',
652
+ propertyValue: '12345'
653
+ })).rejects.toThrow('Invalid identity entityReference: :1');
654
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
655
+ });
656
+ it('should throw error when entityReference ends with a colon (missing id)', async () => {
657
+ mockEntitiesGet.mockResolvedValue([{ entityReference: 'item:' }]);
658
+ await expect(btep.getEntityUsingIdentityService({
659
+ poolKey: 'item',
660
+ propertyName: 'itemNumber',
661
+ propertyValue: '12345'
662
+ })).rejects.toThrow('Invalid identity entityReference: item:');
663
+ expect(mockEntitiesGet).toHaveBeenCalledTimes(1);
664
+ });
620
665
  });
621
666
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/flexplm",
3
- "version": "1.7.1-alpha.a7e0d3c",
3
+ "version": "1.7.1",
4
4
  "description": "Library used for integration with flexplm.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",