Git URL Credential Sanitizer Tests (src/sanitized_git_url_tests.rs)

openinterpreter · codex-rs/protocol/src/sanitized_git_url_tests.rs · rust · Apache-2.0
dev-tools, security, testing, lang:rust, tag:url-parsing

Unit tests verifying that SanitizedGitUrl strips usernames, passwords, and credentials from HTTPS, SSH, and SCP-style git remote URLs while rejecting malformed/unsafe inputs.

// Source: https://github.com/openinterpreter/openinterpreter | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
use super::SanitizedGitUrl;
use crate::protocol::GitInfo;
use pretty_assertions::assert_eq;
use serde::Deserialize;
use serde::de::value::Error;
use serde::de::value::StrDeserializer;
use serde_json::json;

/// HTTPS usernames and passwords must never survive construction.
#[test]
fn removes_https_username_and_password() {
    let url = SanitizedGitUrl::try_from("https://alice:secret@github.com/org/repo.git")
        .expect("parse remote URL");

    assert_eq!(url.as_str(), "https://github.com/org/repo.git");
}

/// Tokens placed in the username field are credentials too.

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key