Skip to content

Commit

Permalink
Misc output changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Feb 13, 2025
1 parent 6931d1e commit 0bd2f0d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion e2e/tests-dfx/assetscanister.bash
Original file line number Diff line number Diff line change
Expand Up @@ -1444,7 +1444,7 @@ EOF

assert_command dfx deploy
assert_contains "This project uses the default security policy for some assets."
assert_contains "Unhardened assets: all"
assert_not_contains "Unhardened assets:"
assert_command curl --fail --head "http://localhost:$PORT/thing.json?canisterId=$ID"
assert_match "content-security-policy"
assert_match "permissions-policy"
Expand Down
11 changes: 7 additions & 4 deletions src/canisters/frontend/ic-asset/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,14 @@ pub(crate) fn gather_asset_descriptors(
.filter(|asset| asset.config.warn_about_standard_security_policy())
.collect_vec();
if !standard_policy_assets.is_empty() {
warn!(logger, "This project uses the default security policy for some assets. While it is set up to work with many applications, it is recommended to further harden the policy to increase security against attacks like XSS.");
warn!(logger, "To get started, have a look at 'dfx info canister-security-policy'. It shows the default security policy along with suggestions on how to improve it.");
if standard_policy_assets.len() == asset_descriptors.len() {
warn!(logger, "Unhardened assets: all");
let qnt = if standard_policy_assets.len() == asset_descriptors.len() {
"all"
} else {
"some"
};
warn!(logger, "This project uses the default security policy for {qnt} assets. While it is set up to work with many applications, it is recommended to further harden the policy to increase security against attacks like XSS.");
warn!(logger, "To get started, have a look at 'dfx info canister-security-policy'. It shows the default security policy along with suggestions on how to improve it.");
if standard_policy_assets.len() != asset_descriptors.len() {
warn!(logger, "Unhardened assets:");
for asset in &standard_policy_assets {
warn!(logger, " - {}", asset.key);
Expand Down
11 changes: 6 additions & 5 deletions src/dfx/src/commands/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,14 @@ fn display_urls(env: &dyn Environment) -> DfxResult {
let green = Style::new().green();
if !frontend_urls.is_empty() {
info!(log, " Frontend canister via browser:");
for (name, (url1, url2)) in frontend_urls {
if let Some(url2) = url2 {
for (name, (query_url, subdomain_url)) in frontend_urls {
if let Some(subdomain_url) = subdomain_url {
info!(log, " {}:", name);
info!(log, " - {}", green.apply_to(url1));
info!(log, " - {}", green.apply_to(url2));
#[rustfmt::skip]
info!(log, " - {} (Recommended)", green.apply_to(subdomain_url));
info!(log, " - {} (Legacy)", green.apply_to(query_url));
} else {
info!(log, " {}: {}", name, green.apply_to(url1));
info!(log, " {}: {}", name, green.apply_to(query_url));
}
}
}
Expand Down
23 changes: 20 additions & 3 deletions src/dfx/src/lib/builders/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ use candid::Principal as CanisterId;
use console::style;
use dfx_core::config::model::network_descriptor::NetworkDescriptor;
use fn_error_context::context;
use itertools::Itertools;
use slog::{debug, info, o, Logger};
use std::fs;
use std::io::ErrorKind;
use std::path::Path;
use std::process::{Command, Stdio};

Expand Down Expand Up @@ -232,9 +234,24 @@ fn build_frontend(
.stderr(Stdio::piped());
debug!(logger, "Running {cmd:?}...");

let output = cmd
.output()
.with_context(|| format!("Error executing {cmd:#?}"))?;
let res = cmd.output();
let output = match res {
Ok(o) => o,
Err(e) => {
let root_err = if e.kind() == ErrorKind::NotFound {
anyhow!("npm was not found. (Is it installed?)")
} else {
e.into()
};
return Err(root_err).context(format!(
"Error executing \"{}\" {}",
shell_words::quote(&cmd.get_program().to_string_lossy()),
cmd.get_args()
.map(|a| shell_words::quote(&a.to_string_lossy()).into_owned())
.format(" ")
));
}
};
if !output.status.success() {
return Err(DfxError::new(BuildError::CommandError(
format!("{cmd:?}",),
Expand Down

0 comments on commit 0bd2f0d

Please sign in to comment.