Skip to content
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

Add test for authoritzation and limits #12

Open
Sjors opened this issue Jul 9, 2024 · 0 comments
Open

Add test for authoritzation and limits #12

Sjors opened this issue Jul 9, 2024 · 0 comments

Comments

@Sjors
Copy link

Sjors commented Jul 9, 2024

The more tests the better of course, but this like the most security critical part:

// Check event is valid
if event.verify().is_err() {
info!("Event {} is invalid", event.id.to_hex());
continue;
}
// info!("Got event: {:?}", serde_json::to_string_pretty(&event));
// Check event is from correct pubkey
if event.pubkey.ne(&connect_client_keys.public_key()) {
// TODO: Should respond with unauth
info!("Event from incorrect pubkey: {}", event.pubkey.to_string());
continue;
}
// Decrypt bolt11 from content (NIP04)
let content = match decrypt(
&keys.secret_key()?,
&connect_client_keys.public_key(),
&event.content,
) {
Ok(content) => content,
Err(err) => {
info!("Could not decrypt: {err}");
continue;
}
};
// info!("Decrypted Content: {:?}", content);
let request = match nip47::Request::from_json(&content) {
Ok(req) => req,
Err(err) => {
warn!("Could not decode request {:?}", err);
continue;
}
};
// info!("request: {:?}", request);
let event_builder = match request.params {
nip47::RequestParams::PayInvoice(pay_invoice_param) => {
handle_pay_invoice(
&event,
&keys,
pay_invoice_param,
cln_client.clone(),
limits.clone(),

Maybe these lines can go in a helper function and then the tests can check that it returns true / false depending on some test vectors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant