-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(npm): use configured auth for tarball urls instead of scope auth #24111
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,11 @@ use deno_npm::npm_rc::ResolvedNpmRc; | |
use deno_npm::registry::NpmPackageVersionDistInfo; | ||
use deno_runtime::deno_fs::FileSystem; | ||
use deno_semver::package::PackageNv; | ||
use reqwest::StatusCode; | ||
use reqwest::Url; | ||
|
||
use crate::args::CacheSetting; | ||
use crate::http_util::DownloadError; | ||
use crate::http_util::HttpClientProvider; | ||
use crate::npm::common::maybe_auth_header_for_npm_registry; | ||
use crate::util::progress_bar::ProgressBar; | ||
|
@@ -138,8 +141,6 @@ impl TarballCache { | |
let tarball_cache = self.clone(); | ||
async move { | ||
let registry_url = tarball_cache.npmrc.get_registry_url(&package_nv.name); | ||
let registry_config = | ||
tarball_cache.npmrc.get_registry_config(&package_nv.name).clone(); | ||
let package_folder = | ||
tarball_cache.cache.package_folder_for_nv_and_url(&package_nv, registry_url); | ||
let should_use_cache = tarball_cache.cache.should_use_cache_for_package(&package_nv); | ||
|
@@ -161,14 +162,40 @@ impl TarballCache { | |
bail!("Tarball URL was empty."); | ||
} | ||
|
||
let maybe_auth_header = | ||
maybe_auth_header_for_npm_registry(®istry_config); | ||
// IMPORTANT: npm registries may specify tarball URLs at different URLS than the | ||
// registry, so we MUST get the auth for the tarball URL and not the registry URL. | ||
let tarball_uri = Url::parse(&dist.tarball)?; | ||
let maybe_registry_config = | ||
tarball_cache.npmrc.tarball_config(&tarball_uri); | ||
let maybe_auth_header = maybe_registry_config.and_then(|c| maybe_auth_header_for_npm_registry(c)); | ||
|
||
let guard = tarball_cache.progress_bar.update(&dist.tarball); | ||
let maybe_bytes = tarball_cache.http_client_provider | ||
let result = tarball_cache.http_client_provider | ||
.get_or_create()? | ||
.download_with_progress(&dist.tarball, maybe_auth_header, &guard) | ||
.await?; | ||
.download_with_progress(tarball_uri, maybe_auth_header, &guard) | ||
.await; | ||
let maybe_bytes = match result { | ||
Ok(maybe_bytes) => maybe_bytes, | ||
Err(DownloadError::BadResponse(err)) => { | ||
if err.status_code == StatusCode::UNAUTHORIZED | ||
&& maybe_registry_config.is_none() | ||
&& tarball_cache.npmrc.get_registry_config(&package_nv.name).auth_token.is_some() | ||
{ | ||
bail!( | ||
concat!( | ||
"No auth for tarball URI, but present for scoped registry.\n\n", | ||
"Tarball URI: {}\n", | ||
"Scope URI: {}\n\n", | ||
"More info here: https://github.com/npm/cli/wiki/%22No-auth-for-URI,-but-auth-present-for-scoped-registry%22" | ||
Comment on lines
+186
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, thanks! |
||
), | ||
dist.tarball, | ||
registry_url, | ||
) | ||
} | ||
return Err(err.into()) | ||
}, | ||
Err(err) => return Err(err.into()), | ||
}; | ||
match maybe_bytes { | ||
Some(bytes) => { | ||
let extraction_mode = if should_use_cache || !package_folder_exists { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/registry/npm-private/@denotest/tarballs-privateserver2/1.0.0/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'hi_private1'; |
4 changes: 4 additions & 0 deletions
4
tests/registry/npm-private/@denotest/tarballs-privateserver2/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@denotest/tarballs-privateserver2", | ||
"version": "1.0.0" | ||
} |
1 change: 1 addition & 0 deletions
1
tests/registry/npm-private2/@denotest/tarballs-privateserver2/1.0.0/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = () => 'hi_private2'; |
4 changes: 4 additions & 0 deletions
4
tests/registry/npm-private2/@denotest/tarballs-privateserver2/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@denotest/tarballs-privateserver2", | ||
"version": "1.0.0" | ||
} |
2 changes: 2 additions & 0 deletions
2
tests/registry/npm/@denotest/tarballs-privateserver2/1.0.0/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// this is a special package that the test server serves tarballs from the second private registry server | ||
module.exports = () => 'hi'; |
4 changes: 4 additions & 0 deletions
4
tests/registry/npm/@denotest/tarballs-privateserver2/1.0.0/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@denotest/tarballs-privateserver2", | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_authToken=private-reg-token | ||
@denotest2:registry=http://127.0.0.1:4262/ | ||
//127.0.0.1:4262/:_authToken=private-reg-token2 | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=private-reg-token | ||
@denotest2:registry=http://localhost:4262/ | ||
//localhost:4262/:_authToken=private-reg-token2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_authToken=private-reg-token | ||
@denotest2:registry=http://127.0.0.1:4262/ | ||
//127.0.0.1:4262/:_authToken=private-reg-token2 | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=private-reg-token | ||
@denotest2:registry=http://localhost:4262/ | ||
//localhost:4262/:_authToken=private-reg-token2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
@denotest:registry=http://localhost:4261/ | ||
; This configuration is wrong - the registry URL must | ||
; be exactly the same as registry configured for the scope, | ||
; not root url + scope name. | ||
//127.0.0.1:4261/denotest/:_authToken=invalid-token | ||
//localhost:4261/denotest/:_authToken=invalid-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag. | ||
Download http://127.0.0.1:4261/@denotest/basic | ||
error: Error getting response at http://127.0.0.1:4261/@denotest/basic for package "@denotest/basic": Bad response: 401 | ||
Download http://localhost:4261/@denotest/basic | ||
error: Error getting response at http://localhost:4261/@denotest/basic for package "@denotest/basic": Bad response: 401 | ||
[WILDCARD] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_authToken=invalid-token | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=invalid-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag. | ||
Download http://127.0.0.1:4261/@denotest/basic | ||
error: Error getting response at http://127.0.0.1:4261/@denotest/basic for package "@denotest/basic": Bad response: 401 | ||
Download http://localhost:4261/@denotest/basic | ||
error: Error getting response at http://localhost:4261/@denotest/basic for package "@denotest/basic": Bad response: 401 | ||
[WILDCARD] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_auth=ZGVubzpsYW5k | ||
@denotest2:registry=http://127.0.0.1:4262/ | ||
//127.0.0.1:4262/:_auth=ZGVubzpsYW5kMg== | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_auth=ZGVubzpsYW5k | ||
@denotest2:registry=http://localhost:4262/ | ||
//localhost:4262/:_auth=ZGVubzpsYW5kMg== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_authToken=private-reg-token | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=private-reg-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Download http://127.0.0.1:4261/@denotest/basic | ||
Download http://localhost:4261/@denotest/basic | ||
Download http://localhost:4261/@denotest/basic/1.0.0.tgz | ||
0 | ||
42 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@denotest:registry=http://127.0.0.1:4261/ | ||
//127.0.0.1:4261/:_authToken=private-reg-token | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=private-reg-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"tempDir": true, | ||
"tests": { | ||
"auth_success": { | ||
"cwd": "success", | ||
"args": "run --node-modules-dir -A main.js", | ||
"output": "success/main.out", | ||
"exitCode": 1 | ||
}, | ||
"auth_fail": { | ||
"cwd": "fail", | ||
"args": "run --node-modules-dir -A main.js", | ||
"output": "fail/main.out", | ||
"exitCode": 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@denotest:registry=http://localhost:4261/ | ||
//localhost:4261/:_authToken=private-reg-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import getValue from "@denotest/tarballs-privateserver2"; | ||
|
||
console.log(getValue()); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanup 👍