use serde_json::Value;
use std::collections::BTreeSet;
use std::path::Path;
use vivacity_core::layout::{plugin_verdict, PluginVerdict};
const PACKAGE_VERSIONS: &str = "composer/package-versions-deprecated";
const OLD_LOCK: &str = "Your composer.lock was generated before the allow-plugins security feature was introduced and your composer.json does not define allow-plugins. Run \"composer update --lock\" locally and commit the updated composer.lock, then add an explicit allow-plugins section to composer.json. See https://getcomposer.org/allow-plugins";
#[derive(Debug, Default, PartialEq, Eq)]
pub(crate) struct Load {
pub(crate) warnings: Vec<String>,
pub(crate) refusal: Option<String>,
pub(crate) refused: Option<String>,
pub(crate) loaded: Vec<String>,
pub(crate) hand_over: Option<String>,
pub(crate) deprecation: Vec<String>,
pub(crate) deprecation_at: usize,
}
pub(crate) fn installers_deprecation(vendor_dir: &Path, normalized_version: &str) -> Vec<String> {
let line = match php_minor() {
_ if !normalized_version.starts_with("1.") => return Vec::new(),
Some(v) if v >= (8, 5) => 140,
Some(v) if v >= (8, 4) => 136,
_ => return Vec::new(),
};
let vendor = physical(vendor_dir);
vec![
format!(
"Deprecation Notice: Composer\\Installers\\Installer::__construct(): Implicitly marking parameter $filesystem as nullable is deprecated, the explicit nullable type must be used instead in {}/composer/installers/src/Composer/Installers/Installer.php:{line}",
vendor.display()
),
"More deprecation notices were hidden, run again with `-v` to show them.".to_owned(),
]
}
fn physical(path: &Path) -> std::path::PathBuf {
if let Ok(p) = std::fs::canonicalize(path) {
return p;
}
match (path.parent(), path.file_name()) {
(Some(parent), Some(name)) if parent != path => physical(parent).join(name),
_ => path.to_path_buf(),
}
}
fn php_minor() -> Option<(u32, u32)> {
let Ok(entries) = vivacity_resolver::platform::probe() else {
return None;
};
let version = entries
.iter()
.find(|e| e.get("name").and_then(Value::as_str) == Some("php"))
.and_then(|e| e.get("version").and_then(Value::as_str))
.unwrap_or_default();
let mut parts = version.split('.').map(|n| n.parse::<u32>().unwrap_or(0));
Some((parts.next().unwrap_or(0), parts.next().unwrap_or(0)))
}
pub(crate) type Rules = Option<Value>;
fn is_allowed(rules: &Rules, name: &str, global: bool, optional: bool) -> Result<bool, String> {
let Some(rules) = rules else {
return Err(OLD_LOCK.to_owned());
};
match plugin_verdict(Some(rules), name) {
PluginVerdict::Allowed => Ok(true),
PluginVerdict::Blocked => Ok(false),
PluginVerdict::Unlisted if name == PACKAGE_VERSIONS || optional => Ok(false),
PluginVerdict::Unlisted => Err(blocked_message(name, global)),
}
}
fn blocked_message(name: &str, global: bool) -> String {
let (installed, command) = if global {
(" (installed globally)", "global ")
} else {
("", "")
};
format!(
"{name}{installed} contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe.\n\
You can run \"composer {command}config --no-plugins allow-plugins.{name} [true|false]\" to enable it (true) or disable it explicitly and suppress this exception (false)\n\
See https://getcomposer.org/allow-plugins"
)
}
fn is_empty_config(v: Option<&Value>) -> bool {
match v {
None => true,
Some(Value::Object(m)) => m.is_empty(),
Some(Value::Array(a)) => a.is_empty(),
Some(_) => false,
}
}
fn lock_predates_allow_plugins(lock_path: &Path) -> bool {
let Some(lock) = vivacity_core::jsonfile::read(lock_path) else {
return false;
};
if lock.get("packages").is_none_or(Value::is_null) {
return false;
}
let api = lock
.get("plugin-api-version")
.and_then(Value::as_str)
.unwrap_or("1.1.0");
vivacity_resolver::phpver::version_compare(api, "2.2.0") == std::cmp::Ordering::Less
}
#[derive(Default)]
pub(crate) struct Globals {
pub(crate) allow_plugins: Option<Value>,
pub(crate) composer: Option<(std::path::PathBuf, Value)>,
}
impl Globals {
pub(crate) fn current() -> Globals {
Globals {
allow_plugins: vivacity_core::layout::global_allow_plugins(),
composer: crate::plugin_order::global_composer_dir().map(|dir| {
(
dir,
vivacity_core::layout::global_composer_allow_plugins()
.unwrap_or_else(|| Value::Array(Vec::new())),
)
}),
}
}
}
fn project_rules(manifest: &Value, globals: &Globals, lock_path: Option<&Path>) -> Rules {
let merged = vivacity_core::layout::merged_allow_plugins(
manifest.get("config").and_then(|c| c.get("allow-plugins")),
globals.allow_plugins.as_ref(),
);
if is_empty_config(merged.as_ref()) && lock_path.is_some_and(lock_predates_allow_plugins) {
return None;
}
Some(merged.unwrap_or_else(|| Value::Array(Vec::new())))
}
fn names_and_requires(p: &Value) -> (Vec<String>, Vec<String>) {
let keys = |field: &str| -> Vec<String> {
p.get(field)
.and_then(Value::as_object)
.map(|m| m.keys().map(|k| k.to_ascii_lowercase()).collect())
.unwrap_or_default()
};
let mut names: Vec<String> = p
.get("name")
.and_then(Value::as_str)
.map(|n| vec![n.to_ascii_lowercase()])
.unwrap_or_default();
names.extend(keys("provide"));
names.extend(keys("replace"));
(names, keys("require"))
}
fn required_names(installed: &[Value], manifest: &Value) -> BTreeSet<String> {
let mut wanted: BTreeSet<String> = ["require", "require-dev"]
.iter()
.filter_map(|f| manifest.get(*f).and_then(Value::as_object))
.flat_map(|m| m.keys().map(|k| k.to_ascii_lowercase()))
.collect();
let packages: Vec<(Vec<String>, Vec<String>)> =
installed.iter().map(names_and_requires).collect();
let mut taken = vec![false; packages.len()];
let mut out: BTreeSet<String> = BTreeSet::new();
loop {
let mut grew = false;
for (i, (names, requires)) in packages.iter().enumerate() {
if !taken[i] && names.iter().any(|n| wanted.contains(n)) {
taken[i] = true;
grew = true;
out.extend(names.first().cloned());
wanted.extend(requires.iter().cloned());
}
}
if !grew {
return out;
}
}
}
fn checked_before_judgement(p: &crate::plugin_order::InstalledPlugin) -> bool {
if !p.composer_plugin {
return false;
}
let Some(api) = &p.plugin_api else {
return true;
};
let accepts = vivacity_resolver::constraint::parse_constraints(api)
.is_ok_and(|c| c.constraint.matches_version("2.9.0.0") && c.pretty != PLUGIN_API_VERSION);
let old_flex = p.name == "symfony/flex"
&& p.version.chars().all(|c| c.is_ascii_digit() || c == '.')
&& vivacity_resolver::phpver::version_compare(&p.version, "1.9.8")
== std::cmp::Ordering::Less;
!accepts || old_flex
}
const PLUGIN_API_VERSION: &str = "2.9.0";
pub(crate) fn load(
manifest: &Value,
composer_dir: &Path,
lock_path: Option<&Path>,
globals: &Globals,
) -> Load {
let mut out = Load::default();
let rules = project_rules(manifest, globals, lock_path);
let installed = crate::plugin_order::installed_json_packages(composer_dir);
let required = required_names(&installed, manifest);
let mut judged: Vec<(crate::plugin_order::InstalledPlugin, bool)> = Vec::new();
for p in crate::plugin_order::sorted_plugins(&installed, composer_dir) {
judged.push((p, false));
}
if let Some((global_dir, _)) = &globals.composer {
let installed = crate::plugin_order::installed_json_packages(global_dir);
for p in crate::plugin_order::sorted_plugins(&installed, global_dir) {
judged.push((p, true));
}
}
let global_rules: Rules = globals.composer.as_ref().map(|(_, r)| r.clone());
for (p, global) in &judged {
let rules = if *global { &global_rules } else { &rules };
if !global && !required.contains(&p.name) {
match is_allowed(rules, &p.name, false, true) {
Ok(true) => {}
Ok(false) => {
out.warnings.push(format!(
"The \"{}\" plugin was not loaded as it is not listed in allow-plugins and is not required by the root package anymore.",
p.name
));
continue;
}
Err(e) => {
out.refusal = Some(e);
out.refused = Some(p.name.clone());
break;
}
}
}
let verdict = is_allowed(rules, &p.name, *global, p.optional);
if verdict != Ok(true) && checked_before_judgement(p) {
out.hand_over = Some(p.name.clone());
return out;
}
match verdict {
Err(e) => {
out.refusal = Some(e);
out.refused = Some(p.name.clone());
break;
}
Ok(true) if !global && p.present => {
if p.name == "composer/installers" {
out.deprecation = composer_dir
.parent()
.map(|vendor| installers_deprecation(vendor, &p.version))
.unwrap_or_default();
out.deprecation_at = out.warnings.len();
}
out.loaded.push(p.name.clone())
}
Ok(_) => {}
}
}
out
}
pub(crate) fn load_for(project: &Path, manifest: &Value) -> Load {
load(
manifest,
&composer_dir(project, manifest),
lock_path(project, manifest).as_deref(),
&Globals::current(),
)
}
fn composer_dir(project: &Path, manifest: &Value) -> std::path::PathBuf {
match vivacity_core::dirs::Dirs::resolve(manifest) {
Ok(d) => d.composer_dir(project),
Err(_) => project.join("vendor").join("composer"),
}
}
fn lock_path(project: &Path, manifest: &Value) -> Option<std::path::PathBuf> {
crate::config_lock_enabled(&manifest.to_string()).then(|| project.join("composer.lock"))
}
pub(crate) fn hand_over_issue(name: &str) -> vivacity_core::scope::ScopeIssue {
vivacity_core::scope::ScopeIssue::ResolutionPlugin(
name.to_owned(),
"is not allowed by config.allow-plugins and Composer checks its plugin API (or its version) before judging it (not emulated)".to_owned(),
)
}
fn root_without_superuser() -> bool {
let allowed =
std::env::var("COMPOSER_ALLOW_SUPERUSER").is_ok_and(|v| !v.is_empty() && v != "0");
#[cfg(unix)]
let root = {
use std::os::unix::fs::MetadataExt;
std::fs::metadata("/proc/self").is_ok_and(|m| m.uid() == 0)
};
#[cfg(not(unix))]
let root = false;
root && !allowed
}
pub(crate) fn root_issue() -> Option<vivacity_core::scope::ScopeIssue> {
root_without_superuser().then(|| {
vivacity_core::scope::ScopeIssue::Layout(
"running as root without COMPOSER_ALLOW_SUPERUSER, where Composer disables the plugins and would not judge them (not emulated)".to_owned(),
)
})
}
pub(crate) fn at_load(
project: &Path,
manifest: &Value,
edited: Option<&Value>,
plugins_enabled: bool,
no_fallback: bool,
) -> anyhow::Result<Option<i32>> {
if !plugins_enabled {
return Ok(None);
}
let load = load_for(project, manifest);
let issue = match (&load.hand_over, edited) {
(Some(name), _) => Some(hand_over_issue(name)),
(None, _) if deprecation_issue(&load).is_some() => deprecation_issue(&load),
(None, Some(edited)) if load.refusal.is_none() => second_load_issue(project, edited),
_ => None,
};
let issue = match issue {
Some(i) => Some(root_issue().unwrap_or(i)),
None if load.refusal.is_some() => root_issue(),
None => None,
};
if let Some(issue) = issue {
return crate::delegate_resolution(&[issue], no_fallback).map(Some);
}
if load.refusal.is_some() {
return refuse(project, manifest, &load, 2).map(Some);
}
hold_warnings(&load);
Ok(None)
}
pub(crate) fn hold_warnings(load: &Load) {
let mut lines = load.warnings.clone();
let at = load.deprecation_at.min(lines.len());
lines.splice(at..at, load.deprecation.iter().cloned());
vivacity_core::io::hold_after_factory(vivacity_core::io::Verbosity::Normal, &lines);
}
pub(crate) fn deprecation_issue(load: &Load) -> Option<vivacity_core::scope::ScopeIssue> {
let verbose = vivacity_core::io::level() >= vivacity_core::io::Verbosity::Verbose;
(!load.deprecation.is_empty() && (load.refusal.is_some() || verbose)).then(|| {
vivacity_core::scope::ScopeIssue::ResolutionPlugin(
"composer/installers".to_owned(),
"1.x prints PHP deprecations at load, here with a refusal or under -v (not emulated)"
.to_owned(),
)
})
}
pub(crate) fn activate_before_refusal(
project: &Path,
manifest: &Value,
load: &Load,
) -> anyhow::Result<()> {
if load
.loaded
.iter()
.any(|n| n == vivacity_core::yii2_composer::PLUGIN_NAME)
{
crate::no_install::activate_yii2_composer(project, manifest, true)?;
}
Ok(())
}
pub(crate) fn refuse(
project: &Path,
manifest: &Value,
load: &Load,
attempts: usize,
) -> anyhow::Result<i32> {
let Some(refusal) = &load.refusal else {
return Ok(0);
};
activate_before_refusal(project, manifest, load)?;
let factory = vivacity_core::io::factory_held();
hold_warnings(load);
vivacity_core::io::release_held();
for _ in 1..attempts {
for line in factory.iter().chain(&load.warnings) {
vivacity_core::say!("{line}");
}
}
vivacity_core::io::github_action_error(refusal);
for line in &factory {
vivacity_core::say!("{line}");
}
vivacity_core::say_always!("{refusal}");
Ok(1)
}
pub(crate) fn install_issue<'a>(
project: &Path,
load_manifest: &Value,
plugins: impl IntoIterator<Item = (&'a str, bool)>,
) -> Option<vivacity_core::scope::ScopeIssue> {
let issue = install_issue_with(project, load_manifest, &Globals::current(), plugins)?;
Some(root_issue().unwrap_or(issue))
}
fn install_issue_with<'a>(
project: &Path,
load_manifest: &Value,
globals: &Globals,
plugins: impl IntoIterator<Item = (&'a str, bool)>,
) -> Option<vivacity_core::scope::ScopeIssue> {
let rules = project_rules(
load_manifest,
globals,
lock_path(project, load_manifest).as_deref(),
);
for (name, optional) in plugins {
if let Err(e) = is_allowed(&rules, name, false, optional) {
let why = if e == OLD_LOCK {
"would be installed under a lock that predates config.allow-plugins (Composer stops in the middle of the installation; not emulated)"
} else {
"is not covered by config.allow-plugins and this run installs it (Composer stops in the middle of the installation; not emulated)"
};
return Some(vivacity_core::scope::ScopeIssue::ResolutionPlugin(
name.to_owned(),
why.to_owned(),
));
}
}
None
}
pub(crate) fn installed_by(
project: &Path,
manifest: &Value,
lock: &vivacity_core::lock::Lock,
with_dev: bool,
) -> Vec<(String, bool)> {
let installed = crate::installed_packages(project, manifest);
lock.wanted_packages(with_dev)
.filter(|p| {
matches!(
p.raw.get("type").and_then(Value::as_str),
Some("composer-plugin" | "composer-installer")
)
})
.filter(|p| !crate::installed_as_locked(&installed, p))
.map(|p| (p.name().to_ascii_lowercase(), optional(&p.raw)))
.collect()
}
pub(crate) fn optional(entry: &serde_json::Map<String, Value>) -> bool {
entry.get("extra").and_then(|e| e.get("plugin-optional")) == Some(&Value::Bool(true))
}
pub(crate) fn second_load_issue(
project: &Path,
edited: &Value,
) -> Option<vivacity_core::scope::ScopeIssue> {
let load = load_for(project, edited);
if let Some(name) = &load.hand_over {
return Some(hand_over_issue(name));
}
load.refused.as_ref().map(|name| {
vivacity_core::scope::ScopeIssue::ResolutionPlugin(
name.clone(),
"is not covered by config.allow-plugins and becomes required by this command (Composer refuses it after editing composer.json; not emulated)".to_owned(),
)
})
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
fn project(installed: Value, lock: Option<Value>) -> tempfile::TempDir {
let dir = tempfile::tempdir().unwrap();
let composer = dir.path().join("vendor/composer");
std::fs::create_dir_all(&composer).unwrap();
std::fs::write(
composer.join("installed.json"),
json!({ "packages": installed }).to_string(),
)
.unwrap();
if let Some(lock) = lock {
std::fs::write(dir.path().join("composer.lock"), lock.to_string()).unwrap();
}
dir
}
fn plugin(name: &str) -> Value {
json!({"name": name, "version": "1.0.0", "type": "composer-plugin",
"require": {"composer-plugin-api": "^2.0"}})
}
fn run(dir: &Path, manifest: Value) -> Load {
let mut l = load(
&manifest,
&dir.join("vendor/composer"),
Some(&dir.join("composer.lock")),
&Globals::default(),
);
l.loaded.clear();
l
}
#[test]
fn a_required_unlisted_plugin_stops_the_command() {
let d = project(json!([plugin("a/p")]), None);
let l = run(d.path(), json!({"require": {"a/p": "*"}}));
assert!(l.warnings.is_empty());
assert_eq!(
l.refusal.unwrap().lines().next(),
Some("a/p contains a Composer plugin which is blocked by your allow-plugins config. You may add it to the list if you consider it safe.")
);
}
#[test]
fn an_explicit_rule_decides() {
let d = project(json!([plugin("a/p")]), None);
for allow in [
json!({"a/*": true}),
json!({"a/p": false}),
json!(true),
json!(false),
] {
let l = run(
d.path(),
json!({"require": {"a/p": "*"}, "config": {"allow-plugins": allow}}),
);
assert_eq!(l, Load::default(), "{allow}");
}
}
#[test]
fn a_plugin_no_longer_required_is_skipped_with_a_warning() {
let d = project(json!([plugin("a/p")]), None);
for allow in [json!({}), json!({"a/p": false})] {
let l = run(d.path(), json!({"config": {"allow-plugins": allow}}));
assert_eq!(l.warnings.len(), 1);
assert!(l.refusal.is_none());
}
let l = run(
d.path(),
json!({"config": {"allow-plugins": {"a/p": true}}}),
);
assert_eq!(l, Load::default());
}
#[test]
fn required_through_a_package_replace_or_provide() {
let mut lib = json!({"name": "b/lib", "version": "1.0.0", "require": {"a/p": "*"},
"replace": {"c/old": "*"}});
let d = project(json!([plugin("a/p"), lib.clone()]), None);
assert!(run(d.path(), json!({"require": {"c/old": "*"}}))
.refusal
.is_some());
lib["require"] = json!({});
let d = project(json!([plugin("a/p"), lib]), None);
let l = run(d.path(), json!({"require": {"c/old": "*"}}));
assert_eq!(l.warnings.len(), 1);
assert!(l.refusal.is_none());
}
#[test]
fn optional_and_package_versions_are_skipped_silently() {
let mut p = plugin("a/p");
p["extra"] = json!({"plugin-optional": true});
let d = project(json!([p, plugin(PACKAGE_VERSIONS)]), None);
let l = run(
d.path(),
json!({"require": {"a/p": "*", PACKAGE_VERSIONS: "*"}}),
);
assert_eq!(l, Load::default());
}
#[test]
fn an_old_lock_without_rules_stops_at_the_first_plugin() {
let lock = json!({"packages": [], "plugin-api-version": "2.1.0"});
let d = project(json!([plugin(PACKAGE_VERSIONS)]), Some(lock));
for m in [
json!({"require": {PACKAGE_VERSIONS: "*"}}),
json!({"config": {"allow-plugins": {}}}),
] {
assert_eq!(run(d.path(), m).refusal.as_deref(), Some(OLD_LOCK));
}
let l = run(
d.path(),
json!({"config": {"allow-plugins": {"x/y": true}}}),
);
assert_eq!(l.warnings.len(), 1);
let d = project(
json!([plugin(PACKAGE_VERSIONS)]),
Some(json!({"packages": [], "plugin-api-version": "2.2.0"})),
);
assert_eq!(
run(d.path(), json!({"require": {PACKAGE_VERSIONS: "*"}})),
Load::default()
);
let d = project(
json!([plugin(PACKAGE_VERSIONS)]),
Some(json!({"packages": []})),
);
assert!(run(d.path(), json!({})).refusal.is_some());
}
#[test]
fn the_first_refusal_in_sorted_order_wins() {
let mut q = plugin("b/q");
q["require"]["a/p"] = json!("*");
let d = project(json!([q, plugin("a/p")]), None);
let l = run(d.path(), json!({"require": {"b/q": "*"}}));
assert!(l.refusal.unwrap().starts_with("a/p contains"));
}
#[test]
fn a_plugin_composer_checks_first_goes_to_composer() {
let mut no_api = plugin("a/p");
no_api["require"] = json!({});
let mut old_api = plugin("b/q");
old_api["require"] = json!({"composer-plugin-api": "^1.0"});
let mut bare_api = plugin("c/r");
bare_api["require"] = json!({"composer-plugin-api": "2.9.0"});
for p in [no_api, old_api, bare_api] {
let name = p["name"].as_str().unwrap().to_owned();
let d = project(json!([p]), None);
let l = run(d.path(), json!({"require": {name.clone(): "*"}}));
assert_eq!(l.hand_over.as_deref(), Some(name.as_str()));
let l = run(
d.path(),
json!({"require": {name.clone(): "*"}, "config": {"allow-plugins": {name: true}}}),
);
assert_eq!(l, Load::default());
}
let mut installer = plugin("d/s");
installer["type"] = json!("composer-installer");
installer["require"] = json!({});
let d = project(json!([installer]), None);
let l = run(d.path(), json!({"require": {"d/s": "*"}}));
assert!(l.hand_over.is_none() && l.refusal.is_some());
}
#[test]
fn a_gone_plugin_is_warned_about_before_any_api_check() {
let mut p = plugin("a/p");
p["require"] = json!({});
let d = project(json!([p]), None);
let l = run(d.path(), json!({}));
assert_eq!(l.warnings.len(), 1);
assert!(l.hand_over.is_none() && l.refusal.is_none());
}
#[test]
fn the_install_phase_judges_what_it_installs() {
let d = project(json!([]), None);
let m = json!({"config": {"allow-plugins": {"a/ok": true}}});
assert!(install_issue(
d.path(),
&m,
[("a/ok", false), ("b/opt", true), (PACKAGE_VERSIONS, false)]
)
.is_none());
assert!(
install_issue_with(d.path(), &m, &Globals::default(), [("c/blocked", false)])
.is_some_and(|i| i.to_string().starts_with("plugin c/blocked is not covered"))
);
let d = project(
json!([]),
Some(json!({"packages": [], "plugin-api-version": "2.1.0"})),
);
assert!(
install_issue_with(d.path(), &json!({}), &Globals::default(), [("b/opt", true)])
.is_some()
);
assert!(install_issue_with(d.path(), &m, &Globals::default(), [("b/opt", true)]).is_none());
}
#[test]
fn an_old_flex_is_skipped_by_composer_on_its_normalized_version() {
let mut flex = plugin("symfony/flex");
flex["version"] = json!("v1.9.7");
flex["require"] = json!({"composer-plugin-api": "^1.0|^2.0"});
let d = project(json!([flex.clone()]), None);
let l = run(d.path(), json!({"require": {"symfony/flex": "*"}}));
assert_eq!(l.hand_over.as_deref(), Some("symfony/flex"));
flex["version"] = json!("v1.9.8");
let d = project(json!([flex]), None);
let l = run(d.path(), json!({"require": {"symfony/flex": "*"}}));
assert!(l.hand_over.is_none() && l.refusal.is_some());
}
#[test]
fn a_global_plugin_is_judged_by_the_global_rules() {
let d = project(json!([]), None);
let home = tempfile::tempdir().unwrap();
std::fs::write(
home.path().join("installed.json"),
json!({"packages": [plugin("g/p")]}).to_string(),
)
.unwrap();
let globals = |rules: Value| Globals {
allow_plugins: None,
composer: Some((home.path().to_path_buf(), rules)),
};
let m = json!({"config": {"allow-plugins": {"g/p": true}}});
let l = load(
&m,
&d.path().join("vendor/composer"),
None,
&globals(json!([])),
);
assert!(l
.refusal
.unwrap()
.starts_with("g/p (installed globally) contains"));
let l = load(
&m,
&d.path().join("vendor/composer"),
None,
&globals(json!({"g/*": true})),
);
assert!(l.refusal.is_none() && l.warnings.is_empty() && l.loaded.is_empty());
let globals = Globals {
allow_plugins: Some(json!({"a/p": true})),
composer: None,
};
let d = project(json!([plugin("a/p")]), None);
let l = load(
&json!({"require": {"a/p": "*"}}),
&d.path().join("vendor/composer"),
None,
&globals,
);
assert_eq!(l.loaded, vec!["a/p".to_owned()]);
assert!(l.refusal.is_none());
}
#[test]
fn the_global_message() {
assert!(blocked_message("a/p", true)
.contains("a/p (installed globally) contains a Composer plugin which is blocked"));
assert!(blocked_message("a/p", true)
.contains("\"composer global config --no-plugins allow-plugins.a/p [true|false]\""));
}
}