Skip to content

Move test client back in the Parsec repo #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name = "parsec"
path = "src/bin/main.rs"

[dependencies]
parsec-interface = "0.12.0"
parsec-interface = "0.13.0"
rand = "0.7.2"
base64 = "0.10.1"
uuid = "0.7.4"
Expand All @@ -40,12 +40,13 @@ derivative = "1.0.3"
version = "3.0.0"

[dev-dependencies]
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.3.0" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

num_cpus = "1.10.1"
picky-asn1-der = "0.2.2"
picky-asn1 = "0.2.1"
serde = { version = "1.0", features = ["derive"] }
sha2 = "0.8.1"
parsec-client = "0.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

parsec-interface = { version = "0.13.0", features = ["testing"] }

[build-dependencies]
bindgen = "0.50.0"
Expand Down
20 changes: 1 addition & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,25 +73,7 @@ Contributions from the developer community are welcome. Please refer to the cont

# Example

Launch the Parsec service with a single software-based provider (using the default configuration):
```bash
$ git clone https://github.com/parallaxsecond/parsec.git
$ cd parsec
$ RUST_LOG=info cargo run
```

Parsec Client Libraries can now communicate with the service. For example using the Rust Test client,
RSA signatures can be done as follows:
```rust
use parsec_client_test::TestClient;

let mut client = TestClient::new();
let key_name = String::from("🔑 What shall I sign? 🔑");
client.generate_rsa_sign_key(key_name.clone()).unwrap();
let signature = client.sign(key_name,
String::from("Platform AbstRaction for SECurity").into_bytes())
.unwrap();
```
For examples of how to access PARSEC as a client application, check [this Rust client documentation](https://docs.rs/parsec-client/*/parsec_client/core/basic_client/struct.BasicClient.html).

Check the [**user**](https://parallaxsecond.github.io/parsec-book/parsec_users.html), [**client developer**](https://parallaxsecond.github.io/parsec-book/parsec_client/index.html) and [**service developer**](https://parallaxsecond.github.io/parsec-book/parsec_service/index.html) guides for more information on building, installing, testing and using Parsec!

Expand Down
5 changes: 2 additions & 3 deletions tests/all_providers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use parsec_interface::requests::Result;
use parsec_interface::requests::{Opcode, ProviderID};
use crate::test_clients::TestClient;
use parsec_interface::requests::{Opcode, ProviderID, Result};
use std::collections::HashSet;
use uuid::Uuid;

Expand Down
1 change: 1 addition & 0 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@

mod all_providers;
mod per_provider;
mod test_clients;
5 changes: 3 additions & 2 deletions tests/per_provider/normal_tests/asym_sign_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use crate::test_clients::TestClient;
use parsec_interface::operations::psa_algorithm::*;
use parsec_interface::operations::psa_key_attributes::*;
use parsec_interface::requests::{ResponseStatus, Result};
use parsec_interface::requests::ResponseStatus;
use parsec_interface::requests::Result;
use sha2::{Digest, Sha256};

const HASH: [u8; 32] = [
Expand Down
13 changes: 7 additions & 6 deletions tests/per_provider/normal_tests/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use parsec_interface::requests::{ResponseStatus, Result};
use crate::test_clients::TestClient;
use parsec_interface::requests::ResponseStatus;
use parsec_interface::requests::Result;

#[test]
fn two_auths_same_key_name() -> Result<()> {
let key_name = String::from("two_auths_same_key_name");
let mut client = TestClient::new();
let auth1 = String::from("first_client").into_bytes();
let auth2 = String::from("second_client").into_bytes();
let auth1 = String::from("first_client");
let auth2 = String::from("second_client");

client.set_auth(auth1);
client.generate_rsa_sign_key(key_name.clone())?;
Expand All @@ -33,8 +34,8 @@ fn two_auths_same_key_name() -> Result<()> {
fn delete_wrong_key() -> Result<()> {
let key_name = String::from("delete_wrong_key");
let mut client = TestClient::new();
let auth1 = String::from("first_client").into_bytes();
let auth2 = String::from("second_client").into_bytes();
let auth1 = String::from("first_client");
let auth2 = String::from("second_client");

client.set_auth(auth1);
client.generate_rsa_sign_key(key_name.clone())?;
Expand Down
51 changes: 7 additions & 44 deletions tests/per_provider/normal_tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,17 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::RequestTestClient;
use parsec_client_test::TestClient;
use crate::test_clients::RawRequestClient;
use parsec_interface::requests::request::RawHeader;
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus};

#[test]
fn invalid_version() {
let mut client = RequestTestClient::new();
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 0xff;

let resp = client
.send_raw_request(req_hdr, Vec::new())
.expect("Failed to read Response");
assert_eq!(
resp.header.status,
ResponseStatus::WireProtocolVersionNotSupported
);
assert_eq!(resp.header.opcode, Opcode::Ping);
}

#[test]
fn invalid_provider() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = 0xff;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 0x01;

let resp = client
.send_raw_request(req_hdr, Vec::new())
Expand All @@ -54,12 +33,11 @@ fn invalid_provider() {

#[test]
fn invalid_content_type() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 1;
req_hdr.content_type = 0xff;

let resp = client
Expand All @@ -71,12 +49,11 @@ fn invalid_content_type() {

#[test]
fn invalid_accept_type() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 1;

req_hdr.accept_type = 0xff;

Expand All @@ -89,12 +66,11 @@ fn invalid_accept_type() {

#[test]
fn invalid_body_len() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 1;

req_hdr.body_len = 0xff_ff;

Expand All @@ -106,12 +82,11 @@ fn invalid_body_len() {

#[test]
fn invalid_auth_len() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = Opcode::Ping as u16;
req_hdr.version_maj = 1;

req_hdr.auth_len = 0xff_ff;

Expand All @@ -123,26 +98,14 @@ fn invalid_auth_len() {

#[test]
fn invalid_opcode() {
let mut client = RequestTestClient::new();
let mut client = RawRequestClient {};
let mut req_hdr = RawHeader::new();

req_hdr.provider = ProviderID::Core as u8;
req_hdr.opcode = 0xff_ff;
req_hdr.version_maj = 1;

let resp = client
.send_raw_request(req_hdr, Vec::new())
.expect("Failed to read Response");
assert_eq!(resp.header.status, ResponseStatus::OpcodeDoesNotExist);
}

#[test]
fn wrong_provider_core() {
let mut client = TestClient::new();
client.set_provider(Some(ProviderID::Core));

let response_status = client
.destroy_key(String::new())
.expect_err("Core Provider should not support DestroyKey operation!");
assert_eq!(response_status, ResponseStatus::PsaErrorNotSupported);
}
5 changes: 3 additions & 2 deletions tests/per_provider/normal_tests/create_destroy_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use crate::test_clients::TestClient;
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash};
use parsec_interface::operations::psa_key_attributes::{
KeyAttributes, KeyPolicy, KeyType, UsageFlags,
};
use parsec_interface::requests::{ResponseStatus, Result};
use parsec_interface::requests::ResponseStatus;
use parsec_interface::requests::Result;
use picky_asn1::wrapper::IntegerAsn1;
use serde::{Deserialize, Serialize};

Expand Down
5 changes: 3 additions & 2 deletions tests/per_provider/normal_tests/export_public_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use crate::test_clients::TestClient;
use parsec_interface::operations::psa_algorithm::*;
use parsec_interface::operations::psa_key_attributes::*;
use parsec_interface::requests::{ResponseStatus, Result};
use parsec_interface::requests::ResponseStatus;
use parsec_interface::requests::Result;
use picky_asn1::wrapper::IntegerAsn1;
use serde::{Deserialize, Serialize};

Expand Down
7 changes: 3 additions & 4 deletions tests/per_provider/normal_tests/import_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
use parsec_client_test::TestClient;
use crate::test_clients::TestClient;
use parsec_interface::operations::psa_algorithm::*;
use parsec_interface::operations::psa_key_attributes::*;
use parsec_interface::requests::{ResponseStatus, Result};
use parsec_interface::requests::ResponseStatus;
use parsec_interface::requests::Result;
use picky_asn1::wrapper::IntegerAsn1;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -57,8 +58,6 @@ fn import_key() -> Result<()> {
let mut client = TestClient::new();
let key_name = String::from("import_key");

println!("{:?}", KEY_DATA.to_vec());

client.import_rsa_public_key(key_name, KEY_DATA.to_vec())
}

Expand Down
6 changes: 3 additions & 3 deletions tests/per_provider/normal_tests/key_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2020, Arm Limited, All Rights Reserved
// SPDX-License-Identifier: Apache-2.0
use parsec_client_test::TestClient;
use crate::test_clients::TestClient;
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Cipher, Hash};
use parsec_interface::operations::psa_key_attributes::{
KeyAttributes, KeyPolicy, KeyType, UsageFlags,
};
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus};
use parsec_interface::requests::{ProviderID, ResponseStatus};

// Ignored as only RSA key types are supported for now.
#[ignore]
Expand Down Expand Up @@ -121,7 +121,7 @@ fn wrong_permitted_algorithm() {

// The Mbed Crypto provider currently does not support other algorithms than the RSA PKCS 1v15
// signing algorithm with hash when checking policies only.
if client.get_cached_provider(Opcode::PsaSignHash) == ProviderID::MbedCrypto {
if client.provider().unwrap() == ProviderID::MbedCrypto {
return;
}

Expand Down
Loading