Skip to content

Commit 6df3a2d

Browse files
committed
Move test client back in the Parsec repo
This commit moves the test client back in the main Parsec repo and moves it on top of the `BasicClient` - the main core client, thus making the most out of functionality re-use. Signed-off-by: Ionut Mihalcea <[email protected]>
1 parent 369328a commit 6df3a2d

19 files changed

+700
-108
lines changed

Cargo.lock

Lines changed: 21 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ name = "parsec"
1818
path = "src/bin/main.rs"
1919

2020
[dependencies]
21-
parsec-interface = "0.12.0"
21+
parsec-interface = "0.13.0"
2222
rand = "0.7.2"
2323
base64 = "0.10.1"
2424
uuid = "0.7.4"
@@ -40,12 +40,13 @@ derivative = "1.0.3"
4040
version = "3.0.0"
4141

4242
[dev-dependencies]
43-
parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.3.0" }
4443
num_cpus = "1.10.1"
4544
picky-asn1-der = "0.2.2"
4645
picky-asn1 = "0.2.1"
4746
serde = { version = "1.0", features = ["derive"] }
4847
sha2 = "0.8.1"
48+
parsec-client = "0.1.0"
49+
parsec-interface = { version = "0.13.0", features = ["testing"] }
4950

5051
[build-dependencies]
5152
bindgen = "0.50.0"

README.md

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,7 @@ Contributions from the developer community are welcome. Please refer to the cont
7373

7474
# Example
7575

76-
Launch the Parsec service with a single software-based provider (using the default configuration):
77-
```bash
78-
$ git clone https://github.com/parallaxsecond/parsec.git
79-
$ cd parsec
80-
$ RUST_LOG=info cargo run
81-
```
82-
83-
Parsec Client Libraries can now communicate with the service. For example using the Rust Test client,
84-
RSA signatures can be done as follows:
85-
```rust
86-
use parsec_client_test::TestClient;
87-
88-
let mut client = TestClient::new();
89-
let key_name = String::from("🔑 What shall I sign? 🔑");
90-
client.generate_rsa_sign_key(key_name.clone()).unwrap();
91-
let signature = client.sign(key_name,
92-
String::from("Platform AbstRaction for SECurity").into_bytes())
93-
.unwrap();
94-
```
76+
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).
9577

9678
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!
9779

tests/all_providers/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
16-
use parsec_interface::requests::Result;
17-
use parsec_interface::requests::{Opcode, ProviderID};
15+
use crate::test_clients::TestClient;
16+
use parsec_interface::requests::{Opcode, ProviderID, Result};
1817
use std::collections::HashSet;
1918
use uuid::Uuid;
2019

tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444

4545
mod all_providers;
4646
mod per_provider;
47+
mod test_clients;

tests/per_provider/normal_tests/asym_sign_verify.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
15+
use crate::test_clients::TestClient;
1616
use parsec_interface::operations::psa_algorithm::*;
1717
use parsec_interface::operations::psa_key_attributes::*;
18-
use parsec_interface::requests::{ResponseStatus, Result};
18+
use parsec_interface::requests::ResponseStatus;
19+
use parsec_interface::requests::Result;
1920
use sha2::{Digest, Sha256};
2021

2122
const HASH: [u8; 32] = [

tests/per_provider/normal_tests/auth.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
16-
use parsec_interface::requests::{ResponseStatus, Result};
15+
use crate::test_clients::TestClient;
16+
use parsec_interface::requests::ResponseStatus;
17+
use parsec_interface::requests::Result;
1718

1819
#[test]
1920
fn two_auths_same_key_name() -> Result<()> {
2021
let key_name = String::from("two_auths_same_key_name");
2122
let mut client = TestClient::new();
22-
let auth1 = String::from("first_client").into_bytes();
23-
let auth2 = String::from("second_client").into_bytes();
23+
let auth1 = String::from("first_client");
24+
let auth2 = String::from("second_client");
2425

2526
client.set_auth(auth1);
2627
client.generate_rsa_sign_key(key_name.clone())?;
@@ -33,8 +34,8 @@ fn two_auths_same_key_name() -> Result<()> {
3334
fn delete_wrong_key() -> Result<()> {
3435
let key_name = String::from("delete_wrong_key");
3536
let mut client = TestClient::new();
36-
let auth1 = String::from("first_client").into_bytes();
37-
let auth2 = String::from("second_client").into_bytes();
37+
let auth1 = String::from("first_client");
38+
let auth2 = String::from("second_client");
3839

3940
client.set_auth(auth1);
4041
client.generate_rsa_sign_key(key_name.clone())?;

tests/per_provider/normal_tests/basic.rs

Lines changed: 7 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,17 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::RequestTestClient;
16-
use parsec_client_test::TestClient;
15+
use crate::test_clients::RawRequestClient;
1716
use parsec_interface::requests::request::RawHeader;
1817
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus};
1918

20-
#[test]
21-
fn invalid_version() {
22-
let mut client = RequestTestClient::new();
23-
let mut req_hdr = RawHeader::new();
24-
25-
req_hdr.provider = ProviderID::Core as u8;
26-
req_hdr.opcode = Opcode::Ping as u16;
27-
req_hdr.version_maj = 0xff;
28-
29-
let resp = client
30-
.send_raw_request(req_hdr, Vec::new())
31-
.expect("Failed to read Response");
32-
assert_eq!(
33-
resp.header.status,
34-
ResponseStatus::WireProtocolVersionNotSupported
35-
);
36-
assert_eq!(resp.header.opcode, Opcode::Ping);
37-
}
38-
3919
#[test]
4020
fn invalid_provider() {
41-
let mut client = RequestTestClient::new();
21+
let mut client = RawRequestClient {};
4222
let mut req_hdr = RawHeader::new();
4323

4424
req_hdr.provider = 0xff;
4525
req_hdr.opcode = Opcode::Ping as u16;
46-
req_hdr.version_maj = 0x01;
4726

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

5534
#[test]
5635
fn invalid_content_type() {
57-
let mut client = RequestTestClient::new();
36+
let mut client = RawRequestClient {};
5837
let mut req_hdr = RawHeader::new();
5938

6039
req_hdr.provider = ProviderID::Core as u8;
6140
req_hdr.opcode = Opcode::Ping as u16;
62-
req_hdr.version_maj = 1;
6341
req_hdr.content_type = 0xff;
6442

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

7250
#[test]
7351
fn invalid_accept_type() {
74-
let mut client = RequestTestClient::new();
52+
let mut client = RawRequestClient {};
7553
let mut req_hdr = RawHeader::new();
7654

7755
req_hdr.provider = ProviderID::Core as u8;
7856
req_hdr.opcode = Opcode::Ping as u16;
79-
req_hdr.version_maj = 1;
8057

8158
req_hdr.accept_type = 0xff;
8259

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

9067
#[test]
9168
fn invalid_body_len() {
92-
let mut client = RequestTestClient::new();
69+
let mut client = RawRequestClient {};
9370
let mut req_hdr = RawHeader::new();
9471

9572
req_hdr.provider = ProviderID::Core as u8;
9673
req_hdr.opcode = Opcode::Ping as u16;
97-
req_hdr.version_maj = 1;
9874

9975
req_hdr.body_len = 0xff_ff;
10076

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

10783
#[test]
10884
fn invalid_auth_len() {
109-
let mut client = RequestTestClient::new();
85+
let mut client = RawRequestClient {};
11086
let mut req_hdr = RawHeader::new();
11187

11288
req_hdr.provider = ProviderID::Core as u8;
11389
req_hdr.opcode = Opcode::Ping as u16;
114-
req_hdr.version_maj = 1;
11590

11691
req_hdr.auth_len = 0xff_ff;
11792

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

12499
#[test]
125100
fn invalid_opcode() {
126-
let mut client = RequestTestClient::new();
101+
let mut client = RawRequestClient {};
127102
let mut req_hdr = RawHeader::new();
128103

129104
req_hdr.provider = ProviderID::Core as u8;
130105
req_hdr.opcode = 0xff_ff;
131-
req_hdr.version_maj = 1;
132106

133107
let resp = client
134108
.send_raw_request(req_hdr, Vec::new())
135109
.expect("Failed to read Response");
136110
assert_eq!(resp.header.status, ResponseStatus::OpcodeDoesNotExist);
137111
}
138-
139-
#[test]
140-
fn wrong_provider_core() {
141-
let mut client = TestClient::new();
142-
client.set_provider(Some(ProviderID::Core));
143-
144-
let response_status = client
145-
.destroy_key(String::new())
146-
.expect_err("Core Provider should not support DestroyKey operation!");
147-
assert_eq!(response_status, ResponseStatus::PsaErrorNotSupported);
148-
}

tests/per_provider/normal_tests/create_destroy_key.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
15+
use crate::test_clients::TestClient;
1616
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Hash};
1717
use parsec_interface::operations::psa_key_attributes::{
1818
KeyAttributes, KeyPolicy, KeyType, UsageFlags,
1919
};
20-
use parsec_interface::requests::{ResponseStatus, Result};
20+
use parsec_interface::requests::ResponseStatus;
21+
use parsec_interface::requests::Result;
2122
use picky_asn1::wrapper::IntegerAsn1;
2223
use serde::{Deserialize, Serialize};
2324

tests/per_provider/normal_tests/export_public_key.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
15+
use crate::test_clients::TestClient;
1616
use parsec_interface::operations::psa_algorithm::*;
1717
use parsec_interface::operations::psa_key_attributes::*;
18-
use parsec_interface::requests::{ResponseStatus, Result};
18+
use parsec_interface::requests::ResponseStatus;
19+
use parsec_interface::requests::Result;
1920
use picky_asn1::wrapper::IntegerAsn1;
2021
use serde::{Deserialize, Serialize};
2122

tests/per_provider/normal_tests/import_key.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
use parsec_client_test::TestClient;
15+
use crate::test_clients::TestClient;
1616
use parsec_interface::operations::psa_algorithm::*;
1717
use parsec_interface::operations::psa_key_attributes::*;
18-
use parsec_interface::requests::{ResponseStatus, Result};
18+
use parsec_interface::requests::ResponseStatus;
19+
use parsec_interface::requests::Result;
1920
use picky_asn1::wrapper::IntegerAsn1;
2021
use serde::{Deserialize, Serialize};
2122

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

60-
println!("{:?}", KEY_DATA.to_vec());
61-
6261
client.import_rsa_public_key(key_name, KEY_DATA.to_vec())
6362
}
6463

tests/per_provider/normal_tests/key_attributes.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) 2020, Arm Limited, All Rights Reserved
22
// SPDX-License-Identifier: Apache-2.0
3-
use parsec_client_test::TestClient;
3+
use crate::test_clients::TestClient;
44
use parsec_interface::operations::psa_algorithm::{Algorithm, AsymmetricSignature, Cipher, Hash};
55
use parsec_interface::operations::psa_key_attributes::{
66
KeyAttributes, KeyPolicy, KeyType, UsageFlags,
77
};
8-
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus};
8+
use parsec_interface::requests::{ProviderID, ResponseStatus};
99

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

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

0 commit comments

Comments
 (0)