(urlParam)
| 37 | }; |
| 38 | |
| 39 | const securityTxtHandler = async (urlParam) => { |
| 40 | let url; |
| 41 | try { |
| 42 | url = new URL(urlParam.includes('://') ? urlParam : 'https://' + urlParam); |
| 43 | } catch (error) { |
| 44 | throw new Error('Invalid URL format'); |
| 45 | } |
| 46 | url.pathname = ''; |
| 47 | |
| 48 | for (let path of SECURITY_TXT_PATHS) { |
| 49 | try { |
| 50 | const result = await fetchSecurityTxt(url, path); |
| 51 | if (result && result.toLowerCase().includes('<html')) continue; |
| 52 | if (result) { |
| 53 | return { |
| 54 | isPresent: true, |
| 55 | foundIn: path, |
| 56 | content: result, |
| 57 | isPgpSigned: isPgpSigned(result), |
| 58 | fields: parseResult(result), |
| 59 | }; |
| 60 | } |
| 61 | } catch (error) { |
| 62 | throw new Error(error.message); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return { isPresent: false }; |
| 67 | }; |
| 68 | |
| 69 | // Returns the file body when the path 200s, else null so the next path is tried |
| 70 | const fetchSecurityTxt = async (baseURL, path) => { |
nothing calls this directly
no test coverage detected