( /** * When true, the authentication token will be scoped to the registry URL. * @example * ```ini * //localhost:4876/:_auth="dGVzdGluZzpzM2NyZXQ=" * ``` * * When false, the authentication will be added as seperate key. * @example * ```ini * _auth="dGVzdGluZzpzM2NyZXQ="` * ``` */ scopedAuthentication = true, /** When true, an incorrect token is used. Use this to validate authentication failures. */ invalidToken = false, )
| 50 | const VALID_TOKEN = `dGVzdGluZzpzM2NyZXQ=`; |
| 51 | |
| 52 | export async function createNpmConfigForAuthentication( |
| 53 | /** |
| 54 | * When true, the authentication token will be scoped to the registry URL. |
| 55 | * @example |
| 56 | * ```ini |
| 57 | * //localhost:4876/:_auth="dGVzdGluZzpzM2NyZXQ=" |
| 58 | * ``` |
| 59 | * |
| 60 | * When false, the authentication will be added as seperate key. |
| 61 | * @example |
| 62 | * ```ini |
| 63 | * _auth="dGVzdGluZzpzM2NyZXQ="` |
| 64 | * ``` |
| 65 | */ |
| 66 | scopedAuthentication = true, |
| 67 | /** When true, an incorrect token is used. Use this to validate authentication failures. */ |
| 68 | invalidToken = false, |
| 69 | ): Promise<void> { |
| 70 | const token = invalidToken ? `invalid=` : VALID_TOKEN; |
| 71 | const registry = (getGlobalVariable('package-secure-registry') as string).replace(/^\w+:/, ''); |
| 72 | |
| 73 | await writeFile( |
| 74 | '.npmrc', |
| 75 | scopedAuthentication |
| 76 | ? ` |
| 77 | ${registry}/:_auth="${token}" |
| 78 | registry=http:${registry} |
| 79 | ` |
| 80 | : ` |
| 81 | _auth="${token}" |
| 82 | registry=http:${registry} |
| 83 | `, |
| 84 | ); |
| 85 | |
| 86 | await writeFile( |
| 87 | '.yarnrc', |
| 88 | scopedAuthentication |
| 89 | ? ` |
| 90 | ${registry}/:_auth "${token}" |
| 91 | registry http:${registry} |
| 92 | ` |
| 93 | : ` |
| 94 | _auth "${token}" |
| 95 | registry http:${registry} |
| 96 | `, |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | export function setNpmEnvVarsForAuthentication( |
| 101 | /** When true, an incorrect token is used. Use this to validate authentication failures. */ |
no test coverage detected