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

Remove Sled crypto store, use SQLite by default #330

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const accessToken = creds?.['accessToken'] ?? 'YOUR_TOKEN';
const storage = new SimpleFsStorageProvider("./examples/storage/bot.json");
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/bot_sled", StoreType.Sled);
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/bot_sqlite", StoreType.Sqlite);

const client = new MatrixClient(homeserverUrl, accessToken, storage, crypto);
AutojoinRoomsMixin.setupOnClient(client);
Expand Down
2 changes: 1 addition & 1 deletion examples/encryption_appservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ try {
const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const storage = new SimpleFsStorageProvider("./examples/storage/encryption_appservice.json");
const crypto = new RustSdkAppserviceCryptoStorageProvider("./examples/storage/encryption_appservice_sled", StoreType.Sled);
const crypto = new RustSdkAppserviceCryptoStorageProvider("./examples/storage/encryption_appservice_sqlite", StoreType.Sqlite);
const worksImage = fs.readFileSync("./examples/static/it-works.png");

const registration: IAppserviceRegistration = {
Expand Down
2 changes: 1 addition & 1 deletion examples/encryption_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const dmTarget = creds?.['dmTarget'] ?? "@admin:localhost";
const homeserverUrl = creds?.['homeserverUrl'] ?? "http://localhost:8008";
const accessToken = creds?.['accessToken'] ?? 'YOUR_TOKEN';
const storage = new SimpleFsStorageProvider("./examples/storage/encryption_bot.json");
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/encryption_bot_sled", StoreType.Sled);
const crypto = new RustSdkCryptoStorageProvider("./examples/storage/encryption_bot_sqlite", StoreType.Sqlite);
const worksImage = fs.readFileSync("./examples/static/it-works.png");

const client = new MatrixClient(homeserverUrl, accessToken, storage, crypto);
Expand Down
4 changes: 2 additions & 2 deletions src/storage/RustSdkCryptoStorageProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class RustSdkCryptoStorageProvider implements ICryptoStorageProvider {
*/
public constructor(
public readonly storagePath: string,
public readonly storageType: RustSdkCryptoStoreType = RustSdkCryptoStoreType.Sled,
public readonly storageType: RustSdkCryptoStoreType = RustSdkCryptoStoreType.Sqlite,
) {
this.storagePath = path.resolve(this.storagePath);
mkdirp.sync(storagePath);
Expand Down Expand Up @@ -69,7 +69,7 @@ export class RustSdkAppserviceCryptoStorageProvider extends RustSdkCryptoStorage
* @param baseStoragePath The *directory* to persist database details to.
* @param storageType The storage type to use. Must be supported by the rust-sdk.
*/
public constructor(private baseStoragePath: string, storageType: RustSdkCryptoStoreType = RustSdkCryptoStoreType.Sled) {
public constructor(private baseStoragePath: string, storageType: RustSdkCryptoStoreType = RustSdkCryptoStoreType.Sqlite) {
super(path.join(baseStoragePath, "_default"), storageType);
}

Expand Down
7 changes: 3 additions & 4 deletions test/MatrixClientTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as tmp from "tmp";
import * as simple from "simple-mock";
import { StoreType } from "@matrix-org/matrix-sdk-crypto-nodejs";

import {
EventKind,
Expand Down Expand Up @@ -48,13 +47,13 @@ describe('MatrixClient', () => {
expect(client.accessToken).toEqual(accessToken);
});

it('should create a crypto client when requested', () => {
it('should create a crypto client when requested', () => testCryptoStores(async (cryptoStoreType) => {
const homeserverUrl = "https://example.org";
const accessToken = "example_token";

const client = new MatrixClient(homeserverUrl, accessToken, null, new RustSdkCryptoStorageProvider(tmp.dirSync().name, StoreType.Sled));
const client = new MatrixClient(homeserverUrl, accessToken, null, new RustSdkCryptoStorageProvider(tmp.dirSync().name, cryptoStoreType));
expect(client.crypto).toBeDefined();
});
}));

it('should NOT create a crypto client when requested', () => {
const homeserverUrl = "https://example.org";
Expand Down
4 changes: 2 additions & 2 deletions test/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export function createTestClient(
const http = new HttpBackend();
const hsUrl = "https://localhost";
const accessToken = "s3cret";
const client = new MatrixClient(hsUrl, accessToken, storage, cryptoStoreType !== undefined ? new RustSdkCryptoStorageProvider(tmp.dirSync().name, cryptoStoreType) : null);
const client = new MatrixClient(hsUrl, accessToken, storage, (cryptoStoreType !== undefined) ? new RustSdkCryptoStorageProvider(tmp.dirSync().name, cryptoStoreType) : null);
(<any>client).userId = userId; // private member access
setRequestFn(http.requestFn);

return { http, hsUrl, accessToken, client };
}

const CRYPTO_STORE_TYPES = [StoreType.Sled, StoreType.Sqlite];
const CRYPTO_STORE_TYPES: StoreType[] = [StoreType.Sqlite];

export async function testCryptoStores(fn: (StoreType) => Promise<void>): Promise<void> {
for (const st of CRYPTO_STORE_TYPES) {
Expand Down
2 changes: 1 addition & 1 deletion test/appservice/IntentTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ describe('Intent', () => {

beforeEach(() => {
storage = new MemoryStorageProvider();
cryptoStorage = new RustSdkAppserviceCryptoStorageProvider(tmp.dirSync().name, StoreType.Sled);
cryptoStorage = new RustSdkAppserviceCryptoStorageProvider(tmp.dirSync().name, StoreType.Sqlite);
options = {
homeserverUrl: hsUrl,
storage: storage,
Expand Down