mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-08-16 11:20:28 +03:00
test that calls without __TAURI_INVOKE_KEY__ fail
This commit is contained in:
parent
8f759c6a81
commit
b4fc721417
9
Cargo.lock
generated
9
Cargo.lock
generated
@ -1921,6 +1921,15 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "invoke-key"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "io-lifetimes"
|
||||
version = "1.0.11"
|
||||
|
@ -13,7 +13,8 @@ members = [
|
||||
# integration tests
|
||||
"core/tests/restart",
|
||||
"core/tests/app-updater",
|
||||
"core/tests/uninitialized-ipc"
|
||||
"core/tests/uninitialized-ipc",
|
||||
"core/tests/invoke-key"
|
||||
]
|
||||
|
||||
exclude = [
|
||||
|
@ -1569,11 +1569,13 @@ impl<R: Runtime> Window<R> {
|
||||
return Err(Error::InvokeKey);
|
||||
}
|
||||
None => {
|
||||
let error = "received ipc message without a __TAURI_INVOKE_KEY__";
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
tracing::error!("received ipc message without a __TAURI_INVOKE_KEY__");
|
||||
tracing::error!(error);
|
||||
|
||||
#[cfg(not(feature = "tracing"))]
|
||||
eprintln!("received ipc message without a __TAURI_INVOKE_KEY__");
|
||||
eprintln!(error);
|
||||
|
||||
return Err(Error::InvokeKey);
|
||||
}
|
||||
|
15
core/tests/invoke-key/Cargo.toml
Normal file
15
core/tests/invoke-key/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "invoke-key"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { path = "../../tauri-build", features = [] }
|
||||
|
||||
[dependencies]
|
||||
tauri = { path = "../../tauri", features = ["tracing"] }
|
||||
tracing = "0.1"
|
||||
|
||||
[features]
|
||||
default = ["custom-protocol"]
|
||||
custom-protocol = ["tauri/custom-protocol"]
|
7
core/tests/invoke-key/build.rs
Normal file
7
core/tests/invoke-key/build.rs
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
fn main() {
|
||||
tauri_build::build()
|
||||
}
|
7
core/tests/invoke-key/index.html
Normal file
7
core/tests/invoke-key/index.html
Normal file
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
window.__TAURI_POST_MESSAGE__({
|
||||
cmd: 'error_if_called',
|
||||
callback: 0,
|
||||
error: 0
|
||||
})
|
||||
</script>
|
24
core/tests/invoke-key/src/main.rs
Normal file
24
core/tests/invoke-key/src/main.rs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use tauri::{command, generate_context, generate_handler, Builder};
|
||||
|
||||
mod subscriber;
|
||||
|
||||
#[command]
|
||||
fn error_if_called() {
|
||||
std::process::exit(1)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing::subscriber::set_global_default(subscriber::InvokeKeyErrorSubscriber)
|
||||
.expect("unable to set tracing global subscriber");
|
||||
|
||||
Builder::default()
|
||||
.invoke_handler(generate_handler![error_if_called])
|
||||
.run(generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
44
core/tests/invoke-key/src/subscriber.rs
Normal file
44
core/tests/invoke-key/src/subscriber.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use std::fmt::Debug;
|
||||
|
||||
use tracing::{
|
||||
field::{Field, Visit},
|
||||
span::{Attributes, Record},
|
||||
Event, Id, Level, Metadata, Subscriber,
|
||||
};
|
||||
|
||||
pub struct InvokeKeyErrorSubscriber;
|
||||
|
||||
impl Subscriber for InvokeKeyErrorSubscriber {
|
||||
fn enabled(&self, metadata: &Metadata<'_>) -> bool {
|
||||
metadata.is_event() && *metadata.level() == Level::ERROR
|
||||
}
|
||||
|
||||
fn new_span(&self, _: &Attributes<'_>) -> Id {
|
||||
// shouldn't be called because we only enable events
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn record(&self, _: &Id, _: &Record<'_>) {}
|
||||
|
||||
fn record_follows_from(&self, _: &Id, _: &Id) {}
|
||||
|
||||
fn event(&self, event: &Event<'_>) {
|
||||
event.record(&mut InvokeKeyExitVisit)
|
||||
}
|
||||
|
||||
fn enter(&self, _: &Id) {}
|
||||
|
||||
fn exit(&self, _: &Id) {}
|
||||
}
|
||||
|
||||
struct InvokeKeyExitVisit;
|
||||
|
||||
impl Visit for InvokeKeyExitVisit {
|
||||
fn record_str(&mut self, field: &Field, value: &str) {
|
||||
if field.name() == "error" && value == "received ipc message without a __TAURI_INVOKE_KEY__" {
|
||||
std::process::exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
fn record_debug(&mut self, _: &Field, _: &dyn Debug) {}
|
||||
}
|
10
core/tests/invoke-key/tauri.conf.json
Normal file
10
core/tests/invoke-key/tauri.conf.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"$schema": "../../../core/tauri-config-schema/schema.json",
|
||||
"build": {
|
||||
"distDir": "index.html",
|
||||
"devPath": "index.html"
|
||||
},
|
||||
"tauri": {
|
||||
"windows": [{}]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user