Skip to content

Commit 0355742

Browse files
gowridurgadgowridurgad
andauthored
Remove dummy NODE_AUTH_TOKEN export (#1558)
Co-authored-by: gowridurgad <gowridurgad@gmail.com>
1 parent ad1b57e commit 0355742

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

__tests__/authutil.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ describe('authutil tests', () => {
118118
expect(process.env.NODE_AUTH_TOKEN).toEqual('foobar');
119119
});
120120

121+
it('should not export NODE_AUTH_TOKEN if not set in environment', async () => {
122+
const exportSpy = jest.spyOn(core, 'exportVariable');
123+
delete process.env.NODE_AUTH_TOKEN;
124+
await auth.configAuthentication('https://registry.npmjs.org/');
125+
expect(fs.statSync(rcFile)).toBeDefined();
126+
const rc = readRcFile(rcFile);
127+
expect(rc['registry']).toBe('https://registry.npmjs.org/');
128+
expect(exportSpy).not.toHaveBeenCalledWith(
129+
'NODE_AUTH_TOKEN',
130+
expect.anything()
131+
);
132+
});
133+
134+
it('should export NODE_AUTH_TOKEN if set to empty string', async () => {
135+
const exportSpy = jest.spyOn(core, 'exportVariable');
136+
process.env.NODE_AUTH_TOKEN = '';
137+
await auth.configAuthentication('https://registry.npmjs.org/');
138+
expect(fs.statSync(rcFile)).toBeDefined();
139+
expect(exportSpy).toHaveBeenCalledWith('NODE_AUTH_TOKEN', '');
140+
});
141+
121142
it('configAuthentication should overwrite non-scoped with non-scoped', async () => {
122143
fs.writeFileSync(rcFile, 'registry=NNN');
123144
await auth.configAuthentication('https://registry.npmjs.org/');

dist/setup/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78875,8 +78875,10 @@ function writeRegistryToFile(registryUrl, fileLocation) {
7887578875
newContents += `${authString}${os.EOL}${registryString}`;
7887678876
fs.writeFileSync(fileLocation, newContents);
7887778877
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
78878-
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
78879-
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX');
78878+
// Only export NODE_AUTH_TOKEN if explicitly provided by user
78879+
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
78880+
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
78881+
}
7888078882
}
7888178883

7888278884

src/authutil.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ function writeRegistryToFile(registryUrl: string, fileLocation: string) {
4646
newContents += `${authString}${os.EOL}${registryString}`;
4747
fs.writeFileSync(fileLocation, newContents);
4848
core.exportVariable('NPM_CONFIG_USERCONFIG', fileLocation);
49-
// Export empty node_auth_token if didn't exist so npm doesn't complain about not being able to find it
50-
core.exportVariable(
51-
'NODE_AUTH_TOKEN',
52-
process.env.NODE_AUTH_TOKEN || 'XXXXX-XXXXX-XXXXX-XXXXX'
53-
);
49+
// Only export NODE_AUTH_TOKEN if explicitly provided by user
50+
if (Object.prototype.hasOwnProperty.call(process.env, 'NODE_AUTH_TOKEN')) {
51+
core.exportVariable('NODE_AUTH_TOKEN', process.env.NODE_AUTH_TOKEN);
52+
}
5453
}

0 commit comments

Comments
 (0)