@ -15,11 +15,7 @@ describe('authutil tests', () => {
let dbgSpy : jest.SpyInstance ;
let dbgSpy : jest.SpyInstance ;
beforeAll ( async ( ) = > {
beforeAll ( async ( ) = > {
const randPath = path . join (
const randPath = path . join ( Math . random ( ) . toString ( 36 ) . substring ( 7 ) ) ;
Math . random ( )
. toString ( 36 )
. substring ( 7 )
) ;
console . log ( '::stop-commands::stoptoken' ) ; // Disable executing of runner commands when running tests in actions
console . log ( '::stop-commands::stoptoken' ) ; // Disable executing of runner commands when running tests in actions
process . env [ 'GITHUB_ENV' ] = '' ; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
process . env [ 'GITHUB_ENV' ] = '' ; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible)
const tempDir = path . join ( _runnerDir , randPath , 'temp' ) ;
const tempDir = path . join ( _runnerDir , randPath , 'temp' ) ;
@ -67,10 +63,10 @@ describe('authutil tests', () => {
} , 100000 ) ;
} , 100000 ) ;
function readRcFile ( rcFile : string ) {
function readRcFile ( rcFile : string ) {
le t rc = { } ;
cons t rc = { } ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
for ( const line of contents . split ( os . EOL ) ) {
for ( const line of contents . split ( os . EOL ) ) {
le t parts = line . split ( '=' ) ;
cons t parts = line . split ( '=' ) ;
if ( parts . length == 2 ) {
if ( parts . length == 2 ) {
rc [ parts [ 0 ] . trim ( ) ] = parts [ 1 ] . trim ( ) ;
rc [ parts [ 0 ] . trim ( ) ] = parts [ 1 ] . trim ( ) ;
}
}
@ -82,8 +78,8 @@ describe('authutil tests', () => {
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'false' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'false' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
} ) ;
} ) ;
@ -92,7 +88,7 @@ describe('authutil tests', () => {
await auth . configAuthentication ( 'https://registry.npmjs.org' , 'false' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org' , 'false' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
} ) ;
} ) ;
@ -102,7 +98,7 @@ describe('authutil tests', () => {
await auth . configAuthentication ( 'https://registry.npmjs.org' , 'false' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org' , 'false' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ '@myscope:registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ '@myscope:registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
} ) ;
} ) ;
@ -111,7 +107,7 @@ describe('authutil tests', () => {
await auth . configAuthentication ( 'npm.pkg.github.com' , 'false' ) ;
await auth . configAuthentication ( 'npm.pkg.github.com' , 'false' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ '@ownername:registry' ] ) . toBe ( 'npm.pkg.github.com/' ) ;
expect ( rc [ '@ownername:registry' ] ) . toBe ( 'npm.pkg.github.com/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
} ) ;
} ) ;
@ -119,16 +115,16 @@ describe('authutil tests', () => {
it ( 'Sets up npmrc for always-auth true' , async ( ) = > {
it ( 'Sets up npmrc for always-auth true' , async ( ) = > {
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'registry' ] ) . toBe ( 'https://registry.npmjs.org/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'true' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'true' ) ;
} ) ;
} ) ;
it ( ' It is already set the NODE_AUTH_TOKEN export it ', async ( ) = > {
it ( ' is already set the NODE_AUTH_TOKEN export it', async ( ) = > {
process . env . NODE_AUTH_TOKEN = 'foobar' ;
process . env . NODE_AUTH_TOKEN = 'foobar' ;
await auth . configAuthentication ( 'npm.pkg.github.com' , 'false' ) ;
await auth . configAuthentication ( 'npm.pkg.github.com' , 'false' ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
expect ( fs . statSync ( rcFile ) ) . toBeDefined ( ) ;
le t rc = readRcFile ( rcFile ) ;
cons t rc = readRcFile ( rcFile ) ;
expect ( rc [ '@ownername:registry' ] ) . toBe ( 'npm.pkg.github.com/' ) ;
expect ( rc [ '@ownername:registry' ] ) . toBe ( 'npm.pkg.github.com/' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( rc [ 'always-auth' ] ) . toBe ( 'false' ) ;
expect ( process . env . NODE_AUTH_TOKEN ) . toEqual ( 'foobar' ) ;
expect ( process . env . NODE_AUTH_TOKEN ) . toEqual ( 'foobar' ) ;
@ -137,7 +133,7 @@ describe('authutil tests', () => {
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/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -146,7 +142,7 @@ describe('authutil tests', () => {
it ( 'configAuthentication should overwrite only non-scoped' , async ( ) = > {
it ( 'configAuthentication should overwrite only non-scoped' , async ( ) = > {
fs . writeFileSync ( rcFile , ` registry=NNN ${ os . EOL } @myscope:registry=MMM ` ) ;
fs . writeFileSync ( rcFile , ` registry=NNN ${ os . EOL } @myscope:registry=MMM ` ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` @myscope:registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` @myscope:registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -155,7 +151,7 @@ describe('authutil tests', () => {
it ( 'configAuthentication should add non-scoped to scoped' , async ( ) = > {
it ( 'configAuthentication should add non-scoped to scoped' , async ( ) = > {
fs . writeFileSync ( rcFile , '@myscope:registry=NNN' ) ;
fs . writeFileSync ( rcFile , '@myscope:registry=NNN' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` @myscope:registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` @myscope:registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -165,7 +161,7 @@ describe('authutil tests', () => {
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
fs . writeFileSync ( rcFile , ` @myscope:registry=NNN ` ) ;
fs . writeFileSync ( rcFile , ` @myscope:registry=NNN ` ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -175,7 +171,7 @@ describe('authutil tests', () => {
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
fs . writeFileSync ( rcFile , ` registry=NNN ${ os . EOL } @myscope:registry=MMM ` ) ;
fs . writeFileSync ( rcFile , ` registry=NNN ${ os . EOL } @myscope:registry=MMM ` ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -185,7 +181,7 @@ describe('authutil tests', () => {
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
fs . writeFileSync ( rcFile , ` registry=MMM ` ) ;
fs . writeFileSync ( rcFile , ` registry=MMM ` ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -198,7 +194,7 @@ describe('authutil tests', () => {
` @otherscope:registry=NNN ${ os . EOL } @myscope:registry=MMM `
` @otherscope:registry=NNN ${ os . EOL } @myscope:registry=MMM `
) ;
) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` @otherscope:registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` @otherscope:registry=NNN ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;
@ -208,7 +204,7 @@ describe('authutil tests', () => {
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
process . env [ 'INPUT_SCOPE' ] = 'myscope' ;
fs . writeFileSync ( rcFile , ` @otherscope:registry=MMM ` ) ;
fs . writeFileSync ( rcFile , ` @otherscope:registry=MMM ` ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
await auth . configAuthentication ( 'https://registry.npmjs.org/' , 'true' ) ;
le t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
cons t contents = fs . readFileSync ( rcFile , { encoding : 'utf8' } ) ;
expect ( contents ) . toBe (
expect ( contents ) . toBe (
` @otherscope:registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
` @otherscope:registry=MMM ${ os . EOL } //registry.npmjs.org/:_authToken= \ ${ NODE_AUTH_TOKEN } ${ os . EOL } @myscope:registry=https://registry.npmjs.org/ ${ os . EOL } always-auth=true `
) ;
) ;