Skip to content

Commit

Permalink
Merge pull request #263 from adorsys/251-cicd-review-and-enhancement-…
Browse files Browse the repository at this point in the history
…for-didcomm-mediator-project-e3

251 cicd review and enhancement for didcomm mediator project e3
  • Loading branch information
ndefokou authored Nov 22, 2024
2 parents 6d512f6 + 273019b commit 30258ce
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 54 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CD

on:
push:
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Rust
uses: actions/setup-rust@v1
with:
rust-version: stable

# Deploy to AWS EC2 Or another instance
19 changes: 12 additions & 7 deletions .github/workflows/rust.yml → .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Rust CI

on: [push, pull_request]
on:[pull_request]

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build and Test

ci:
name: Build and test
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -42,7 +43,11 @@ jobs:
chmod +x .github/scripts/test_config.sh
sh .github/scripts/test_config.sh
- name: Build and Run Test
run: |
cargo build --workspace --all-features
cargo nextest run --workspace --all-features
- name: Check Formatting
run: cargo fmt --all -- --check

- name: Build Project
run: cargo build --workspace --all-features

- name: Run Tests
run: cargo nextest run --workspace --all-features
9 changes: 7 additions & 2 deletions crates/filesystem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,16 @@ mod tests {

impl FileSystem for MockFileSystem {
fn read_to_string(&self, path: &Path) -> IoResult<String> {
Ok(self.map.get(path.to_str().unwrap()).cloned().unwrap_or_default())
Ok(self
.map
.get(path.to_str().unwrap())
.cloned()
.unwrap_or_default())
}

fn write(&mut self, path: &Path, content: &str) -> IoResult<()> {
self.map.insert(path.to_str().unwrap().to_string(), content.to_string());
self.map
.insert(path.to_str().unwrap().to_string(), content.to_string());
Ok(())
}

Expand Down
5 changes: 4 additions & 1 deletion crates/web-plugins/did-endpoint/src/didgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@ where
// Validate the keys in the DID document
if let Some(verification_methods) = &diddoc.verification_method {
for method in verification_methods {
let pubkey = method.public_key.as_ref().ok_or(String::from("Missing key"))?;
let pubkey = method
.public_key
.as_ref()
.ok_or(String::from("Missing key"))?;
let kid = util::handle_vm_id(&method.id, &diddoc);
match pubkey {
KeyFormat::Jwk(_) => validate_key(&kid, keystore)?,
Expand Down
2 changes: 1 addition & 1 deletion crates/web-plugins/did-endpoint/src/plugin.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::{didgen, web};
use axum::Router;
use database::Repository;
use filesystem::FileSystem;
use keystore::Secrets;
use plugin_api::{Plugin, PluginError};
use std::sync::{Arc, Mutex};
use filesystem::FileSystem;

#[derive(Default)]
pub struct DidEndpoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct Parameters {

/// The URL of the X.509 certificate associated with this key.
#[serde(skip_serializing_if = "Option::is_none", default)]
#[cfg(feature = "url")]
pub x5u: Option<url::Url>,

/// The X.509 certificate associated with this key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,12 @@ impl DidPeer {
}

match did {
s if s.starts_with("did:peer:0") => self.expand_did_peer_0(did).map_err(Into::into),
s if s.starts_with("did:peer:2") => self.expand_did_peer_2(did).map_err(Into::into),
s if s.starts_with("did:peer:4") => self.expand_did_peer_4(did).map_err(Into::into),
_ => Err(DIDResolutionError::MethodNotSupported),
s if s.starts_with("did:peer:0") => self.expand_did_peer_0(did).map_err(Into::into),
s if s.starts_with("did:peer:2") => self.expand_did_peer_2(did).map_err(Into::into),
s if s.starts_with("did:peer:4") => self.expand_did_peer_4(did).map_err(Into::into),
_ => Err(DIDResolutionError::MethodNotSupported),
}
}
}


/// Expands did:peer:0 address
///
Expand Down Expand Up @@ -814,10 +813,7 @@ mod tests {
let did_method = DidPeer::default();

let did = "did:peer:1zQmbEB1EqP7PnNVaHiSpXhkatAA6kNyQK9mWkvrMx2eckgq";
assert!(matches!(
did_method.expand(did).unwrap_err(),
DIDResolutionError::MethodNotSupported
));
assert!(matches!(did_method.expand(did).unwrap_err(), DIDResolutionError::MethodNotSupported));
}

#[test]
Expand Down Expand Up @@ -983,10 +979,7 @@ mod tests {
fn test_expand_did_peer_0_fails_on_too_long_did() {
let did_method = DidPeer::default();
let did = "did:peer:0zQebt6zPwbE4Vw5GFAjjARHrNXFALofERVv4q6Z4db8cnDRQm";
assert!(matches!(
did_method.expand(did).unwrap_err(),
DIDResolutionError::InvalidPublicKeyLength
));
assert!(matches!(did_method.expand(did).unwrap_err(), DIDResolutionError::InvalidPublicKeyLength));
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::errors::DIDPeerMethodError;
use crate::didcore::Document as DIDDocument;
use crate::didcore::{VerificationMethodType, Service};
use crate::didcore::{Service, VerificationMethodType};
use serde_json::{json, Map, Value};

pub(super) fn abbreviate_service_for_did_peer_2(service: &Service) -> Result<String, DIDPeerMethodError> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ async fn checks(
Ok(next.unwrap().to_string())
}

pub(crate) async fn handler(state: Arc<AppState>, message: Message) -> Result<Option<Message>, ForwardError> {
pub(crate) async fn handler(
state: Arc<AppState>,
message: Message,
) -> Result<Option<Message>, ForwardError> {
let AppStateRepository {
message_repository,
connection_repository,
Expand Down Expand Up @@ -163,7 +166,9 @@ mod test {
.await
.expect("Unable unpack");

let msg = mediator_forward_process(Arc::new(state.clone()), msg).await.unwrap();
let msg = mediator_forward_process(Arc::new(state.clone()), msg)
.await
.unwrap();

println!("Mediator1 is forwarding message \n{:?}\n", msg);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod coord;
#[cfg(feature = "stateful")]
pub mod stateful;

#[cfg(feature = "stateless")]
pub mod stateless;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod midlw;
#[cfg(feature = "stateful")]
pub mod stateful;
mod midlw;

#[allow(unexpected_cfgs)]
#[cfg(feature = "stateless")]
mod stateless;
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) struct LiveDeliveryChange<'a> {
pub(crate) id: &'a str,

pub(crate) pthid: &'a str,

#[serde(rename = "type")]
pub(crate) type_: &'a str,

Expand Down Expand Up @@ -110,7 +110,7 @@ impl<'a> From<LiveDeliveryChange<'a>> for MessageBuilder {
#[cfg(test)]
mod tests {
use super::*;
use didcomm::{MessageBuilder, Attachment};
use didcomm::{Attachment, MessageBuilder};
use serde_json::{json, Value};

#[test]
Expand Down Expand Up @@ -148,12 +148,16 @@ mod tests {
let id = "12345";
let thid = "67890";
let type_ = "https://didcomm.org/messagepickup/3.0/delivery-response";
let attachment = Attachment::json(json!({"key": "value"})).id("123".to_owned()).finalize();
let attachment = Attachment::json(json!({"key": "value"}))
.id("123".to_owned())
.finalize();
let response = DeliveryResponse {
id,
thid,
type_,
body: BodyDeliveryResponse { recipient_did: None },
body: BodyDeliveryResponse {
recipient_did: None,
},
attachments: vec![attachment.clone()],
};

Expand Down
12 changes: 3 additions & 9 deletions crates/web-plugins/didcomm-messaging/shared/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod resolvers;
pub mod tests_utils;

use did_utils::{
didcore::{VerificationMethodType, Document, KeyFormat, VerificationMethod},
didcore::{Document, KeyFormat, VerificationMethod, VerificationMethodType},
jwk::Jwk,
};
use filesystem::FileSystem;
Expand Down Expand Up @@ -104,10 +104,7 @@ mod tests {
)
.unwrap();

assert_eq!(
vm_id,
"#key-2"
);
assert_eq!(vm_id, "#key-2");
assert_eq!(
json_canon::to_string(&jwk).unwrap(),
json_canon::to_string(&expected_jwk).unwrap()
Expand All @@ -128,10 +125,7 @@ mod tests {
)
.unwrap();

assert_eq!(
vm_id,
"#key-1"
);
assert_eq!(vm_id, "#key-1");
assert_eq!(
json_canon::to_string(&jwk).unwrap(),
json_canon::to_string(&expected_jwk).unwrap()
Expand Down
2 changes: 0 additions & 2 deletions crates/web-plugins/didcomm-messaging/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
mod did_rotation;
mod error;
mod manager;
mod midlw;
mod protocols;
mod web;

pub mod plugin;
Empty file.
10 changes: 2 additions & 8 deletions crates/web-plugins/didcomm-messaging/src/midlw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ pub async fn unpack_didcomm_message(
let bytes = match hyper::body::to_bytes(body).await {
Ok(bytes) => bytes,
Err(_) => {
let response = (
StatusCode::BAD_REQUEST,
Error::UnparseablePayload.json(),
);
let response = (StatusCode::BAD_REQUEST, Error::UnparseablePayload.json());

return response.into_response();
}
Expand Down Expand Up @@ -133,10 +130,7 @@ async fn unpack_payload(
}

if plain_message.from.is_none() || !metadata.authenticated || metadata.anonymous_sender {
let response = (
StatusCode::BAD_REQUEST,
Error::AnonymousPacker.json(),
);
let response = (StatusCode::BAD_REQUEST, Error::AnonymousPacker.json());

return Err(response.into_response());
}
Expand Down
Empty file.
4 changes: 3 additions & 1 deletion src/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ lazy_static! {
#[cfg(feature = "plugin-oob_messages")]
Arc::new(Mutex::new(oob_messages::plugin::OOBMessages {})),
#[cfg(feature = "plugin-didcomm_messaging")]
Arc::new(Mutex::new(didcomm_messaging::plugin::MediatorCoordination::default())),
Arc::new(Mutex::new(
didcomm_messaging::plugin::MediatorCoordination::default()
)),
];
}

0 comments on commit 30258ce

Please sign in to comment.