From 4a6e21adad13580d6ba7c4199471a8b2dd09ab51 Mon Sep 17 00:00:00 2001 From: mraszyk <31483726+mraszyk@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:30:29 +0100 Subject: [PATCH 1/3] fix: default effective canister id for PocketIC (#4059) --- e2e/tests-dfx/start.bash | 12 ++++++++++++ src/dfx/src/actors/pocketic.rs | 19 +++---------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/e2e/tests-dfx/start.bash b/e2e/tests-dfx/start.bash index 417a84f180..9874305fd1 100644 --- a/e2e/tests-dfx/start.bash +++ b/e2e/tests-dfx/start.bash @@ -29,6 +29,18 @@ teardown() { dfx_stop } +@test "start and stop with specified canister id" { + dfx_start + + dfx_new hello + dfx deploy hello_backend --specified-id gt2iw-kiaaa-aaad7-qaaaa-cai + + dfx_stop + + dfx_start + dfx_stop +} + @test "start and stop with different options" { [[ "$USE_POCKETIC" ]] && skip "skipped for pocketic: clean required" dfx_start --artificial-delay 101 diff --git a/src/dfx/src/actors/pocketic.rs b/src/dfx/src/actors/pocketic.rs index c143978291..6d27d1034e 100644 --- a/src/dfx/src/actors/pocketic.rs +++ b/src/dfx/src/actors/pocketic.rs @@ -385,25 +385,12 @@ async fn initialize_pocketic( instance_id, topology, } => { - let subnets = match replica_config.subnet_type { - ReplicaSubnetType::Application => topology.get_app_subnets(), - ReplicaSubnetType::System => topology.get_system_subnets(), - ReplicaSubnetType::VerifiedApplication => topology.get_verified_app_subnets(), - }; - if subnets.len() != 1 { - return Err(anyhow!("Internal error: PocketIC topology contains multiple subnets of the same subnet kind.")); - } - let subnet_id = subnets[0]; - let subnet_config = topology.subnet_configs.get(&subnet_id).ok_or(anyhow!( - "Internal error: subnet id {} not found in PocketIC topology", - subnet_id - ))?; - let effective_canister_id = - Principal::from_slice(&subnet_config.canister_ranges[0].start.canister_id); + let default_effective_canister_id: Principal = + topology.default_effective_canister_id.into(); let effective_config = CachedConfig::pocketic( replica_config, replica_rev().into(), - Some(effective_canister_id), + Some(default_effective_canister_id), ); save_json_file(effective_config_path, &effective_config)?; instance_id From 90d18e9065ff7ac125f1feee91c9bea54bc4d0d8 Mon Sep 17 00:00:00 2001 From: Andre Popovitch Date: Wed, 8 Jan 2025 11:13:04 -0600 Subject: [PATCH 2/3] chore: update `keyring` to version 3 (#4057) --- Cargo.lock | 528 ++++++---------------- Cargo.toml | 8 +- src/dfx-core/src/error/keyring.rs | 3 + src/dfx-core/src/identity/keyring_mock.rs | 20 +- 4 files changed, 172 insertions(+), 387 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 34d63ca273..aec2be11f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -120,18 +120,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "aes" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8b47f52ea9bae42228d07ec09eb676433d7c4ed1ebdf0f1d1c29ed446f1ab8" -dependencies = [ - "cfg-if", - "cipher 0.3.0", - "cpufeatures", - "opaque-debug", -] - [[package]] name = "aes" version = "0.8.4" @@ -139,7 +127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" dependencies = [ "cfg-if", - "cipher 0.4.4", + "cipher", "cpufeatures", ] @@ -150,8 +138,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" dependencies = [ "aead", - "aes 0.8.4", - "cipher 0.4.4", + "aes", + "cipher", "ctr", "ghash", "subtle", @@ -368,35 +356,6 @@ dependencies = [ "futures-core", ] -[[package]] -name = "async-io" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" -dependencies = [ - "async-lock 2.8.0", - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-lite", - "log", - "parking", - "polling", - "rustix 0.37.27", - "slab", - "socket2 0.4.10", - "waker-fn", -] - -[[package]] -name = "async-lock" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" -dependencies = [ - "event-listener 2.5.3", -] - [[package]] name = "async-lock" version = "3.4.0" @@ -556,7 +515,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b30ed1d6f8437a487a266c8293aeb95b61a23261273e3e02912cdb8b68bf798b" dependencies = [ "bs58", - "hmac 0.12.1", + "hmac", "k256 0.11.6", "once_cell", "pbkdf2", @@ -633,22 +592,6 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-modes" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cb03d1bed155d89dce0f845b7899b18a9a163e148fd004e1c28421a783e2d8e" -dependencies = [ - "block-padding", - "cipher 0.3.0", -] - -[[package]] -name = "block-padding" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" - [[package]] name = "borsh" version = "1.5.3" @@ -666,7 +609,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2593a3b8b938bd68373196c9832f516be11fa487ef4ae745eb282e6a56a7244" dependencies = [ "once_cell", - "proc-macro-crate 3.2.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.90", @@ -968,15 +911,6 @@ dependencies = [ "envmnt", ] -[[package]] -name = "cipher" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" -dependencies = [ - "generic-array", -] - [[package]] name = "cipher" version = "0.4.4" @@ -1311,23 +1245,13 @@ dependencies = [ "typenum", ] -[[package]] -name = "crypto-mac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25fab6889090c8133f3deb8f73ba3c65a7f456f66436fc012a1b1e272b1e103e" -dependencies = [ - "generic-array", - "subtle", -] - [[package]] name = "ctr" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" dependencies = [ - "cipher 0.4.4", + "cipher", ] [[package]] @@ -1503,6 +1427,31 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "dbus" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" +dependencies = [ + "libc", + "libdbus-sys", + "winapi", +] + +[[package]] +name = "dbus-secret-service" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42a16374481d92aed73ae45b1f120207d8e71d24fb89f357fadbd8f946fd84b" +dependencies = [ + "dbus", + "futures-util", + "num", + "once_cell", + "openssl", + "rand", +] + [[package]] name = "delay" version = "0.3.1" @@ -1654,7 +1603,7 @@ dependencies = [ "thiserror 1.0.69", "time", "tokio", - "toml 0.7.8", + "toml", "url", "walkdir", "walrus", @@ -1956,27 +1905,6 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" -[[package]] -name = "enumflags2" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0" -dependencies = [ - "enumflags2_derive", - "serde", -] - -[[package]] -name = "enumflags2_derive" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "env_logger" version = "0.10.2" @@ -2068,15 +1996,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" -[[package]] -name = "fastrand" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] - [[package]] name = "fastrand" version = "2.3.0" @@ -2155,6 +2074,21 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2238,21 +2172,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" -[[package]] -name = "futures-lite" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" -dependencies = [ - "fastrand 1.9.0", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.31" @@ -2494,12 +2413,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "hermit-abi" version = "0.4.0" @@ -2515,26 +2428,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hkdf" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01706d578d5c281058480e673ae4086a9f4710d8df1ad80a5b03e39ece5f886b" -dependencies = [ - "digest 0.9.0", - "hmac 0.11.0", -] - -[[package]] -name = "hmac" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" -dependencies = [ - "crypto-mac", - "digest 0.9.0", -] - [[package]] name = "hmac" version = "0.12.1" @@ -2727,7 +2620,7 @@ dependencies = [ "http-body 1.0.1", "hyper 1.5.1", "pin-project-lite", - "socket2 0.5.8", + "socket2", "tokio", "tower-service", "tracing", @@ -2763,7 +2656,7 @@ source = "git+https://github.com/dfinity/agent-rs?rev=0a51f2a65dde7d9e1790c378bd dependencies = [ "arc-swap", "async-channel", - "async-lock 3.4.0", + "async-lock", "async-trait", "async-watch", "backoff", @@ -3767,17 +3660,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "io-lifetimes" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" -dependencies = [ - "hermit-abi 0.3.9", - "libc", - "windows-sys 0.48.0", -] - [[package]] name = "ipnet" version = "2.10.1" @@ -3790,7 +3672,7 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" dependencies = [ - "hermit-abi 0.4.0", + "hermit-abi", "libc", "windows-sys 0.52.0", ] @@ -3938,14 +3820,18 @@ dependencies = [ [[package]] name = "keyring" -version = "1.2.1" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba264b266563c1363dcce004776cbf198d7422a4262f77f4ca285bf26ae30955" +checksum = "2f8fe839464d4e4b37d756d7e910063696af79a7e877282cb1825e4ec5f10833" dependencies = [ "byteorder", - "secret-service", + "dbus-secret-service", + "linux-keyutils", + "log", + "openssl", "security-framework 2.11.1", - "winapi", + "security-framework 3.0.1", + "windows-sys 0.59.0", ] [[package]] @@ -3997,6 +3883,16 @@ version = "0.2.168" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aaeb2981e0606ca11d79718f8bb01164f1d6ed75080182d3abf017e6d244b6d" +[[package]] +name = "libdbus-sys" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" +dependencies = [ + "cc", + "pkg-config", +] + [[package]] name = "libflate" version = "1.4.0" @@ -4088,10 +3984,14 @@ dependencies = [ ] [[package]] -name = "linux-raw-sys" -version = "0.3.8" +name = "linux-keyutils" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "761e49ec5fd8a5a463f9b84e877c373d888935b71c6be78f3767fe2ae6bed18e" +dependencies = [ + "bitflags 2.6.0", + "libc", +] [[package]] name = "linux-raw-sys" @@ -4249,35 +4149,12 @@ dependencies = [ "similar", ] -[[package]] -name = "nb-connect" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1bb540dc6ef51cfe1916ec038ce7a620daf3a111e2502d745197cd53d6bca15" -dependencies = [ - "libc", - "socket2 0.4.10", -] - [[package]] name = "new_debug_unreachable" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" -[[package]] -name = "nix" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" -dependencies = [ - "bitflags 1.3.2", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.24.3" @@ -4470,12 +4347,60 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "openssl" +version = "0.10.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.90", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "300.4.1+3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "faa4eac4138c62414b5622d1b31c5c304f34b406b013c079c2bbc652fdd6678c" +dependencies = [ + "cc", +] + +[[package]] +name = "openssl-sys" +version = "0.9.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45abf306cbf99debc8195b66b7346498d7b10c210de50418b5ccd7ceba08c741" +dependencies = [ + "cc", + "libc", + "openssl-src", + "pkg-config", + "vcpkg", +] + [[package]] name = "os_str_bytes" version = "6.6.1" @@ -4799,6 +4724,12 @@ dependencies = [ "spki 0.7.3", ] +[[package]] +name = "pkg-config" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" + [[package]] name = "pocket-ic" version = "6.0.0" @@ -4828,22 +4759,6 @@ dependencies = [ "wslpath", ] -[[package]] -name = "polling" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" -dependencies = [ - "autocfg", - "bitflags 1.3.2", - "cfg-if", - "concurrent-queue", - "libc", - "log", - "pin-project-lite", - "windows-sys 0.48.0", -] - [[package]] name = "polyval" version = "0.6.2" @@ -4919,25 +4834,6 @@ dependencies = [ "elliptic-curve 0.13.8", ] -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml 0.5.11", -] - -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit 0.19.15", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -5046,7 +4942,7 @@ dependencies = [ "quinn-udp", "rustc-hash 2.1.0", "rustls 0.23.19", - "socket2 0.5.8", + "socket2", "thiserror 2.0.6", "tokio", "tracing", @@ -5081,7 +4977,7 @@ dependencies = [ "cfg_aliases", "libc", "once_cell", - "socket2 0.5.8", + "socket2", "tracing", "windows-sys 0.59.0", ] @@ -5304,7 +5200,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" dependencies = [ "crypto-bigint 0.4.9", - "hmac 0.12.1", + "hmac", "zeroize", ] @@ -5314,7 +5210,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ - "hmac 0.12.1", + "hmac", "subtle", ] @@ -5426,20 +5322,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" -[[package]] -name = "rustix" -version = "0.37.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" -dependencies = [ - "bitflags 1.3.2", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys 0.3.8", - "windows-sys 0.48.0", -] - [[package]] name = "rustix" version = "0.38.42" @@ -5449,7 +5331,7 @@ dependencies = [ "bitflags 2.6.0", "errno", "libc", - "linux-raw-sys 0.4.14", + "linux-raw-sys", "windows-sys 0.59.0", ] @@ -5595,12 +5477,6 @@ dependencies = [ "syn 2.0.90", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scoped_threadpool" version = "0.1.9" @@ -5663,26 +5539,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "secret-service" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1da5c423b8783185fd3fecd1c8796c267d2c089d894ce5a93c280a5d3f780a2" -dependencies = [ - "aes 0.7.5", - "block-modes", - "hkdf", - "lazy_static", - "num", - "rand", - "serde", - "sha2 0.9.9", - "zbus", - "zbus_macros", - "zvariant", - "zvariant_derive", -] - [[package]] name = "security-framework" version = "2.11.1" @@ -6042,16 +5898,6 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" -[[package]] -name = "socket2" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "socket2" version = "0.5.8" @@ -6113,12 +5959,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "stop-token" version = "0.7.0" @@ -6328,9 +6168,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" dependencies = [ "cfg-if", - "fastrand 2.3.0", + "fastrand", "once_cell", - "rustix 0.38.42", + "rustix", "windows-sys 0.59.0", ] @@ -6360,7 +6200,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5352447f921fda68cf61b4101566c0bdb5104eff6804d0678e5227580ab6a4e9" dependencies = [ - "rustix 0.38.42", + "rustix", "windows-sys 0.59.0", ] @@ -6460,7 +6300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62cc94d358b5a1e84a5cb9109f559aa3c4d634d2b1b4de3d0fa4adc7c78e2861" dependencies = [ "anyhow", - "hmac 0.12.1", + "hmac", "once_cell", "pbkdf2", "rand", @@ -6519,7 +6359,7 @@ dependencies = [ "parking_lot 0.12.3", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.8", + "socket2", "tokio-macros", "windows-sys 0.52.0", ] @@ -6580,15 +6420,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.5.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - [[package]] name = "toml" version = "0.7.8" @@ -6872,6 +6703,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" @@ -6887,12 +6724,6 @@ dependencies = [ "libc", ] -[[package]] -name = "waker-fn" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" - [[package]] name = "walkdir" version = "2.5.0" @@ -7143,7 +6974,7 @@ dependencies = [ "either", "home", "once_cell", - "rustix 0.38.42", + "rustix", ] [[package]] @@ -7168,7 +6999,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -7422,8 +7253,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" dependencies = [ "libc", - "linux-raw-sys 0.4.14", - "rustix 0.38.42", + "linux-raw-sys", + "rustix", ] [[package]] @@ -7456,41 +7287,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zbus" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cbeb2291cd7267a94489b71376eda33496c1b9881adf6b36f26cc2779f3fc49" -dependencies = [ - "async-io", - "byteorder", - "derivative", - "enumflags2", - "fastrand 1.9.0", - "futures", - "nb-connect", - "nix 0.22.3", - "once_cell", - "polling", - "scoped-tls", - "serde", - "serde_repr", - "zbus_macros", - "zvariant", -] - -[[package]] -name = "zbus_macros" -version = "1.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa3959a7847cf95e3d51e312856617c5b1b77191176c65a79a5f14d778bbe0a6" -dependencies = [ - "proc-macro-crate 0.1.5", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "zerocopy" version = "0.7.35" @@ -7574,29 +7370,3 @@ dependencies = [ "quote", "syn 2.0.90", ] - -[[package]] -name = "zvariant" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68c7b55f2074489b7e8e07d2d0a6ee6b4f233867a653c664d8020ba53692525" -dependencies = [ - "byteorder", - "enumflags2", - "libc", - "serde", - "static_assertions", - "zvariant_derive", -] - -[[package]] -name = "zvariant_derive" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4ca5e22593eb4212382d60d26350065bf2a02c34b85bc850474a74b589a3de9" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2", - "quote", - "syn 1.0.109", -] diff --git a/Cargo.toml b/Cargo.toml index 58bbde2814..6492e7fc50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,13 @@ handlebars = "4.3.3" hex = "0.4.3" humantime = "2.1.0" itertools = "0.10.3" -keyring = "1.2.0" +keyring = { version = "3", features = [ + "apple-native", + "windows-native", + "linux-native", + "sync-secret-service", + "vendored", +] } lazy_static = "1.4.0" mime = "0.3.16" mime_guess = "2.0.4" diff --git a/src/dfx-core/src/error/keyring.rs b/src/dfx-core/src/error/keyring.rs index 795b43acc1..ab0a96822e 100644 --- a/src/dfx-core/src/error/keyring.rs +++ b/src/dfx-core/src/error/keyring.rs @@ -12,6 +12,9 @@ pub enum KeyringError { #[error("Failed to get password for keyring")] GetPasswordFailed(#[source] keyring::Error), + #[error("Failed to create entry for keyring")] + NewEntryFailed(#[source] keyring::Error), + #[error("Failed to load mock keyring")] LoadMockKeyringFailed(#[source] StructuredFileError), diff --git a/src/dfx-core/src/identity/keyring_mock.rs b/src/dfx-core/src/identity/keyring_mock.rs index ec1a16e73d..36f3e71596 100644 --- a/src/dfx-core/src/identity/keyring_mock.rs +++ b/src/dfx-core/src/identity/keyring_mock.rs @@ -2,7 +2,7 @@ use super::TEMP_IDENTITY_PREFIX; use crate::error::keyring::KeyringError; use crate::error::keyring::KeyringError::{ DecodePemFailed, DeletePasswordFailed, GetPasswordFailed, LoadMockKeyringFailed, - MockKeyNotFound, MockUnavailable, SaveMockKeyringFailed, SetPasswordFailed, + MockKeyNotFound, MockUnavailable, NewEntryFailed, SaveMockKeyringFailed, SetPasswordFailed, }; use crate::json::{load_json_file, save_json_file}; use keyring; @@ -73,7 +73,8 @@ pub fn load_pem_from_keyring(identity_name_suffix: &str) -> Result, Keyr let keyring_identity_name = keyring_identity_name_from_suffix(identity_name_suffix); match KeyringMockMode::current_mode() { KeyringMockMode::NoMock => { - let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name); + let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name) + .map_err(NewEntryFailed)?; let encoded_pem = entry.get_password().map_err(GetPasswordFailed)?; let pem = hex::decode(encoded_pem).map_err(DecodePemFailed)?; Ok(pem) @@ -99,7 +100,8 @@ pub fn write_pem_to_keyring( let encoded_pem = hex::encode(pem_content); match KeyringMockMode::current_mode() { KeyringMockMode::NoMock => { - let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name); + let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name) + .map_err(NewEntryFailed)?; entry .set_password(&encoded_pem) .map_err(SetPasswordFailed)?; @@ -125,8 +127,11 @@ pub fn keyring_available(log: &Logger) -> bool { "{}{}{}", KEYRING_IDENTITY_PREFIX, TEMP_IDENTITY_PREFIX, "dummy" ); - let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &dummy_entry_name); - entry.set_password("dummy entry").is_ok() + if let Ok(entry) = keyring::Entry::new(KEYRING_SERVICE_NAME, &dummy_entry_name) { + entry.set_password("dummy entry").is_ok() + } else { + false + } } KeyringMockMode::MockReject => false, KeyringMockMode::MockAvailable => true, @@ -137,9 +142,10 @@ pub fn delete_pem_from_keyring(identity_name_suffix: &str) -> Result<(), Keyring let keyring_identity_name = keyring_identity_name_from_suffix(identity_name_suffix); match KeyringMockMode::current_mode() { KeyringMockMode::NoMock => { - let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name); + let entry = keyring::Entry::new(KEYRING_SERVICE_NAME, &keyring_identity_name) + .map_err(NewEntryFailed)?; if entry.get_password().is_ok() { - entry.delete_password().map_err(DeletePasswordFailed)?; + entry.delete_credential().map_err(DeletePasswordFailed)?; } } KeyringMockMode::MockAvailable => { From 72f0cde3658c2119adc7390d733ee509bdab90ba Mon Sep 17 00:00:00 2001 From: Adam Spofford <93943719+adamspofford-dfinity@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:22:54 -0800 Subject: [PATCH 3/3] feat: make `dfx info replica-port` pocketic-incompatible (#4056) --- CHANGELOG.md | 5 ++++ docs/cli-reference/dfx-info.mdx | 17 ++++++------ e2e/tests-dfx/create.bash | 2 +- e2e/tests-dfx/info.bash | 17 ++++++++---- e2e/tests-dfx/start.bash | 7 +++-- .../config/model/local_server_descriptor.rs | 8 ++++++ src/dfx/src/commands/info/mod.rs | 13 +++++++--- .../src/commands/info/pocketic_config_port.rs | 26 +++++++++++++++++++ src/dfx/src/commands/info/replica_port.rs | 12 +++++---- 9 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 src/dfx/src/commands/info/pocketic_config_port.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 30bad5914a..df118b6ed0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ # UNRELEASED +### feat!: `dfx info pocketic-config-port` + +Due to the incompatibility between the APIs on the replica port and the PocketIC port, `dfx info replica-port` +no longer works with PocketIC, and the PocketIC port is provided by a new command, `dfx info pocketic-config-port`. + ### test: adds playwright test for svelte `dfx new` project The first of a suite of baseline tests to automate testing starter projects. Makes sure they are compatible with other dfx or asset canister changes. diff --git a/docs/cli-reference/dfx-info.mdx b/docs/cli-reference/dfx-info.mdx index 6ff0b43215..10ce99290b 100644 --- a/docs/cli-reference/dfx-info.mdx +++ b/docs/cli-reference/dfx-info.mdx @@ -14,14 +14,15 @@ dfx info [type] [flag] These are the types of information that the `dfx info` command can display. -| Information | Description | -|--------------------|--------------------------------------------------------------------------------------------------------------------| -| candid-ui-url | The URL of the Candid UI canister. | -| networks-json-path | Path to network definition file networks.json. | -| replica-port | The listening port of the replica. | -| replica-rev | The revision of the bundled replica. | -| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". | -| webserver-port | The local webserver port. | +| Information | Description | +|----------------------|--------------------------------------------------------------------------------------------------------------------| +| candid-ui-url | The URL of the Candid UI canister. | +| networks-json-path | Path to network definition file networks.json. | +| replica-port | The listening port of the replica. | +| pocketic-config-port | The listening port of PocketIC. | +| replica-rev | The revision of the bundled replica. | +| security-policy | Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". | +| webserver-port | The local webserver port. | ## Options diff --git a/e2e/tests-dfx/create.bash b/e2e/tests-dfx/create.bash index fbbe866d4d..30976902e7 100644 --- a/e2e/tests-dfx/create.bash +++ b/e2e/tests-dfx/create.bash @@ -416,7 +416,7 @@ function textual_decode() { # base64 encode the actual canister id CANISTER_ID_BASE64="$(textual_decode "${CANISTER_ID}" | xxd -r -p | base64)" # fetch topology from PocketIC server - TOPOLOGY="$(curl "http://127.0.0.1:$(dfx info replica-port)/instances/0/read/topology")" + TOPOLOGY="$(curl "http://127.0.0.1:$(dfx info pocketic-config-port)/instances/0/read/topology")" echo "${TOPOLOGY}" # find application subnet id in the topology for subnet_id in $(echo "${TOPOLOGY}" | jq '.subnet_configs | keys[]') diff --git a/e2e/tests-dfx/info.bash b/e2e/tests-dfx/info.bash index cd60d1ed08..d6307dddf3 100644 --- a/e2e/tests-dfx/info.bash +++ b/e2e/tests-dfx/info.bash @@ -15,15 +15,22 @@ teardown() { } @test "displays the replica port" { - assert_command_fail dfx info replica-port - assert_contains "No replica port found" - - dfx_start - assert_command dfx info replica-port if [[ "$USE_POCKETIC" ]] then + assert_command_fail dfx info pocketic-config-port + assert_contains "No PocketIC port found" + dfx_start + assert_command_fail dfx info replica-port + assert_contains "The running server is PocketIC" + assert_command dfx info pocketic-config-port assert_eq "$(get_pocketic_port)" else + assert_command_fail dfx info replica-port + assert_contains "No replica port found" + dfx_start + assert_command_fail dfx info pocketic-config-port + assert_contains "The running server is a native replica" + assert_command dfx info replica-port assert_eq "$(get_replica_port)" fi } diff --git a/e2e/tests-dfx/start.bash b/e2e/tests-dfx/start.bash index 9874305fd1..c86a949cb5 100644 --- a/e2e/tests-dfx/start.bash +++ b/e2e/tests-dfx/start.bash @@ -283,8 +283,11 @@ teardown() { jq ".local.replica.port=$replica_port" "$E2E_NETWORKS_JSON" | sponge "$E2E_NETWORKS_JSON" dfx_start - - assert_command dfx info replica-port + if [[ "$USE_POCKETIC" ]]; then + assert_command dfx info pocketic-config-port + else + assert_command dfx info replica-port + fi assert_eq "$replica_port" } diff --git a/src/dfx-core/src/config/model/local_server_descriptor.rs b/src/dfx-core/src/config/model/local_server_descriptor.rs index e2a6f9af62..f43a83400a 100644 --- a/src/dfx-core/src/config/model/local_server_descriptor.rs +++ b/src/dfx-core/src/config/model/local_server_descriptor.rs @@ -18,6 +18,8 @@ use std::net::SocketAddr; use std::path::{Path, PathBuf}; use time::OffsetDateTime; +use super::replica_config::CachedReplicaConfig; + #[derive(Deserialize, Serialize, Debug)] pub struct NetworkMetadata { pub created: OffsetDateTime, @@ -394,6 +396,12 @@ impl LocalServerDescriptor { None => Ok(None), } } + + pub fn is_pocketic(&self) -> Result, StructuredFileError> { + Ok(self + .effective_config()? + .map(|cfg| matches!(cfg.config, CachedReplicaConfig::PocketIc { .. }))) + } } /// Reads a port number from a file. diff --git a/src/dfx/src/commands/info/mod.rs b/src/dfx/src/commands/info/mod.rs index 02ddbdff38..092f4e0397 100644 --- a/src/dfx/src/commands/info/mod.rs +++ b/src/dfx/src/commands/info/mod.rs @@ -1,3 +1,4 @@ +mod pocketic_config_port; mod replica_port; mod webserver_port; use crate::commands::info::{replica_port::get_replica_port, webserver_port::get_webserver_port}; @@ -10,6 +11,7 @@ use crate::Environment; use anyhow::{bail, Context}; use clap::{Parser, Subcommand}; use dfx_core::config::model::dfinity::NetworksConfig; +use pocketic_config_port::get_pocketic_config_port; #[derive(Subcommand, Clone, Debug)] enum InfoType { @@ -17,14 +19,16 @@ enum InfoType { CandidUiUrl, /// Show the headers that gets applied to assets in .ic-assets.json5 if "security_policy" is "standard" or "hardened". SecurityPolicy, - /// Show the port of the local replica - ReplicaPort, + /// Show the port of the local IC API/HTTP gateway + WebserverPort, /// Show the revision of the replica shipped with this dfx binary ReplicaRev, - /// Show the port of the webserver - WebserverPort, /// Show the path to network configuration file NetworksJsonPath, + /// Show the port the replica is using, if it is running + ReplicaPort, + /// Show the port that PocketIC is using, if it is running + PocketicConfigPort, } #[derive(Parser)] @@ -54,6 +58,7 @@ pub fn exec(env: &dyn Environment, opts: InfoOpts) -> DfxResult { ic_asset::security_policy::SecurityPolicy::Standard.to_json5_str() } InfoType::ReplicaPort => get_replica_port(env)?, + InfoType::PocketicConfigPort => get_pocketic_config_port(env)?, InfoType::ReplicaRev => info::replica_rev().to_string(), InfoType::WebserverPort => get_webserver_port(env)?, InfoType::NetworksJsonPath => NetworksConfig::new()? diff --git a/src/dfx/src/commands/info/pocketic_config_port.rs b/src/dfx/src/commands/info/pocketic_config_port.rs new file mode 100644 index 0000000000..74322a46ef --- /dev/null +++ b/src/dfx/src/commands/info/pocketic_config_port.rs @@ -0,0 +1,26 @@ +use anyhow::bail; +use dfx_core::network::provider::{create_network_descriptor, LocalBindDetermination}; + +use crate::lib::{environment::Environment, error::DfxResult}; + +pub(crate) fn get_pocketic_config_port(env: &dyn Environment) -> DfxResult { + let network_descriptor = create_network_descriptor( + env.get_config()?, + env.get_networks_config(), + None, + None, + LocalBindDetermination::AsConfigured, + )?; + let local = network_descriptor.local_server_descriptor()?; + match local.is_pocketic()? { + Some(true) => {} + Some(false) => bail!("The running server is a native replica, not PocketIC"), + None => bail!("No PocketIC port found"), + } + let logger = None; + if let Some(port) = local.get_running_pocketic_port(logger)? { + Ok(format!("{}", port)) + } else { + bail!("No PocketIC port found"); + } +} diff --git a/src/dfx/src/commands/info/replica_port.rs b/src/dfx/src/commands/info/replica_port.rs index 8dc4ebd149..2e441e0c30 100644 --- a/src/dfx/src/commands/info/replica_port.rs +++ b/src/dfx/src/commands/info/replica_port.rs @@ -11,12 +11,14 @@ pub(crate) fn get_replica_port(env: &dyn Environment) -> DfxResult { None, LocalBindDetermination::AsConfigured, )?; - + let local = network_descriptor.local_server_descriptor()?; + match local.is_pocketic()? { + Some(false) => {} + Some(true) => bail!("The running server is PocketIC, not a native replica"), + None => bail!("No replica port found"), + } let logger = None; - if let Some(port) = network_descriptor - .local_server_descriptor()? - .get_running_replica_port(logger)? - { + if let Some(port) = local.get_running_replica_port(logger)? { Ok(format!("{}", port)) } else { bail!("No replica port found");