Skip to content

Commit

Permalink
Add more tests against ss link parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbai committed Feb 2, 2024
1 parent 32211a2 commit 63634ce
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 48 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ytflow-app-util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ base64 = "0.21"
thiserror = "1"
cbor4ii = { version = "0.3", features = ["use_std", "serde1"] }
serde = { version = "1", features = ["derive"] }
serde_bytes = "0.11"
ytflow = { path = "../ytflow" }
4 changes: 3 additions & 1 deletion ytflow-app-util/src/proxy/protocol/shadowsocks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use serde_bytes::ByteBuf;

use ytflow::plugin::shadowsocks::SupportedCipher;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShadowsocksProxy {
pub cipher: SupportedCipher,
pub password: Vec<u8>,
pub password: ByteBuf,
}
10 changes: 6 additions & 4 deletions ytflow-app-util/src/share_link/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ pub static BASE64_ENGINE: base64::engine::GeneralPurpose = base64::engine::Gener
pub enum DecodeError {
#[error("invalid URL")]
InvalidUrl,
#[error("invalid URL or base64 encoding")]
#[error("invalid URL, UTF-8 or Base64 encoding")]
InvalidEncoding,
#[error("invalid value")]
InvalidValue,
#[error(r#""{0}" is required, but is missing"#)]
MissingInfo(&'static str),
#[error(r#"unknown value for field "{0}"#)]
UnknownValue(&'static str),
#[error("unknown URL scheme")]
UnknownScheme,
#[error(r#"extra parameter "{0}""#)]
Expand All @@ -33,7 +35,7 @@ pub type DecodeResult<T> = Result<T, DecodeError>;
pub(super) type QueryMap<'a> = BTreeMap<Cow<'a, str>, Cow<'a, str>>;

pub fn decode_share_link(link: &str) -> Result<Proxy, DecodeError> {
let url = url::Url::parse(link).map_err(|_| DecodeError::InvalidUrl)?;
let url = url::Url::parse(link.trim()).map_err(|_| DecodeError::InvalidUrl)?;
let mut queries = url.query_pairs().collect::<QueryMap>();

let proxy = match url.scheme() {
Expand Down
Loading

0 comments on commit 63634ce

Please sign in to comment.