diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:21:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-27 17:26:28 +0900 |
| commit | e98823e599eb375b30037cc714710e3309d927d1 (patch) | |
| tree | e1689ec164086798fc46aa6a58d1e914cf4873b2 /crates/shirabe/tests/util/http_downloader_test.rs | |
| parent | 20f620bdd0b5764ed2e9812dc0772f907b0d6f29 (diff) | |
| download | php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.gz php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.tar.zst php-shirabe-e98823e599eb375b30037cc714710e3309d927d1.zip | |
test: port Composer tests unblocked by mockall, add seams
Port 11 categories of previously-ignored Composer tests now reachable with
the mockall crate: DownloadManager, VCS/Perforce/File downloaders,
VersionSelector, PlatformRepository, Auditor, installer/FilesystemRepository,
RootPackageLoader, util auth/http, commands, and Cache.
Extract test seams additively on concrete structs as *Interface traits
(Runtime, HhvmDetector, VersionGuesser, RepositorySet, Perforce,
BinaryInstaller) plus mock-field seams (Cache, Filesystem); consumers take
trait objects. Mocks are defined locally in the test crates via
mockall::mock!, since automock-generated mocks are cfg(test)-gated and
invisible across the integration-test boundary.
dataProviders are ported in full; tests blocked by unported shims stay
#[ignore] with documented reasons rather than reduced or weakened.
Fix product bugs surfaced by the ports:
- util/github: use the exception code, not the HTTP status, for 401/403
- advisory: serialize empty audit maps as [] to match PHP json_encode
- repository/filesystem and downloader/file: fix RefCell double-borrow panics
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/util/http_downloader_test.rs')
| -rw-r--r-- | crates/shirabe/tests/util/http_downloader_test.rs | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/crates/shirabe/tests/util/http_downloader_test.rs b/crates/shirabe/tests/util/http_downloader_test.rs index 59807a9..078fd57 100644 --- a/crates/shirabe/tests/util/http_downloader_test.rs +++ b/crates/shirabe/tests/util/http_downloader_test.rs @@ -4,16 +4,59 @@ use std::cell::RefCell; use std::rc::Rc; use indexmap::IndexMap; +use shirabe::config::Config; +use shirabe::downloader::TransportException; use shirabe::io::IOInterface; use shirabe::io::buffer_io::BufferIO; +use shirabe::io::io_interface; +use shirabe::util::Platform; use shirabe::util::http_downloader::HttpDownloader; use shirabe_external_packages::symfony::console::output::output_interface::VERBOSITY_NORMAL; use shirabe_php_shim::{PHP_EOL, PhpMixed}; +use crate::config_stub::ConfigStubBuilder; +use crate::io_mock::{Expectation, get_io_mock}; + +// PHP performs a live HTTP get to assert the URL's user:pass is captured via +// setAuthentication. The credential capture happens in `add_job`, before any +// network I/O, so COMPOSER_DISABLE_NETWORK short-circuits the actual request +// (yielding a non-200 TransportException, as PHP's live 404 would) while the +// setAuthentication side effect still runs and is verified through the IOMock. #[test] -#[ignore = "asserts IOInterface mock ->expects()->method('setAuthentication')->with(...) and performs a live HTTP get; no mock infrastructure exists"] +#[serial_test::serial] fn test_capture_authentication_params_from_url() { - todo!() + let (io_mock, _io_guard) = get_io_mock(io_interface::NORMAL).unwrap(); + io_mock + .borrow_mut() + .expects( + vec![Expectation::auth( + "github.com", + "user", + Some("pass".to_string()), + )], + false, + ) + .unwrap(); + + // The PHP Config mock returns [] for github-domains/gitlab-domains. + let config: Rc<RefCell<Config>> = ConfigStubBuilder::new() + .with("github-domains", PhpMixed::Array(IndexMap::new())) + .with("gitlab-domains", PhpMixed::Array(IndexMap::new())) + .build_shared(); + + let io: Rc<RefCell<dyn IOInterface>> = io_mock.clone(); + + Platform::put_env("COMPOSER_DISABLE_NETWORK", "1"); + let mut fs = HttpDownloader::new(io, config, IndexMap::new(), false); + Platform::clear_env("COMPOSER_DISABLE_NETWORK"); + + if let Err(e) = fs.get( + "https://user:pass@github.com/composer/composer/404", + IndexMap::new(), + ) && let Some(te) = e.downcast_ref::<TransportException>() + { + assert_ne!(200, te.get_code()); + } } #[test] |
