11import * as assert from 'assert' ;
2- import * as fs from 'fs' ;
32import * as path from 'path' ;
4- import * as Q from 'q' ;
5-
63import * as mockery from 'mockery' ;
74import * as ttm from 'vsts-task-lib/mock-test' ;
85
96import { NpmMockHelper } from './NpmMockHelper' ;
7+ import Lazy_NpmRegistry = require( 'npm-common/npmregistry' ) ;
108
119const BASIC_AUTH_PAT_PASSWD_REGEX = / \/ \/ .* \/ : _ p a s s w o r d = .* / g;
1210const BEARER_AUTH_REGEX = / \/ \/ .* \/ : _ a u t h T o k e n = A U T H T O K E N .* / g;
@@ -16,6 +14,7 @@ const AWLAYS_AUTH_REGEX = /\/\/.*\/:always-auth=true.*/g;
1614
1715describe ( 'Npm Task' , function ( ) {
1816 before ( ( ) => {
17+ mockery . disable ( ) ; // needed to ensure that we can mock vsts-task-lib/task
1918 mockery . enable ( {
2019 useCleanCache : true ,
2120 warnOnUnregistered : false
@@ -236,15 +235,21 @@ describe('Npm Task', function () {
236235 } ) ;
237236
238237 it ( 'gets feed id from VSTS registry' , ( done : MochaDone ) => {
239- mockery . registerMock ( 'vsts-task-lib/task' , { } ) ;
238+ let mockTask = {
239+ debug : message => { }
240+ } ;
241+ mockery . registerMock ( 'vsts-task-lib/task' , mockTask ) ;
240242 let util = require ( 'npm-common/util' ) ;
241243
242244 assert . equal ( util . getFeedIdFromRegistry (
243- 'http ://account.visualstudio.com/_packaging/feedId/npm/registry' ) ,
245+ 'https ://account.visualstudio.com/_packaging/feedId/npm/registry' ) ,
244246 'feedId' ) ;
245247 assert . equal ( util . getFeedIdFromRegistry (
246- 'http ://account.visualstudio.com/_packaging/feedId/npm/registry/' ) ,
248+ 'https ://account.visualstudio.com/_packaging/feedId/npm/registry/' ) ,
247249 'feedId' ) ;
250+ assert . equal ( util . getFeedIdFromRegistry (
251+ 'https://account.visualstudio.com/_packaging/feedId@PreRelease/npm/registry/' ) ,
252+ 'feedId@PreRelease' ) ;
248253 assert . equal ( util . getFeedIdFromRegistry (
249254 'http://TFSSERVER/_packaging/feedId/npm/registry' ) ,
250255 'feedId' ) ;
@@ -515,4 +520,39 @@ describe('Npm Task', function () {
515520 done ( ) ;
516521 } ) ;
517522
523+ it ( 'handles views in registry URL' , async ( done : MochaDone ) => {
524+ // Scenario: Includes view (e.g. @Release) within the registry entry
525+ const hostName = 'https://mytfsserver.visualstudio.com' ;
526+ const nerfedRegistry = "//mytfsserver.pkgs.visualstudio.com/npmRegistry@Release/npm/registry/" ;
527+ const registry = `https:${ nerfedRegistry } ` ;
528+ const authToken = '**sometoken**' ;
529+
530+ const mockTask = {
531+ loc : key => "LocValue" ,
532+ debug : msg => null ,
533+ exist : path => true ,
534+ getVariable : v => {
535+ return ( v === 'System.TeamFoundationCollectionUri' ) ? hostName : null ;
536+ } ,
537+ getEndpointAuthorization : ( id , optional ) => {
538+ return { scheme : 'OAuth' , parameters : { 'AccessToken' : authToken } } ;
539+ }
540+ } ;
541+ const mockParser = {
542+ GetRegistries : ( npmrc : string ) => [ registry ]
543+ } ;
544+ mockery . registerMock ( 'vsts-task-lib/task' , mockTask ) ;
545+ mockery . registerMock ( './npmrcparser' , mockParser ) ;
546+
547+ const util = require ( 'npm-common/util' ) ;
548+ const registries = await util . getLocalNpmRegistries ( "somePath" ) ;
549+
550+ assert . equal ( registries . length , 1 , "Expected one response" ) ;
551+ const npmRegistry : Lazy_NpmRegistry . INpmRegistry = registries [ 0 ] ;
552+ assert . equal ( npmRegistry . url , registry , "Registry needs to match" ) ;
553+ assert . equal ( npmRegistry . auth , `${ nerfedRegistry } :_authToken=${ authToken } ` , "Auth needs to match" ) ;
554+ assert . equal ( npmRegistry . authOnly , true , "Authonly needs to match" ) ;
555+
556+ done ( ) ;
557+ } ) ;
518558} ) ;
0 commit comments