forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ModuleSpecifier a type alias, not wrapper struct (denoland#9531)
- Loading branch information
Showing
34 changed files
with
594 additions
and
801 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -52,11 +52,10 @@ impl AuthTokens { | |
/// matching is case insensitive. | ||
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<AuthToken> { | ||
self.0.iter().find_map(|t| { | ||
let url = specifier.as_url(); | ||
let hostname = if let Some(port) = url.port() { | ||
format!("{}:{}", url.host_str()?, port) | ||
let hostname = if let Some(port) = specifier.port() { | ||
format!("{}:{}", specifier.host_str()?, port) | ||
} else { | ||
url.host_str()?.to_string() | ||
specifier.host_str()?.to_string() | ||
}; | ||
if hostname.to_lowercase().ends_with(&t.host) { | ||
Some(t.clone()) | ||
|
@@ -70,46 +69,40 @@ impl AuthTokens { | |
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use deno_core::resolve_url; | ||
|
||
#[test] | ||
fn test_auth_token() { | ||
let auth_tokens = AuthTokens::new(Some("[email protected]".to_string())); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer abc123" | ||
); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://www.deno.land/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://www.deno.land/x/mod.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer abc123".to_string() | ||
); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("http:https://127.0.0.1:8080/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("http:https://127.0.0.1:8080/x/mod.ts").unwrap(); | ||
assert_eq!(auth_tokens.get(&fixture), None); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land.example.com/x/mod.ts") | ||
.unwrap(); | ||
resolve_url("https://deno.land.example.com/x/mod.ts").unwrap(); | ||
assert_eq!(auth_tokens.get(&fixture), None); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land:8080/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://deno.land:8080/x/mod.ts").unwrap(); | ||
assert_eq!(auth_tokens.get(&fixture), None); | ||
} | ||
|
||
#[test] | ||
fn test_auth_tokens_multiple() { | ||
let auth_tokens = | ||
AuthTokens::new(Some("[email protected];[email protected]".to_string())); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer abc123".to_string() | ||
); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("http:https://example.com/a/file.ts").unwrap(); | ||
let fixture = resolve_url("http:https://example.com/a/file.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer def456".to_string() | ||
|
@@ -120,11 +113,9 @@ mod tests { | |
fn test_auth_tokens_port() { | ||
let auth_tokens = | ||
AuthTokens::new(Some("[email protected]:8080".to_string())); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
assert_eq!(auth_tokens.get(&fixture), None); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("http:https://deno.land:8080/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("http:https://deno.land:8080/x/mod.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer abc123".to_string() | ||
|
@@ -134,8 +125,7 @@ mod tests { | |
#[test] | ||
fn test_auth_tokens_contain_at() { | ||
let auth_tokens = AuthTokens::new(Some("abc@[email protected]".to_string())); | ||
let fixture = | ||
ModuleSpecifier::resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap(); | ||
assert_eq!( | ||
auth_tokens.get(&fixture).unwrap().to_string(), | ||
"Bearer abc@123".to_string() | ||
|
Oops, something went wrong.