mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix: trim space around DENO_AUTH_TOKENS (#25147)
This commit is contained in:
parent
9bc7de9b13
commit
e7026c5ee8
1 changed files with 42 additions and 8 deletions
|
@ -123,19 +123,19 @@ impl AuthTokens {
|
||||||
pub fn new(maybe_tokens_str: Option<String>) -> Self {
|
pub fn new(maybe_tokens_str: Option<String>) -> Self {
|
||||||
let mut tokens = Vec::new();
|
let mut tokens = Vec::new();
|
||||||
if let Some(tokens_str) = maybe_tokens_str {
|
if let Some(tokens_str) = maybe_tokens_str {
|
||||||
for token_str in tokens_str.split(';') {
|
for token_str in tokens_str.trim().split(';') {
|
||||||
if token_str.contains('@') {
|
if token_str.contains('@') {
|
||||||
let pair: Vec<&str> = token_str.rsplitn(2, '@').collect();
|
let mut iter = token_str.rsplitn(2, '@');
|
||||||
let token = pair[1];
|
let host = AuthDomain::from(iter.next().unwrap());
|
||||||
let host = AuthDomain::from(pair[0]);
|
let token = iter.next().unwrap();
|
||||||
if token.contains(':') {
|
if token.contains(':') {
|
||||||
let pair: Vec<&str> = token.rsplitn(2, ':').collect();
|
let mut iter = token.rsplitn(2, ':');
|
||||||
let username = pair[1].to_string();
|
let password = iter.next().unwrap().to_owned();
|
||||||
let password = pair[0].to_string();
|
let username = iter.next().unwrap().to_owned();
|
||||||
tokens.push(AuthToken {
|
tokens.push(AuthToken {
|
||||||
host,
|
host,
|
||||||
token: AuthTokenData::Basic { username, password },
|
token: AuthTokenData::Basic { username, password },
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
tokens.push(AuthToken {
|
tokens.push(AuthToken {
|
||||||
host,
|
host,
|
||||||
|
@ -211,6 +211,40 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_auth_tokens_space() {
|
||||||
|
let auth_tokens = AuthTokens::new(Some(
|
||||||
|
" abc123@deno.land;def456@example.com\t".to_string(),
|
||||||
|
));
|
||||||
|
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 = resolve_url("http://example.com/a/file.ts").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||||
|
"Bearer def456".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_auth_tokens_newline() {
|
||||||
|
let auth_tokens = AuthTokens::new(Some(
|
||||||
|
"\nabc123@deno.land;def456@example.com\n".to_string(),
|
||||||
|
));
|
||||||
|
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 = resolve_url("http://example.com/a/file.ts").unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||||
|
"Bearer def456".to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_auth_tokens_port() {
|
fn test_auth_tokens_port() {
|
||||||
let auth_tokens =
|
let auth_tokens =
|
||||||
|
|
Loading…
Reference in a new issue