feat: Handle default database paths better (#878)
* return the path in the error message * specify defaults for `decrypt()` and `subscribe()` Closes #868
This commit is contained in:
Родитель
175573d6e6
Коммит
9c0a37f43b
|
@ -6,6 +6,10 @@
|
|||
|
||||
## Push
|
||||
|
||||
### What's new
|
||||
|
||||
- PushAPI now defines a number of default parameters for functions ([#868](https://github.com/mozilla/application-services/issues/868))
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- `mozilla.appservices.push.BridgeTypes` is now
|
||||
|
|
|
@ -290,12 +290,12 @@ interface PushAPI : java.lang.AutoCloseable {
|
|||
* Get the Subscription Info block
|
||||
*
|
||||
* @param channelID Channel ID (UUID4) for new subscription, either pre-generated or "" and one will be created.
|
||||
* @param scope Site scope string.
|
||||
* @param scope Site scope string (defaults to "" for no site scope string).
|
||||
* @return a SubscriptionInfo structure
|
||||
*/
|
||||
fun subscribe(
|
||||
channelID: String = "",
|
||||
scope: String
|
||||
scope: String = ""
|
||||
): SubscriptionInfo
|
||||
|
||||
/**
|
||||
|
@ -342,17 +342,17 @@ interface PushAPI : java.lang.AutoCloseable {
|
|||
*
|
||||
* @param channelID: the ChannelID (included in the envelope of the message)
|
||||
* @param body: The encrypted body of the message
|
||||
* @param encoding: The Content Encoding "enc" field of the message
|
||||
* @param salt: The "salt" field (if present in the raw message)
|
||||
* @param dh: the "dh" field (if present in the raw message)
|
||||
* @param encoding: The Content Encoding "enc" field of the message (defaults to "aes128gcm")
|
||||
* @param salt: The "salt" field (if present in the raw message, defaults to "")
|
||||
* @param dh: the "dh" field (if present in the raw message, defaults to "")
|
||||
* @return Decrypted message body.
|
||||
*/
|
||||
fun decrypt(
|
||||
channelID: String,
|
||||
body: String,
|
||||
encoding: String,
|
||||
salt: String,
|
||||
dh: String
|
||||
encoding: String = "aes128gcm",
|
||||
salt: String = "",
|
||||
dh: String = ""
|
||||
): ByteArray
|
||||
|
||||
/** get the dispatch info for a given subscription channel
|
||||
|
|
|
@ -211,4 +211,18 @@ class PushTest {
|
|||
assertEquals("uaid", "abad1d3a00000000aabbccdd00000000", dispatch.uaid)
|
||||
assertEquals("scope", "foo", dispatch.scope)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testValidPath() {
|
||||
try {
|
||||
PushManager(
|
||||
senderId = mockSenderId,
|
||||
bridgeType = BridgeType.TEST,
|
||||
registrationId = "TestRegistrationId",
|
||||
databasePath = "/dev/false"
|
||||
)
|
||||
} catch (e: PushError) {
|
||||
assert(e is StorageError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::{ops::Deref, path::Path};
|
|||
use rusqlite::Connection;
|
||||
use sql_support::ConnExt;
|
||||
|
||||
use push_errors::Result;
|
||||
use push_errors::{ErrorKind, Result};
|
||||
|
||||
use crate::{record::PushRecord, schema};
|
||||
|
||||
|
@ -39,7 +39,16 @@ impl PushDb {
|
|||
}
|
||||
|
||||
pub fn open(path: impl AsRef<Path>) -> Result<Self> {
|
||||
Ok(Self::with_connection(Connection::open(path)?)?)
|
||||
// By default, file open errors are StorageSqlErrors and aren't super helpful.
|
||||
// Instead, remap to StorageError and provide the path to the file that couldn't be opened.
|
||||
Ok(Self::with_connection(Connection::open(&path).map_err(
|
||||
|_| {
|
||||
ErrorKind::StorageError(format!(
|
||||
"Could not open database file {:?}",
|
||||
&path.as_ref().as_os_str()
|
||||
))
|
||||
},
|
||||
)?)?)
|
||||
}
|
||||
|
||||
pub fn open_in_memory() -> Result<Self> {
|
||||
|
|
Загрузка…
Ссылка в новой задаче