Skip to content

Commit b803eb5

Browse files
committed
fixup! Add jwt- and signature-based headers
pem file handling appropriate headers for vss store unit test
1 parent c278ddb commit b803eb5

6 files changed

Lines changed: 37 additions & 27 deletions

File tree

.github/workflows/vss-integration.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,7 @@ jobs:
4545
if [ "${{ matrix.authorizer }}" == "noop" ]; then
4646
RUSTFLAGS="--cfg noop_authorizer" cargo run --release --no-default-features server/vss-server-config.toml &
4747
elif [ "${{ matrix.authorizer }}" == "jwt" ]; then
48-
export VSS_JWT_RSA_PEM=$(cat <<'EOF'
49-
-----BEGIN PUBLIC KEY-----
50-
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAriGCSdXczZrnLX84/luB
51-
HiV4nPwOoJByTkuzB6gKjqjIOPWmXzo+suJJoVN/32peTnHCeNvfaIUpyazCsFqC
52-
+WB2A9WO+NhM/7a6YxE01egsI4S6LwlbVm2a44r1J2G9XxHhqEPKfgjjisjDN7P4
53-
kFZYc6qPOpGfX3GhhYs68pHEYpkgzrjd1fwFnAd33Crny0u+s+srDU8Iil/8JwVB
54-
LaHwCyFdYva3MhabpkRov/ZaPNHlXAtUxK8QNwuSBMCUNfFwmrTNh39sYuA9+SQy
55-
vNP9DGN7u0yYGKxaWk4bind5Z0kj8edXpyVBGjYF7lDb03SpBRJ9QEkYuSzWzSyo
56-
VwIDAQAB
57-
-----END PUBLIC KEY-----
58-
EOF
59-
)
48+
export VSS_JWT_RSA_PEM=$(cat ../../ldk-node/tests/fixtures/vss_jwt_rsa_pub.pem)
6049
cargo run --release server/vss-server-config.toml &
6150
else
6251
cargo run --release server/vss-server-config.toml &
@@ -66,6 +55,6 @@ EOF
6655
run: |
6756
cd ldk-node
6857
export TEST_VSS_BASE_URL="http://localhost:8080/vss"
69-
RUSTFLAGS="--cfg vss_test --cfg ${{ matrix.authorizer }}_auth_test" cargo test io::vss_store
58+
RUSTFLAGS="--cfg vss_test --cfg ${{ matrix.authorizer }}_auth_test" cargo test --features test_utils io::vss_store
7059
RUSTFLAGS="--cfg vss_test --cfg cycle_tests --cfg ${{ matrix.authorizer }}_auth_test" cargo test \
7160
--features test_utils --test integration_tests_vss

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ panic = 'abort' # Abort on panic
2525

2626
[features]
2727
default = []
28-
test_utils = ["jsonwebtoken"]
28+
test_utils = ["jsonwebtoken", "lightning/_test_utils"]
2929

3030
[dependencies]
3131
#lightning = { version = "0.2.0", features = ["std"] }

src/io/test_utils.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::future::Future;
1212
use std::panic::RefUnwindSafe;
1313
use std::path::PathBuf;
1414
use std::sync::Mutex;
15+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
1516
use std::time::SystemTime;
1617

1718
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
@@ -29,6 +30,7 @@ use lightning::util::test_utils;
2930
use lightning::{check_closed_broadcast, io};
3031
use rand::distr::Alphanumeric;
3132
use rand::{rng, Rng};
33+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
3234
use serde::{Deserialize, Serialize};
3335

3436
type TestMonitorUpdatePersister<'a, K> = MonitorUpdatingPersister<
@@ -41,7 +43,7 @@ type TestMonitorUpdatePersister<'a, K> = MonitorUpdatingPersister<
4143
>;
4244

4345
const EXPECTED_UPDATES_PER_PAYMENT: u64 = 5;
44-
#[cfg(jwt_auth_test)]
46+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
4547
pub const VSS_PRIVATE_PEM: &str = r#"
4648
-----BEGIN PRIVATE KEY-----
4749
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCuIYJJ1dzNmuct
@@ -388,7 +390,7 @@ pub(crate) fn do_test_store<K: KVStoreSync + Sync>(store_0: &K, store_1: &K) {
388390
check_persisted_data!(persister_0_max_pending_updates * 2 * EXPECTED_UPDATES_PER_PAYMENT + 1);
389391
}
390392

391-
#[cfg(jwt_auth_test)]
393+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
392394
#[derive(Serialize, Deserialize)]
393395
struct TestClaims {
394396
sub: String,
@@ -397,7 +399,7 @@ struct TestClaims {
397399
exp: i64,
398400
}
399401

400-
#[cfg(jwt_auth_test)]
402+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
401403
pub fn generate_test_jwt(private_pem: &str, user_id: &str) -> String {
402404
let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs() as i64;
403405

@@ -416,7 +418,7 @@ pub fn get_fixed_headers() -> HashMap<String, String> {
416418
{
417419
return HashMap::new();
418420
}
419-
#[cfg(jwt_auth_test)]
421+
#[cfg(all(jwt_auth_test, feature = "test_utils"))]
420422
{
421423
let token = generate_test_jwt(VSS_PRIVATE_PEM, "test");
422424
let mut headers = HashMap::new();
@@ -429,6 +431,6 @@ pub fn get_fixed_headers() -> HashMap<String, String> {
429431
todo!()
430432
}
431433

432-
#[cfg(not(any(noop_auth_test, jwt_auth_test, sig_auth_test)))]
434+
#[cfg(not(any(noop_auth_test, all(jwt_auth_test, feature = "test_utils"), sig_auth_test)))]
433435
HashMap::new()
434436
}

src/io/vss_store.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ mod tests {
969969
use vss_client::headers::FixedHeaders;
970970

971971
use super::*;
972-
use crate::io::test_utils::{do_read_write_remove_list_persist, get_header_provider};
972+
use crate::io::test_utils::{do_read_write_remove_list_persist, get_fixed_headers};
973973

974974
#[test]
975975
fn vss_read_write_remove_list_persist() {
@@ -978,9 +978,14 @@ mod tests {
978978
let rand_store_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
979979
let mut vss_seed = [0u8; 32];
980980
rng.fill_bytes(&mut vss_seed);
981-
let header_provider = get_header_provider();
982-
let vss_store =
983-
VssStore::new(vss_base_url, rand_store_id, vss_seed, header_provider).unwrap();
981+
let header_provider = get_fixed_headers();
982+
let vss_store = VssStore::new(
983+
vss_base_url,
984+
rand_store_id,
985+
vss_seed,
986+
Arc::new(FixedHeaders::new(header_provider)),
987+
)
988+
.unwrap();
984989
do_read_write_remove_list_persist(&vss_store);
985990
}
986991

@@ -991,9 +996,14 @@ mod tests {
991996
let rand_store_id: String = (0..7).map(|_| rng.sample(Alphanumeric) as char).collect();
992997
let mut vss_seed = [0u8; 32];
993998
rng.fill_bytes(&mut vss_seed);
994-
let header_provider = get_header_provider();
995-
let vss_store =
996-
VssStore::new(vss_base_url, rand_store_id, vss_seed, header_provider).unwrap();
999+
let header_provider = get_fixed_headers();
1000+
let vss_store = VssStore::new(
1001+
vss_base_url,
1002+
rand_store_id,
1003+
vss_seed,
1004+
Arc::new(FixedHeaders::new(header_provider)),
1005+
)
1006+
.unwrap();
9971007

9981008
do_read_write_remove_list_persist(&vss_store);
9991009
drop(vss_store)

tests/fixtures/vss_jwt_rsa_pub.pem

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-----BEGIN PUBLIC KEY-----
2+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAriGCSdXczZrnLX84/luB
3+
HiV4nPwOoJByTkuzB6gKjqjIOPWmXzo+suJJoVN/32peTnHCeNvfaIUpyazCsFqC
4+
+WB2A9WO+NhM/7a6YxE01egsI4S6LwlbVm2a44r1J2G9XxHhqEPKfgjjisjDN7P4
5+
kFZYc6qPOpGfX3GhhYs68pHEYpkgzrjd1fwFnAd33Crny0u+s+srDU8Iil/8JwVB
6+
LaHwCyFdYva3MhabpkRov/ZaPNHlXAtUxK8QNwuSBMCUNfFwmrTNh39sYuA9+SQy
7+
vNP9DGN7u0yYGKxaWk4bind5Z0kj8edXpyVBGjYF7lDb03SpBRJ9QEkYuSzWzSyo
8+
VwIDAQAB
9+
-----END PUBLIC KEY-----

tests/integration_tests_vss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. You may not use this file except in
66
// accordance with one or both of these licenses.
77

8-
#![cfg(all(vss_test))]
8+
#![cfg(all(vss_test, feature = "test_utils"))]
99

1010
mod common;
1111

0 commit comments

Comments
 (0)