mirror of
				https://gitea.com/actions/setup-node.git
				synced 2025-10-29 15:52:42 +08:00 
			
		
		
		
	Add auth support (#21)
* Updates * Update * Update * Update * Update * Yarn sometimes prefers npmrc, so use same token * Description * Update readme * Feedback * Add type * new toolkit and scoped registries * npmrc in RUNNER_TEMP * Dont always auth * Try exporting blank token * Get auth working for now pending runner changes * Fix string interpolation for auth token. * Don't export both userconfigs * Update authutil.js * Add single quotes for authString * Fix the registry string. * Use userconfig and append trailing slash * Keep in root of repo * Try just adding auth token * Remove auth token * Try changes again * Add tests * Npm and GPR samples * Add types
This commit is contained in:
		
							
								
								
									
										62
									
								
								__tests__/authutil.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								__tests__/authutil.test.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| import io = require('@actions/io'); | ||||
| import fs = require('fs'); | ||||
| import path = require('path'); | ||||
|  | ||||
| const tempDir = path.join( | ||||
|   __dirname, | ||||
|   'runner', | ||||
|   path.join( | ||||
|     Math.random() | ||||
|       .toString(36) | ||||
|       .substring(7) | ||||
|   ), | ||||
|   'temp' | ||||
| ); | ||||
|  | ||||
| const rcFile = path.join(tempDir, '.npmrc'); | ||||
|  | ||||
| process.env['GITHUB_REPOSITORY'] = 'owner/repo'; | ||||
| process.env['RUNNER_TEMP'] = tempDir; | ||||
| import * as auth from '../src/authutil'; | ||||
|  | ||||
| describe('installer tests', () => { | ||||
|   beforeAll(async () => { | ||||
|     await io.rmRF(tempDir); | ||||
|     await io.mkdirP(tempDir); | ||||
|   }, 100000); | ||||
|  | ||||
|   beforeEach(() => { | ||||
|     if (fs.existsSync(rcFile)) { | ||||
|       fs.unlinkSync(rcFile); | ||||
|     } | ||||
|     process.env['INPUT_SCOPE'] = ''; | ||||
|   }); | ||||
|  | ||||
|   it('Sets up npmrc for npmjs', async () => { | ||||
|     await auth.configAuthentication('https://registry.npmjs.org/'); | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|   }); | ||||
|  | ||||
|   it('Appends trailing slash to registry', async () => { | ||||
|     await auth.configAuthentication('https://registry.npmjs.org'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|   }); | ||||
|  | ||||
|   it('Configures scoped npm registries', async () => { | ||||
|     process.env['INPUT_SCOPE'] = 'myScope'; | ||||
|     await auth.configAuthentication('https://registry.npmjs.org'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|   }); | ||||
|  | ||||
|   it('Automatically configures GPR scope', async () => { | ||||
|     await auth.configAuthentication('npm.pkg.github.com'); | ||||
|  | ||||
|     expect(fs.existsSync(rcFile)).toBe(true); | ||||
|     expect(fs.readFileSync(rcFile, {encoding: 'utf8'})).toMatchSnapshot(); | ||||
|   }); | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user