Skip to content

Commit eaa880b

Browse files
committed
add tests for isSupported() method of two keychain access implementations
1 parent 25c4bc5 commit eaa880b

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

pom.xml

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

0 commit comments

Comments
 (0)