mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: expose safestorage backend information on linux (#39107)
* feat: expose safestorage backend information on linux Co-authored-by: deepak1556 <hop2deep@gmail.com> * Remove gnome-keyring Refs https://chromium-review.googlesource.com/c/chromium/src/+/4609704 Co-authored-by: deepak1556 <hop2deep@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
@@ -6,15 +6,6 @@ import { ifdescribe } from './lib/spec-helpers';
|
||||
import * as fs from 'fs-extra';
|
||||
import { once } from 'events';
|
||||
|
||||
/* isEncryptionAvailable returns false in Linux when running CI due to a mocked dbus. This stops
|
||||
* Chrome from reaching the system's keyring or libsecret. When running the tests with config.store
|
||||
* set to basic-text, a nullptr is returned from chromium, defaulting the available encryption to false.
|
||||
*
|
||||
* Because all encryption methods are gated by isEncryptionAvailable, the methods will never return the correct values
|
||||
* when run on CI and linux.
|
||||
* Refs: https://github.com/electron/electron/issues/30424.
|
||||
*/
|
||||
|
||||
describe('safeStorage module', () => {
|
||||
it('safeStorage before and after app is ready', async () => {
|
||||
const appPath = path.join(__dirname, 'fixtures', 'crash-cases', 'safe-storage');
|
||||
@@ -33,7 +24,13 @@ describe('safeStorage module', () => {
|
||||
});
|
||||
});
|
||||
|
||||
ifdescribe(process.platform !== 'linux')('safeStorage module', () => {
|
||||
describe('safeStorage module', () => {
|
||||
before(() => {
|
||||
if (process.platform === 'linux') {
|
||||
safeStorage.setUsePlainTextEncryption(true);
|
||||
}
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
const pathToEncryptedString = path.resolve(__dirname, 'fixtures', 'api', 'safe-storage', 'encrypted.txt');
|
||||
if (await fs.pathExists(pathToEncryptedString)) {
|
||||
@@ -47,6 +44,12 @@ ifdescribe(process.platform !== 'linux')('safeStorage module', () => {
|
||||
});
|
||||
});
|
||||
|
||||
ifdescribe(process.platform === 'linux')('SafeStorage.getSelectedStorageBackend()', () => {
|
||||
it('should return a valid backend', () => {
|
||||
expect(safeStorage.getSelectedStorageBackend()).to.equal('basic_text');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SafeStorage.encryptString()', () => {
|
||||
it('valid input should correctly encrypt string', () => {
|
||||
const plaintext = 'plaintext';
|
||||
@@ -87,6 +90,7 @@ ifdescribe(process.platform !== 'linux')('safeStorage module', () => {
|
||||
}).to.throw(Error);
|
||||
});
|
||||
});
|
||||
|
||||
describe('safeStorage persists encryption key across app relaunch', () => {
|
||||
it('can decrypt after closing and reopening app', async () => {
|
||||
const fixturesPath = path.resolve(__dirname, 'fixtures');
|
||||
|
||||
@@ -6,6 +6,9 @@ const pathToEncryptedString = path.resolve(__dirname, '..', 'encrypted.txt');
|
||||
const readFile = fs.readFile;
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
if (process.platform === 'linux') {
|
||||
safeStorage.setUsePlainTextEncryption(true);
|
||||
}
|
||||
const encryptedString = await readFile(pathToEncryptedString);
|
||||
const decrypted = safeStorage.decryptString(encryptedString);
|
||||
console.log(decrypted);
|
||||
|
||||
@@ -6,6 +6,9 @@ const pathToEncryptedString = path.resolve(__dirname, '..', 'encrypted.txt');
|
||||
const writeFile = fs.writeFile;
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
if (process.platform === 'linux') {
|
||||
safeStorage.setUsePlainTextEncryption(true);
|
||||
}
|
||||
const encrypted = safeStorage.encryptString('plaintext');
|
||||
const encryptedString = await writeFile(pathToEncryptedString, encrypted);
|
||||
app.quit();
|
||||
|
||||
Reference in New Issue
Block a user