|
| 1 | +import type { VendorRiskAssessmentCertification } from './agent-types'; |
| 2 | +import { pickDeepScrapeSourceUrl } from './deep-scrape-source-url'; |
| 3 | + |
| 4 | +const cert = ( |
| 5 | + overrides: Partial<VendorRiskAssessmentCertification> = {}, |
| 6 | +): VendorRiskAssessmentCertification => ({ |
| 7 | + type: 'SOC 2 Type II', |
| 8 | + status: 'verified', |
| 9 | + issuedAt: null, |
| 10 | + expiresAt: null, |
| 11 | + url: null, |
| 12 | + ...overrides, |
| 13 | +}); |
| 14 | + |
| 15 | +describe('pickDeepScrapeSourceUrl', () => { |
| 16 | + const vendorDomain = 'acme.com'; |
| 17 | + |
| 18 | + it("prefers 'Trust & Security' link over 'Security Overview'", () => { |
| 19 | + const result = pickDeepScrapeSourceUrl({ |
| 20 | + vendorDomain, |
| 21 | + links: [ |
| 22 | + { label: 'Security Overview', url: 'https://acme.com/security' }, |
| 23 | + { label: 'Trust & Security', url: 'https://acme.com/trust' }, |
| 24 | + ], |
| 25 | + certifications: [], |
| 26 | + }); |
| 27 | + expect(result).toBe('https://acme.com/trust'); |
| 28 | + }); |
| 29 | + |
| 30 | + it("falls back to 'Security Overview' when no 'Trust & Security' link", () => { |
| 31 | + const result = pickDeepScrapeSourceUrl({ |
| 32 | + vendorDomain, |
| 33 | + links: [{ label: 'Security Overview', url: 'https://acme.com/security' }], |
| 34 | + certifications: [], |
| 35 | + }); |
| 36 | + expect(result).toBe('https://acme.com/security'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('falls back to a verified cert URL on the vendor domain when no labelled links match', () => { |
| 40 | + const result = pickDeepScrapeSourceUrl({ |
| 41 | + vendorDomain, |
| 42 | + links: [], |
| 43 | + certifications: [ |
| 44 | + cert({ url: 'https://acme.com/reports/soc2.pdf', status: 'verified' }), |
| 45 | + ], |
| 46 | + }); |
| 47 | + expect(result).toBe('https://acme.com/reports/soc2.pdf'); |
| 48 | + }); |
| 49 | + |
| 50 | + it('skips subdomain-matching cert URL when status is not verified', () => { |
| 51 | + const result = pickDeepScrapeSourceUrl({ |
| 52 | + vendorDomain, |
| 53 | + links: [], |
| 54 | + certifications: [ |
| 55 | + cert({ url: 'https://trust.acme.com/iso', status: 'unknown' }), |
| 56 | + ], |
| 57 | + }); |
| 58 | + expect(result).toBeNull(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('accepts subdomain-matching cert URL (same registrable domain)', () => { |
| 62 | + const result = pickDeepScrapeSourceUrl({ |
| 63 | + vendorDomain, |
| 64 | + links: [], |
| 65 | + certifications: [ |
| 66 | + cert({ url: 'https://trust.acme.com/iso', status: 'verified' }), |
| 67 | + ], |
| 68 | + }); |
| 69 | + expect(result).toBe('https://trust.acme.com/iso'); |
| 70 | + }); |
| 71 | + |
| 72 | + it('rejects off-domain labelled links', () => { |
| 73 | + const result = pickDeepScrapeSourceUrl({ |
| 74 | + vendorDomain, |
| 75 | + links: [ |
| 76 | + { label: 'Trust & Security', url: 'https://acme.trust.page' }, |
| 77 | + ], |
| 78 | + certifications: [], |
| 79 | + }); |
| 80 | + expect(result).toBeNull(); |
| 81 | + }); |
| 82 | + |
| 83 | + it('rejects off-domain verified cert URL', () => { |
| 84 | + const result = pickDeepScrapeSourceUrl({ |
| 85 | + vendorDomain, |
| 86 | + links: [], |
| 87 | + certifications: [ |
| 88 | + cert({ url: 'https://acme.safebase.io/soc2', status: 'verified' }), |
| 89 | + ], |
| 90 | + }); |
| 91 | + expect(result).toBeNull(); |
| 92 | + }); |
| 93 | + |
| 94 | + it('rejects unparseable URLs', () => { |
| 95 | + const result = pickDeepScrapeSourceUrl({ |
| 96 | + vendorDomain, |
| 97 | + links: [{ label: 'Trust & Security', url: 'not a url' }], |
| 98 | + certifications: [cert({ url: 'also not a url', status: 'verified' })], |
| 99 | + }); |
| 100 | + expect(result).toBeNull(); |
| 101 | + }); |
| 102 | + |
| 103 | + it('returns null when everything is empty', () => { |
| 104 | + const result = pickDeepScrapeSourceUrl({ |
| 105 | + vendorDomain, |
| 106 | + links: [], |
| 107 | + certifications: [], |
| 108 | + }); |
| 109 | + expect(result).toBeNull(); |
| 110 | + }); |
| 111 | + |
| 112 | + it('returns first verified cert URL and ignores later verified certs', () => { |
| 113 | + const result = pickDeepScrapeSourceUrl({ |
| 114 | + vendorDomain, |
| 115 | + links: [], |
| 116 | + certifications: [ |
| 117 | + cert({ |
| 118 | + type: 'SOC 2', |
| 119 | + status: 'verified', |
| 120 | + url: 'https://acme.com/first.pdf', |
| 121 | + }), |
| 122 | + cert({ |
| 123 | + type: 'ISO 27001', |
| 124 | + status: 'verified', |
| 125 | + url: 'https://acme.com/second.pdf', |
| 126 | + }), |
| 127 | + ], |
| 128 | + }); |
| 129 | + expect(result).toBe('https://acme.com/first.pdf'); |
| 130 | + }); |
| 131 | + |
| 132 | + it('skips verified certs whose URL is null and continues to next cert', () => { |
| 133 | + const result = pickDeepScrapeSourceUrl({ |
| 134 | + vendorDomain, |
| 135 | + links: [], |
| 136 | + certifications: [ |
| 137 | + cert({ type: 'SOC 2', status: 'verified', url: null }), |
| 138 | + cert({ |
| 139 | + type: 'ISO 27001', |
| 140 | + status: 'verified', |
| 141 | + url: 'https://acme.com/iso.pdf', |
| 142 | + }), |
| 143 | + ], |
| 144 | + }); |
| 145 | + expect(result).toBe('https://acme.com/iso.pdf'); |
| 146 | + }); |
| 147 | +}); |
0 commit comments