Skip to content

Commit 88332af

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 88332af

19 files changed

+778
-80
lines changed

Cargo.lock

Lines changed: 20 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 = { git = "https://github.com/parallaxsecond/parsec-client-rust" }
49+
parsec-interface = { version = "0.13.0", features = ["testing"] }
4950

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

tests/all_providers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +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;
15+
use crate::test_client::TestClient;
16+
use parsec_client::error::Result;
1717
use parsec_interface::requests::{Opcode, ProviderID};
1818
use std::collections::HashSet;
1919
use uuid::Uuid;

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_client;

tests/per_provider/normal_tests/asym_sign_verify.rs

Lines changed: 33 additions & 14 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_client::error::{Error, Result};
16+
use crate::test_client::TestClient;
1617
use parsec_interface::operations::psa_algorithm::*;
1718
use parsec_interface::operations::psa_key_attributes::*;
18-
use parsec_interface::requests::{ResponseStatus, Result};
19+
use parsec_interface::requests::ResponseStatus;
1920
use sha2::{Digest, Sha256};
2021

2122
const HASH: [u8; 32] = [
@@ -30,7 +31,7 @@ fn asym_sign_no_key() {
3031
let status = client
3132
.sign_with_rsa_sha256(key_name, HASH.to_vec())
3233
.expect_err("Key should not exist.");
33-
assert_eq!(status, ResponseStatus::PsaErrorDoesNotExist);
34+
assert_eq!(status, Error::Service(ResponseStatus::PsaErrorDoesNotExist));
3435
}
3536

3637
#[test]
@@ -41,7 +42,7 @@ fn asym_verify_no_key() {
4142
let status = client
4243
.verify_with_rsa_sha256(key_name, HASH.to_vec(), signature)
4344
.expect_err("Verification should have failed");
44-
assert_eq!(status, ResponseStatus::PsaErrorDoesNotExist);
45+
assert_eq!(status, Error::Service(ResponseStatus::PsaErrorDoesNotExist));
4546
}
4647

4748
#[test]
@@ -67,8 +68,8 @@ fn asym_verify_fail() -> Result<()> {
6768
let status = client
6869
.verify_with_rsa_sha256(key_name, HASH.to_vec(), signature)
6970
.expect_err("Verification should fail.");
70-
if !(status == ResponseStatus::PsaErrorInvalidSignature
71-
|| status == ResponseStatus::PsaErrorCorruptionDetected)
71+
if !(status == Error::Service(ResponseStatus::PsaErrorInvalidSignature)
72+
|| status == Error::Service(ResponseStatus::PsaErrorCorruptionDetected))
7273
{
7374
panic!("An invalid signature or a tampering detection should be the only reasons of the verification failing.");
7475
} else {
@@ -171,7 +172,7 @@ fn sign_hash_not_permitted() -> Result<()> {
171172

172173
let status = client.sign_with_rsa_sha256(key_name, hash).unwrap_err();
173174

174-
assert_eq!(status, ResponseStatus::PsaErrorNotPermitted);
175+
assert_eq!(status, Error::Service(ResponseStatus::PsaErrorNotPermitted));
175176

176177
Ok(())
177178
}
@@ -190,8 +191,14 @@ fn sign_hash_bad_format() -> Result<()> {
190191
.unwrap_err();
191192
let status2 = client.sign_with_rsa_sha256(key_name, hash2).unwrap_err();
192193

193-
assert_eq!(status1, ResponseStatus::PsaErrorInvalidArgument);
194-
assert_eq!(status2, ResponseStatus::PsaErrorInvalidArgument);
194+
assert_eq!(
195+
status1,
196+
Error::Service(ResponseStatus::PsaErrorInvalidArgument)
197+
);
198+
assert_eq!(
199+
status2,
200+
Error::Service(ResponseStatus::PsaErrorInvalidArgument)
201+
);
195202
Ok(())
196203
}
197204

@@ -247,7 +254,7 @@ fn verify_hash_not_permitted() -> Result<()> {
247254
.verify_with_rsa_sha256(key_name, hash, signature)
248255
.unwrap_err();
249256

250-
assert_eq!(status, ResponseStatus::PsaErrorNotPermitted);
257+
assert_eq!(status, Error::Service(ResponseStatus::PsaErrorNotPermitted));
251258
Ok(())
252259
}
253260

@@ -271,8 +278,14 @@ fn verify_hash_bad_format() -> Result<()> {
271278
.verify_with_rsa_sha256(key_name, hash2, signature)
272279
.unwrap_err();
273280

274-
assert_eq!(status1, ResponseStatus::PsaErrorInvalidArgument);
275-
assert_eq!(status2, ResponseStatus::PsaErrorInvalidArgument);
281+
assert_eq!(
282+
status1,
283+
Error::Service(ResponseStatus::PsaErrorInvalidArgument)
284+
);
285+
assert_eq!(
286+
status2,
287+
Error::Service(ResponseStatus::PsaErrorInvalidArgument)
288+
);
276289
Ok(())
277290
}
278291

@@ -293,7 +306,10 @@ fn fail_verify_hash() -> Result<()> {
293306
let status = client
294307
.verify_with_rsa_sha256(key_name, hash, signature)
295308
.unwrap_err();
296-
assert_eq!(status, ResponseStatus::PsaErrorInvalidSignature);
309+
assert_eq!(
310+
status,
311+
Error::Service(ResponseStatus::PsaErrorInvalidSignature)
312+
);
297313
Ok(())
298314
}
299315

@@ -314,6 +330,9 @@ fn fail_verify_hash2() -> Result<()> {
314330
let status = client
315331
.verify_with_rsa_sha256(key_name, hash, signature)
316332
.unwrap_err();
317-
assert_eq!(status, ResponseStatus::PsaErrorInvalidSignature);
333+
assert_eq!(
334+
status,
335+
Error::Service(ResponseStatus::PsaErrorInvalidSignature)
336+
);
318337
Ok(())
319338
}

tests/per_provider/normal_tests/auth.rs

Lines changed: 8 additions & 7 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_client::TestClient;
16+
use parsec_client::error::{Error, Result};
17+
use parsec_interface::requests::ResponseStatus;
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())?;
@@ -43,7 +44,7 @@ fn delete_wrong_key() -> Result<()> {
4344
let status = client
4445
.destroy_key(key_name)
4546
.expect_err("Destroying key should have failed");
46-
assert_eq!(status, ResponseStatus::PsaErrorDoesNotExist);
47+
assert_eq!(status, Error::Service(ResponseStatus::PsaErrorDoesNotExist));
4748

4849
Ok(())
4950
}

tests/per_provider/normal_tests/basic.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
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_client::error::Error;
16+
use crate::test_client::RawRequestClient;
17+
use crate::test_client::TestClient;
1718
use parsec_interface::requests::request::RawHeader;
1819
use parsec_interface::requests::{Opcode, ProviderID, ResponseStatus};
1920

2021
#[test]
2122
fn invalid_version() {
22-
let mut client = RequestTestClient::new();
23+
let mut client = RawRequestClient {};
2324
let mut req_hdr = RawHeader::new();
2425

2526
req_hdr.provider = ProviderID::Core as u8;
2627
req_hdr.opcode = Opcode::Ping as u16;
27-
req_hdr.version_maj = 0xff;
2828

2929
let resp = client
3030
.send_raw_request(req_hdr, Vec::new())
@@ -38,12 +38,11 @@ fn invalid_version() {
3838

3939
#[test]
4040
fn invalid_provider() {
41-
let mut client = RequestTestClient::new();
41+
let mut client = RawRequestClient {};
4242
let mut req_hdr = RawHeader::new();
4343

4444
req_hdr.provider = 0xff;
4545
req_hdr.opcode = Opcode::Ping as u16;
46-
req_hdr.version_maj = 0x01;
4746

4847
let resp = client
4948
.send_raw_request(req_hdr, Vec::new())
@@ -54,12 +53,11 @@ fn invalid_provider() {
5453

5554
#[test]
5655
fn invalid_content_type() {
57-
let mut client = RequestTestClient::new();
56+
let mut client = RawRequestClient {};
5857
let mut req_hdr = RawHeader::new();
5958

6059
req_hdr.provider = ProviderID::Core as u8;
6160
req_hdr.opcode = Opcode::Ping as u16;
62-
req_hdr.version_maj = 1;
6361
req_hdr.content_type = 0xff;
6462

6563
let resp = client
@@ -71,12 +69,11 @@ fn invalid_content_type() {
7169

7270
#[test]
7371
fn invalid_accept_type() {
74-
let mut client = RequestTestClient::new();
72+
let mut client = RawRequestClient {};
7573
let mut req_hdr = RawHeader::new();
7674

7775
req_hdr.provider = ProviderID::Core as u8;
7876
req_hdr.opcode = Opcode::Ping as u16;
79-
req_hdr.version_maj = 1;
8077

8178
req_hdr.accept_type = 0xff;
8279

@@ -89,12 +86,11 @@ fn invalid_accept_type() {
8986

9087
#[test]
9188
fn invalid_body_len() {
92-
let mut client = RequestTestClient::new();
89+
let mut client = RawRequestClient {};
9390
let mut req_hdr = RawHeader::new();
9491

9592
req_hdr.provider = ProviderID::Core as u8;
9693
req_hdr.opcode = Opcode::Ping as u16;
97-
req_hdr.version_maj = 1;
9894

9995
req_hdr.body_len = 0xff_ff;
10096

@@ -106,12 +102,11 @@ fn invalid_body_len() {
106102

107103
#[test]
108104
fn invalid_auth_len() {
109-
let mut client = RequestTestClient::new();
105+
let mut client = RawRequestClient {};
110106
let mut req_hdr = RawHeader::new();
111107

112108
req_hdr.provider = ProviderID::Core as u8;
113109
req_hdr.opcode = Opcode::Ping as u16;
114-
req_hdr.version_maj = 1;
115110

116111
req_hdr.auth_len = 0xff_ff;
117112

@@ -123,12 +118,11 @@ fn invalid_auth_len() {
123118

124119
#[test]
125120
fn invalid_opcode() {
126-
let mut client = RequestTestClient::new();
121+
let mut client = RawRequestClient {};
127122
let mut req_hdr = RawHeader::new();
128123

129124
req_hdr.provider = ProviderID::Core as u8;
130125
req_hdr.opcode = 0xff_ff;
131-
req_hdr.version_maj = 1;
132126

133127
let resp = client
134128
.send_raw_request(req_hdr, Vec::new())
@@ -144,5 +138,8 @@ fn wrong_provider_core() {
144138
let response_status = client
145139
.destroy_key(String::new())
146140
.expect_err("Core Provider should not support DestroyKey operation!");
147-
assert_eq!(response_status, ResponseStatus::PsaErrorNotSupported);
141+
assert_eq!(
142+
response_status,
143+
Error::Service(ResponseStatus::PsaErrorNotSupported)
144+
);
148145
}

0 commit comments

Comments
 (0)