mirror of
https://github.com/actions/setup-node.git
synced 2026-02-04 06:28:20 +00:00
Merge ecb118ff9d into 6044e13b5d
This commit is contained in:
commit
02bd4fe351
4 changed files with 31 additions and 7 deletions
|
|
@ -118,6 +118,24 @@ describe('authutil tests', () => {
|
||||||
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
|
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not export NODE_AUTH_TOKEN if not set (OIDC support)', async () => {
|
||||||
|
// Clean NODE_AUTH_TOKEN from environment
|
||||||
|
delete process.env.NODE_AUTH_TOKEN;
|
||||||
|
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||||
|
expect(fs.statSync(rcFile)).toBeDefined();
|
||||||
|
// NODE_AUTH_TOKEN should not be exported to environment if not initially set
|
||||||
|
// This allows OIDC authentication to work properly
|
||||||
|
const rc = readRcFile(rcFile);
|
||||||
|
expect(rc['registry']).toBe('https://registry.npmjs.org/');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should export empty string NODE_AUTH_TOKEN if explicitly set to empty (OIDC support)', async () => {
|
||||||
|
process.env.NODE_AUTH_TOKEN = '';
|
||||||
|
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||||
|
expect(fs.statSync(rcFile)).toBeDefined();
|
||||||
|
expect(process.env.NODE_AUTH_TOKEN).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
|
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
|
||||||
fs.writeFileSync(rcFile, 'registry=NNN');
|
fs.writeFileSync(rcFile, 'registry=NNN');
|
||||||
await auth.configAuthentication('https://registry.npmjs.org/');
|
await auth.configAuthentication('https://registry.npmjs.org/');
|
||||||
|
|
|
||||||
8
dist/setup/index.js
vendored
8
dist/setup/index.js
vendored
|
|
@ -53633,8 +53633,12 @@ function writeRegistryToFile(registryUrl, fileLocation) {
|
||||||
newContents += `${authString}${os.EOL}${registryString}`;
|
newContents += `${authString}${os.EOL}${registryString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||||
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
|
// Only export NODE_AUTH_TOKEN if explicitly provided by user
|
||||||
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
|
// This is required to support NPM OIDC tokens which need NODE_AUTH_TOKEN to be unset
|
||||||
|
// See: https://github.com/actions/setup-node/issues/1440
|
||||||
|
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
|
||||||
|
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -513,6 +513,7 @@
|
||||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/code-frame": "^7.27.1",
|
"@babel/code-frame": "^7.27.1",
|
||||||
"@babel/generator": "^7.28.5",
|
"@babel/generator": "^7.28.5",
|
||||||
|
|
|
||||||
|
|
@ -46,9 +46,10 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
|
||||||
newContents += `${authString}${os.EOL}${registryString}`;
|
newContents += `${authString}${os.EOL}${registryString}`;
|
||||||
fs.writeFileSync(fileLocation, newContents);
|
fs.writeFileSync(fileLocation, newContents);
|
||||||
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
|
||||||
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
|
// Only export NODE_AUTH_TOKEN if explicitly provided by user
|
||||||
core.exportVariable(
|
// This is required to support NPM OIDC tokens which need NODE_AUTH_TOKEN to be unset
|
||||||
'NODE_AUTH_TOKEN',
|
// See: https://github.com/actions/setup-node/issues/1440
|
||||||
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
|
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
|
||||||
);
|
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue