Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions change/change-d225ca47-dc98-496f-b248-d0fbd2439a71.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
35 changes: 24 additions & 11 deletions packages/ado-npm-auth-lib/src/npmrc/npmrcFileProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>((registry) => config.get(registry, "project") as string)
return registryConfigKeys
.map<string>(
(registryConfigKey) =>
config.get(registryConfigKey, "project") as string,
)
.map((feed) => getFeedWithoutProtocol(feed));
}

override async getUserFeeds(): Promise<Map<string, Feed>> {
const result = new Map<string, Feed>();
const feeds = new Map<string, Feed>();
await this.processFeeds(this.userFilePath, feeds);
await this.processFeeds(this.workspaceFilePath, feeds);
return feeds;
}

async processFeeds(
filePath: string,
feeds: Map<string, Feed>,
): Promise<void> {
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;
Expand All @@ -101,8 +116,6 @@ export class NpmrcFileProvider extends FileProvider {
}
},
);

return result;
}

async patchUserNpmRcFile(
Expand Down