diff --git a/change/change-d225ca47-dc98-496f-b248-d0fbd2439a71.json b/change/change-d225ca47-dc98-496f-b248-d0fbd2439a71.json new file mode 100644 index 00000000..4bb532ce --- /dev/null +++ b/change/change-d225ca47-dc98-496f-b248-d0fbd2439a71.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "type": "minor", + "comment": "Fix registry extraction form .npmrc. We had false positives for authentication comments like ://", + "packageName": "@microsoft/ado-npm-auth-lib", + "email": "dannyvv@microsoft.com", + "dependentChangeType": "patch" + } + ] +} \ No newline at end of file diff --git a/packages/ado-npm-auth-lib/src/npmrc/npmrcFileProvider.ts b/packages/ado-npm-auth-lib/src/npmrc/npmrcFileProvider.ts index ce603604..77c9a5a8 100644 --- a/packages/ado-npm-auth-lib/src/npmrc/npmrcFileProvider.ts +++ b/packages/ado-npm-auth-lib/src/npmrc/npmrcFileProvider.ts @@ -64,34 +64,49 @@ export class NpmrcFileProvider extends FileProvider { (config.data?.get("project") || {})["data"] || {}, ); - // find any and all keys which are a registry - const registries = projectNpmrcKeys.filter((key) => - key.includes("registry"), + // find any and all keys which are a registry. + const registryConfigKeys = projectNpmrcKeys.filter( + (key) => key === "registry" || key.endsWith(":registry"), ); - return registries - .map((registry) => config.get(registry, "project") as string) + return registryConfigKeys + .map( + (registryConfigKey) => + config.get(registryConfigKey, "project") as string, + ) .map((feed) => getFeedWithoutProtocol(feed)); } override async getUserFeeds(): Promise> { - const result = new Map(); + const feeds = new Map(); + await this.processFeeds(this.userFilePath, feeds); + await this.processFeeds(this.workspaceFilePath, feeds); + return feeds; + } + async processFeeds( + filePath: string, + feeds: Map, + ): Promise { await this.processNpmRcFile( - this.userFilePath, + filePath, (_: string, registry: string, field: string, value: string) => { - let feed = result.get(registry); + let feed = feeds.get(registry); if (!feed) { feed = { registry: registry, adoOrganization: getOrganizationFromFeedUrl(registry), }; - result.set(feed.registry, feed); + feeds.set(feed.registry, feed); } switch (field) { case "_password": + case "_auth": feed.authToken = fromBase64(value).trim(); break; + case "_authToken": + feed.authToken = value.trim(); + break; case "username": feed.userName = value; break; @@ -101,8 +116,6 @@ export class NpmrcFileProvider extends FileProvider { } }, ); - - return result; } async patchUserNpmRcFile(