Skip to content

Commit

Permalink
Merge branch 'main' into restore_pagination_test
Browse files Browse the repository at this point in the history
  • Loading branch information
aoyako authored Oct 28, 2024
2 parents 8027386 + d2846a3 commit f7bd0c8
Show file tree
Hide file tree
Showing 15 changed files with 311 additions and 244 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/iroha2-dev-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ jobs:
--all-features
--branch --no-report
- name: Generate lcov report
run: cargo llvm-cov report --text --output-path coverage.txt
run: cargo llvm-cov report --lcov --output-path lcov.info
- name: Upload lcov report
uses: actions/upload-artifact@v4
with:
name: report-coverage
path: coverage.txt
path: lcov.info
- name: Upload test network artifacts
if: failure() && (steps.test_no_features.outcome == 'failure' || steps.test_all_features.outcome == 'failure')
uses: actions/upload-artifact@v4
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/iroha2-dev-sonar-dojo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
with:
args: >
-Dcommunity.rust.clippy.reportPaths=lints/clippy.json
-Dsonar.cfamily.llvm-cov.reportPath=lints/coverage.txt
-Dcommunity.rust.lcov.reportPaths=lints/lcov.info
-Dsonar.cfamily.llvm-cov.reportPath=lints/lcov.info
-Dsonar.cfamily.gcov.reportsPath=lints/lcov.info
-Dsonar.pullrequest.key=${{ github.event.workflow_run.pull_requests[0].number }}
-Dsonar.pullrequest.base=${{ github.event.workflow_run.pull_requests[0].base.ref }}
-Dsonar.pullrequest.branch=${{ github.event.workflow_run.pull_requests[0].head.ref }}
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions crates/iroha/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ impl Client {
mut headers: HashMap<String, String>,
) -> Self {
if let Some(basic_auth) = basic_auth {
let credentials = format!("{}:{}", basic_auth.web_login, basic_auth.password);
let credentials = format!(
"{}:{}",
basic_auth.web_login,
basic_auth.password.expose_secret()
);
let engine = base64::engine::general_purpose::STANDARD;
let encoded = base64::engine::Engine::encode(&engine, credentials);
headers.insert(String::from("Authorization"), format!("Basic {encoded}"));
Expand Down Expand Up @@ -974,11 +978,13 @@ mod blocks_api {

#[cfg(test)]
mod tests {
use iroha_primitives::small::SmallStr;
use iroha_test_samples::gen_account_in;

use super::*;
use crate::config::{BasicAuth, Config};
use crate::{
config::{BasicAuth, Config},
secrecy::SecretString,
};

const LOGIN: &str = "mad_hatter";
const PASSWORD: &str = "ilovetea";
Expand Down Expand Up @@ -1035,7 +1041,7 @@ mod tests {
let client = Client::new(Config {
basic_auth: Some(BasicAuth {
web_login: LOGIN.parse().expect("Failed to create valid `WebLogin`"),
password: SmallStr::from_str(PASSWORD),
password: SecretString::new(PASSWORD.to_owned()),
}),
..config_factory()
});
Expand Down
6 changes: 4 additions & 2 deletions crates/iroha/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod user;

pub use user::Root as UserConfig;

use crate::secrecy::SecretString;

#[allow(missing_docs)]
pub const DEFAULT_TRANSACTION_TIME_TO_LIVE: Duration = Duration::from_secs(100);
#[allow(missing_docs)]
Expand Down Expand Up @@ -49,12 +51,12 @@ impl FromStr for WebLogin {
}

/// Basic Authentication credentials
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
#[derive(Clone, Deserialize, Serialize, Debug)]
pub struct BasicAuth {
/// Login for Basic Authentication
pub web_login: WebLogin,
/// Password for Basic Authentication
pub password: SmallStr,
pub password: SecretString,
}

/// Complete client configuration
Expand Down
1 change: 1 addition & 0 deletions crates/iroha/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod config;
pub mod http;
mod http_default;
pub mod query;
mod secrecy;

pub use iroha_crypto as crypto;
pub use iroha_data_model as data_model;
27 changes: 27 additions & 0 deletions crates/iroha/src/secrecy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::fmt;

use derive_more::Constructor;
use serde::{Deserialize, Serialize, Serializer};

#[derive(Clone, Deserialize, Constructor)]
pub struct SecretString(String);

impl SecretString {
pub fn expose_secret(&self) -> &str {
&self.0
}
}

const REDACTED: &'static str = "[REDACTED]";

impl Serialize for SecretString {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
REDACTED.serialize(serializer)
}
}

impl fmt::Debug for SecretString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
REDACTED.fmt(f)
}
}
18 changes: 6 additions & 12 deletions crates/iroha_core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,10 +817,9 @@ mod tests {
use iroha_data_model::{
account::Account,
domain::{Domain, DomainId},
executor::Executor,
isi::Log,
peer::PeerId,
transaction::{TransactionBuilder, WasmSmartContract},
transaction::TransactionBuilder,
ChainId, Level,
};
use iroha_genesis::GenesisBuilder;
Expand Down Expand Up @@ -1111,16 +1110,11 @@ mod tests {
live_query_store,
);

let executor = {
let executor_blob = std::fs::read("../../defaults/executor.wasm").unwrap();
Executor::new(WasmSmartContract::from_compiled(executor_blob))
};
let genesis = GenesisBuilder::default().build_and_sign(
chain_id.clone(),
executor,
topology.as_ref().to_owned(),
&genesis_key_pair,
);
let executor_path = PathBuf::from("../../defaults/executor.wasm").into();
let genesis = GenesisBuilder::new(chain_id.clone(), executor_path)
.set_topology(topology.as_ref().to_owned())
.build_and_sign(&genesis_key_pair)
.expect("genesis block should be built");

{
let mut state_block = state.block(genesis.0.header());
Expand Down
9 changes: 9 additions & 0 deletions crates/iroha_data_model/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,15 @@ impl Default for SmartContractParameters {
}
}

impl FromIterator<Parameter> for Parameters {
fn from_iter<T: IntoIterator<Item = Parameter>>(iter: T) -> Self {
iter.into_iter().fold(Parameters::default(), |mut acc, x| {
acc.set_parameter(x);
acc
})
}
}

impl Parameters {
/// Convert [`Self`] into iterator of individual parameters
pub fn parameters(&self) -> impl Iterator<Item = Parameter> + '_ {
Expand Down
2 changes: 2 additions & 0 deletions crates/iroha_genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ parity-scale-codec = { workspace = true }
[dev-dependencies]
iroha_crypto = { workspace = true, features = ["rand"] }
iroha_test_samples = { workspace = true }

tempfile = { workspace = true }
Loading

0 comments on commit f7bd0c8

Please sign in to comment.