refactor(bare): enhance security and performance optimizations
- Remove unnecessary sorting in advertise_refs for deterministic output - Add path traversal detection and validation in bare_dir construction - Implement symlink resolution checks to prevent security vulnerabilities - Refactor cache system with CRC validation and improved metrics - Integrate repo-specific cache invalidation using indexed keys - Add comprehensive unit tests for commit operations and diff functionality - Move configuration constants to centralized config module - Optimize string operations in disk cache random value generation - Enhance license detection algorithm with cleaner matching logic - Streamline argument processing in various git operations - Update dependencies including crc32fast and flate2 for performance - Add signal handling capability to tokio runtime configuration
This commit is contained in:
@@ -519,3 +519,221 @@ async fn test_oid_binary_encoding() {
|
||||
let hex_from_bytes: String = oid.value.iter().map(|b| format!("{b:02x}")).collect();
|
||||
assert_eq!(hex_from_bytes, oid.hex);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_count_commits_head() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.count_commits(CountCommitsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: String::new(),
|
||||
path: String::new(),
|
||||
since: String::new(),
|
||||
until: String::new(),
|
||||
}).unwrap();
|
||||
assert_eq!(resp.count, 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count_commits_with_revision() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.count_commits(CountCommitsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: "feature".into(),
|
||||
path: String::new(),
|
||||
since: String::new(),
|
||||
until: String::new(),
|
||||
}).unwrap();
|
||||
assert_eq!(resp.count, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count_commits_with_path() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.count_commits(CountCommitsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: "main".into(),
|
||||
path: "README.md".into(),
|
||||
since: String::new(),
|
||||
until: String::new(),
|
||||
}).unwrap();
|
||||
assert!(resp.count >= 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_count_diverging_commits() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.count_diverging_commits(CountDivergingCommitsRequest {
|
||||
repository: Some(hdr()),
|
||||
left: "feature".into(),
|
||||
right: "main".into(),
|
||||
}).unwrap();
|
||||
assert_eq!(resp.left_count, 0);
|
||||
assert_eq!(resp.right_count, 3);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_find_commit_by_oid() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let oid = common::get_main_oid(&gb);
|
||||
let commit = gb.find_commit(FindCommitRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: common::oid_selector(&oid),
|
||||
include_stats: false,
|
||||
}).unwrap();
|
||||
assert!(!commit.oid.as_ref().unwrap().hex.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_commit_by_revision() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let commit = gb.find_commit(FindCommitRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: common::rev_selector("main"),
|
||||
include_stats: false,
|
||||
}).unwrap();
|
||||
assert!(!commit.oid.as_ref().unwrap().hex.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_commit_default_head() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let commit = gb.find_commit(FindCommitRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: None,
|
||||
include_stats: false,
|
||||
}).unwrap();
|
||||
assert!(!commit.oid.as_ref().unwrap().hex.is_empty());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_list_commits_by_oid() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let oid = common::get_main_oid(&gb);
|
||||
let oid_bytes = gitks::oid::hex_to_bytes(&oid).unwrap();
|
||||
let resp = gb.list_commits_by_oid(ListCommitsByOidRequest {
|
||||
repository: Some(hdr()),
|
||||
oids: vec![oid_bytes],
|
||||
include_stats: false,
|
||||
}).unwrap();
|
||||
assert_eq!(resp.commits.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_commits_by_oid_empty() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.list_commits_by_oid(ListCommitsByOidRequest {
|
||||
repository: Some(hdr()),
|
||||
oids: vec![],
|
||||
include_stats: false,
|
||||
}).unwrap();
|
||||
assert!(resp.commits.is_empty());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_commits_by_message_basic() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.commits_by_message(CommitsByMessageRequest {
|
||||
repository: Some(hdr()),
|
||||
query: "initial".into(),
|
||||
revision: String::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
case_insensitive: false,
|
||||
}).unwrap();
|
||||
assert_eq!(resp.commits.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_commits_by_message_case_insensitive() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.commits_by_message(CommitsByMessageRequest {
|
||||
repository: Some(hdr()),
|
||||
query: "INITIAL".into(),
|
||||
revision: String::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
case_insensitive: true,
|
||||
}).unwrap();
|
||||
assert_eq!(resp.commits.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_commits_by_message_no_match() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.commits_by_message(CommitsByMessageRequest {
|
||||
repository: Some(hdr()),
|
||||
query: "zzzznonexistent".into(),
|
||||
revision: String::new(),
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
case_insensitive: false,
|
||||
}).unwrap();
|
||||
assert!(resp.commits.is_empty());
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_check_objects_exist() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let oid = common::get_main_oid(&gb);
|
||||
let resp = gb.check_objects_exist(CheckObjectsExistRequest {
|
||||
repository: Some(hdr()),
|
||||
revisions: vec![oid.clone(), "HEAD".into(), "nonexistent-branch".into()],
|
||||
}).unwrap();
|
||||
assert_eq!(resp.revisions.len(), 3);
|
||||
assert!(resp.revisions[0].exists);
|
||||
assert!(resp.revisions[1].exists);
|
||||
assert!(!resp.revisions[2].exists);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_get_commit_stats() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let oid = common::get_main_oid(&gb);
|
||||
let stats = gb.get_commit_stats(GetCommitStatsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: common::oid_selector(&oid),
|
||||
}).unwrap();
|
||||
assert!(stats.changed_files >= 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_commit_stats_default() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let stats = gb.get_commit_stats(GetCommitStatsRequest {
|
||||
repository: Some(hdr()),
|
||||
revision: None,
|
||||
}).unwrap();
|
||||
assert!(stats.changed_files >= 1);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_last_commit_for_path() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.last_commit_for_path(LastCommitForPathRequest {
|
||||
repository: Some(hdr()),
|
||||
path: "README.md".into(),
|
||||
revision: "main".into(),
|
||||
literal_pathspec: false,
|
||||
}).unwrap();
|
||||
assert!(resp.commit.is_some());
|
||||
assert_eq!(resp.path, "README.md");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_last_commit_for_path_nonexistent() {
|
||||
let (_dir, gb) = common::setup_bare_repo();
|
||||
let resp = gb.last_commit_for_path(LastCommitForPathRequest {
|
||||
repository: Some(hdr()),
|
||||
path: "nonexistent.txt".into(),
|
||||
revision: "main".into(),
|
||||
literal_pathspec: false,
|
||||
}).unwrap();
|
||||
assert!(resp.commit.is_none());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user