Skip to content

Commit de36913

Browse files
committed
Merge branch 'release/0.1.1'
2 parents 11fdd51 + a812cb8 commit de36913

File tree

5 files changed

+108
-3
lines changed

5 files changed

+108
-3
lines changed

pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>org.cryptomator</groupId>
77
<artifactId>integrations-linux</artifactId>
8-
<version>0.1.0</version>
8+
<version>0.1.1</version>
99

1010
<name>integrations-linux</name>
1111
<description>Provides optional Linux services used by Cryptomator</description>
@@ -43,6 +43,7 @@
4343
<kdewallet.version>1.1.1</kdewallet.version>
4444
<guava.version>30.0-jre</guava.version>
4545
<slf4j.version>1.7.30</slf4j.version>
46+
<junit.version>5.7.0</junit.version>
4647
</properties>
4748

4849
<repositories>
@@ -86,6 +87,12 @@
8687
<artifactId>kdewallet</artifactId>
8788
<version>${kdewallet.version}</version>
8889
</dependency>
90+
<dependency>
91+
<groupId>org.junit.jupiter</groupId>
92+
<artifactId>junit-jupiter</artifactId>
93+
<version>${junit.version}</version>
94+
<scope>test</scope>
95+
</dependency>
8996
</dependencies>
9097

9198
<build>

src/main/java/org/cryptomator/linux/keychain/KDEWalletKeychainAccess.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,17 @@ public class KDEWalletKeychainAccess implements KeychainAccessProvider {
2424
public KDEWalletKeychainAccess() {
2525
ConnectedWallet wallet = null;
2626
try {
27-
DBusConnection conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
27+
DBusConnection conn = null;
28+
try {
29+
conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SESSION);
30+
} catch (RuntimeException e) {
31+
if (e.getMessage() == "Cannot Resolve Session Bus Address") {
32+
LOG.warn("SESSION DBus not found.");
33+
}
34+
}
35+
if (conn == null) {
36+
conn = DBusConnection.getConnection(DBusConnection.DBusBusType.SYSTEM);
37+
}
2838
wallet = new ConnectedWallet(conn);
2939
} catch (DBusException e) {
3040
LOG.warn("Connecting to D-Bus failed.", e);

src/main/java/org/cryptomator/linux/keychain/SecretServiceKeychainAccess.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public boolean isSupported() {
1818
try (@SuppressWarnings("unused") SimpleCollection keyring = new SimpleCollection()) {
1919
// seems like we're able to access the keyring.
2020
return true;
21-
} catch (IOException | RuntimeException e) {
21+
} catch (IOException | ExceptionInInitializerError | RuntimeException e) {
2222
return false;
2323
}
2424
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.cryptomator.linux.keychain;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.condition.EnabledOnOs;
7+
import org.junit.jupiter.api.condition.OS;
8+
9+
import java.io.IOException;
10+
import java.util.List;
11+
import java.util.concurrent.TimeUnit;
12+
13+
/**
14+
* Unit tests for KWallet access via DBUS.
15+
*/
16+
@EnabledOnOs(OS.LINUX)
17+
public class KDEWalletKeychainAccessTest {
18+
19+
private static boolean isInstalled;
20+
21+
@BeforeAll
22+
public static void checkSystemAndSetup() throws IOException {
23+
ProcessBuilder dbusSend = new ProcessBuilder("dbus-send","--print-reply","--dest=org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus.ListNames");
24+
ProcessBuilder grep = new ProcessBuilder("grep", "org.kde.kwallet");
25+
try {
26+
Process end = ProcessBuilder.startPipeline(List.of(dbusSend, grep)).get(1);
27+
if (end.waitFor(1000, TimeUnit.MILLISECONDS)) {
28+
isInstalled = end.exitValue() == 0;
29+
} else {
30+
isInstalled = false;
31+
}
32+
} catch (InterruptedException e) {
33+
Thread.currentThread().interrupt();
34+
}
35+
}
36+
37+
38+
@Test
39+
public void testIsSupported() {
40+
KDEWalletKeychainAccess keychainAccess = new KDEWalletKeychainAccess();
41+
Assertions.assertEquals(isInstalled, keychainAccess.isSupported());
42+
}
43+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.cryptomator.linux.keychain;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.BeforeAll;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.condition.EnabledOnOs;
7+
import org.junit.jupiter.api.condition.OS;
8+
9+
import java.io.IOException;
10+
import java.util.List;
11+
import java.util.concurrent.TimeUnit;
12+
13+
/**
14+
* Unit tests for GNOME keyring access via DBUS.
15+
*/
16+
@EnabledOnOs(OS.LINUX)
17+
public class SecretServiceKeychainAccessTest {
18+
19+
private static boolean isInstalled;
20+
21+
@BeforeAll
22+
public static void checkSystemAndSetup() throws IOException {
23+
ProcessBuilder dbusSend = new ProcessBuilder("dbus-send","--print-reply","--dest=org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus.ListNames");
24+
ProcessBuilder grep = new ProcessBuilder("grep", "org.gnome.keyring");
25+
try {
26+
Process end = ProcessBuilder.startPipeline(List.of(dbusSend, grep)).get(1);
27+
if (end.waitFor(1000, TimeUnit.MILLISECONDS)) {
28+
isInstalled = end.exitValue() == 0;
29+
} else {
30+
isInstalled = false;
31+
}
32+
} catch (InterruptedException e) {
33+
Thread.currentThread().interrupt();
34+
}
35+
}
36+
37+
38+
@Test
39+
public void testIsSupported(){
40+
SecretServiceKeychainAccess secretService = new SecretServiceKeychainAccess();
41+
Assertions.assertEquals(isInstalled, secretService.isSupported());
42+
}
43+
44+
45+
}

0 commit comments

Comments
 (0)