|
| 1 | +import { |
| 2 | + extractComplianceBadges, |
| 3 | + mapCertificationToBadgeType, |
| 4 | +} from './cert-badge-mapper'; |
| 5 | + |
| 6 | +describe('mapCertificationToBadgeType', () => { |
| 7 | + // CS-688: the "IEC" infix and ":2022" suffix must not stop ISO 27001 from |
| 8 | + // being recognized. |
| 9 | + it('maps "ISO/IEC 27001:2022" to iso27001', () => { |
| 10 | + expect(mapCertificationToBadgeType('ISO/IEC 27001:2022')).toBe('iso27001'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('maps common certifications to their canonical badge types', () => { |
| 14 | + expect(mapCertificationToBadgeType('SOC 2 Type II')).toBe('soc2'); |
| 15 | + expect(mapCertificationToBadgeType('ISO 9001:2015')).toBe('iso9001'); |
| 16 | + expect(mapCertificationToBadgeType('ISO/IEC 42001:2023')).toBe('iso42001'); |
| 17 | + expect(mapCertificationToBadgeType('GDPR Compliance')).toBe('gdpr'); |
| 18 | + expect(mapCertificationToBadgeType('HIPAA')).toBe('hipaa'); |
| 19 | + expect(mapCertificationToBadgeType('PCI DSS')).toBe('pci_dss'); |
| 20 | + expect(mapCertificationToBadgeType('NEN 7510')).toBe('nen7510'); |
| 21 | + }); |
| 22 | + |
| 23 | + // The fully spelled-out PCI name must map too — the scan-time mappers already |
| 24 | + // recognize it, so the shared display mapper must not drop it. |
| 25 | + it('maps the spelled-out "Payment Card Industry Data Security Standard"', () => { |
| 26 | + expect( |
| 27 | + mapCertificationToBadgeType('Payment Card Industry Data Security Standard'), |
| 28 | + ).toBe('pci_dss'); |
| 29 | + }); |
| 30 | + |
| 31 | + // The digits alone must not classify an unrelated identifier. |
| 32 | + it('does not misclassify ids that merely contain the standard digits', () => { |
| 33 | + expect(mapCertificationToBadgeType('Catalog 19001')).toBeNull(); |
| 34 | + expect(mapCertificationToBadgeType('ISO 90010')).toBeNull(); |
| 35 | + }); |
| 36 | + |
| 37 | + // Distinct 2701x standards must not earn the 27001 badge. |
| 38 | + it('does not read ISO/IEC 27017 or 27018 as iso27001', () => { |
| 39 | + expect(mapCertificationToBadgeType('ISO/IEC 27017:2015')).toBeNull(); |
| 40 | + expect(mapCertificationToBadgeType('ISO/IEC 27018:2019')).toBeNull(); |
| 41 | + }); |
| 42 | + |
| 43 | + it('returns null for certifications with no badge', () => { |
| 44 | + expect(mapCertificationToBadgeType('HDS')).toBeNull(); |
| 45 | + expect(mapCertificationToBadgeType('')).toBeNull(); |
| 46 | + }); |
| 47 | +}); |
| 48 | + |
| 49 | +describe('extractComplianceBadges', () => { |
| 50 | + // CS-688 regression: Scaleway's verified certs must yield iso27001 + gdpr. |
| 51 | + it('extracts verified badges and skips unrecognized certs', () => { |
| 52 | + const badges = extractComplianceBadges({ |
| 53 | + certifications: [ |
| 54 | + { type: 'ISO/IEC 27001:2022', status: 'verified' }, |
| 55 | + { type: 'HDS', status: 'verified' }, |
| 56 | + { type: 'GDPR Compliance', status: 'verified' }, |
| 57 | + ], |
| 58 | + }); |
| 59 | + |
| 60 | + const types = badges.map((b) => b.type); |
| 61 | + expect(types).toContain('iso27001'); |
| 62 | + expect(types).toContain('gdpr'); |
| 63 | + expect(types).not.toContain('HDS'); |
| 64 | + }); |
| 65 | + |
| 66 | + it('ignores certifications that are not verified', () => { |
| 67 | + const badges = extractComplianceBadges({ |
| 68 | + certifications: [ |
| 69 | + { type: 'ISO/IEC 27001:2022', status: 'expired' }, |
| 70 | + { type: 'GDPR Compliance', status: 'verified' }, |
| 71 | + ], |
| 72 | + }); |
| 73 | + |
| 74 | + expect(badges.map((b) => b.type)).toEqual(['gdpr']); |
| 75 | + }); |
| 76 | + |
| 77 | + it('de-duplicates repeated badge types', () => { |
| 78 | + const badges = extractComplianceBadges({ |
| 79 | + certifications: [ |
| 80 | + { type: 'ISO/IEC 27001:2022', status: 'verified' }, |
| 81 | + { type: 'ISO 27001:2013', status: 'verified' }, |
| 82 | + ], |
| 83 | + }); |
| 84 | + |
| 85 | + expect(badges).toEqual([{ type: 'iso27001', verified: true }]); |
| 86 | + }); |
| 87 | + |
| 88 | + it('returns an empty array for missing or malformed data', () => { |
| 89 | + expect(extractComplianceBadges(null)).toEqual([]); |
| 90 | + expect(extractComplianceBadges({})).toEqual([]); |
| 91 | + expect(extractComplianceBadges({ certifications: 'nope' })).toEqual([]); |
| 92 | + }); |
| 93 | +}); |
0 commit comments