mirror of
https://github.com/librespot-org/librespot.git
synced 2025-10-03 17:59:24 +02:00
OAuth: Allow non-loopback addresses (#1514)
This commit is contained in:
parent
9456a02afa
commit
03bcdc6bda
2 changed files with 17 additions and 16 deletions
|
@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- [playback] Changed type alias `MixerFn` to return `Result<Arc<dyn Mixer>, Error>` instead of `Arc<dyn Mixer>` (breaking)
|
- [playback] Changed type alias `MixerFn` to return `Result<Arc<dyn Mixer>, Error>` instead of `Arc<dyn Mixer>` (breaking)
|
||||||
- [playback] Optimize audio conversion to always dither at 16-bit level, and improve performance
|
- [playback] Optimize audio conversion to always dither at 16-bit level, and improve performance
|
||||||
- [playback] Normalizer maintains better stereo imaging, while also being faster
|
- [playback] Normalizer maintains better stereo imaging, while also being faster
|
||||||
|
- [oauth] Remove loopback address requirement from `redirect_uri` when spawning callback handling server versus using stdin.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
|
|
@ -187,24 +187,17 @@ fn get_authcode_listener(
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the specified `redirect_uri` is HTTP, loopback, and contains a port,
|
// If the specified `redirect_uri` is HTTP and contains a port,
|
||||||
// then the corresponding socket address is returned.
|
// then the corresponding socket address is returned.
|
||||||
fn get_socket_address(redirect_uri: &str) -> Option<SocketAddr> {
|
fn get_socket_address(redirect_uri: &str) -> Option<SocketAddr> {
|
||||||
#![warn(missing_docs)]
|
|
||||||
let url = match Url::parse(redirect_uri) {
|
let url = match Url::parse(redirect_uri) {
|
||||||
Ok(u) if u.scheme() == "http" && u.port().is_some() => u,
|
Ok(u) if u.scheme() == "http" && u.port().is_some() => u,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let socket_addr = match url.socket_addrs(|| None) {
|
match url.socket_addrs(|| None) {
|
||||||
Ok(mut addrs) => addrs.pop(),
|
Ok(mut addrs) => addrs.pop(),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
|
||||||
if let Some(s) = socket_addr {
|
|
||||||
if s.ip().is_loopback() {
|
|
||||||
return socket_addr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Struct that handle obtaining and refreshing access tokens.
|
/// Struct that handle obtaining and refreshing access tokens.
|
||||||
|
@ -509,21 +502,21 @@ mod test {
|
||||||
assert_eq!(get_socket_address("http://127.0.0.1/foo"), None);
|
assert_eq!(get_socket_address("http://127.0.0.1/foo"), None);
|
||||||
assert_eq!(get_socket_address("http://127.0.0.1:/foo"), None);
|
assert_eq!(get_socket_address("http://127.0.0.1:/foo"), None);
|
||||||
assert_eq!(get_socket_address("http://[::1]/foo"), None);
|
assert_eq!(get_socket_address("http://[::1]/foo"), None);
|
||||||
// Not localhost
|
|
||||||
assert_eq!(get_socket_address("http://56.0.0.1:1234/foo"), None);
|
|
||||||
assert_eq!(
|
|
||||||
get_socket_address("http://[3ffe:2a00:100:7031::1]:1234/foo"),
|
|
||||||
None
|
|
||||||
);
|
|
||||||
// Not http
|
// Not http
|
||||||
assert_eq!(get_socket_address("https://127.0.0.1/foo"), None);
|
assert_eq!(get_socket_address("https://127.0.0.1/foo"), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn get_socket_address_localhost() {
|
fn get_socket_address_some() {
|
||||||
let localhost_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1234);
|
let localhost_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1234);
|
||||||
let localhost_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8888);
|
let localhost_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8888);
|
||||||
|
let addr_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 1234);
|
||||||
|
let addr_v6 = SocketAddr::new(
|
||||||
|
IpAddr::V6(Ipv6Addr::new(0x2001, 0x4860, 0x4860, 0, 0, 0, 0, 0x8888)),
|
||||||
|
8888,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Loopback addresses
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
get_socket_address("http://127.0.0.1:1234/foo"),
|
get_socket_address("http://127.0.0.1:1234/foo"),
|
||||||
Some(localhost_v4)
|
Some(localhost_v4)
|
||||||
|
@ -536,5 +529,12 @@ mod test {
|
||||||
get_socket_address("http://[::1]:8888/foo"),
|
get_socket_address("http://[::1]:8888/foo"),
|
||||||
Some(localhost_v6)
|
Some(localhost_v6)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Non-loopback addresses
|
||||||
|
assert_eq!(get_socket_address("http://8.8.8.8:1234/foo"), Some(addr_v4));
|
||||||
|
assert_eq!(
|
||||||
|
get_socket_address("http://[2001:4860:4860::8888]:8888/foo"),
|
||||||
|
Some(addr_v6)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue