forked from swiesend/secret-service
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPromptTest.java
More file actions
94 lines (77 loc) · 3.17 KB
/
Copy pathPromptTest.java
File metadata and controls
94 lines (77 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package de.swiesend.secretservice.integration;
import de.swiesend.secretservice.Collection;
import de.swiesend.secretservice.Pair;
import de.swiesend.secretservice.Static;
import org.freedesktop.dbus.DBusPath;
import org.freedesktop.dbus.messages.DBusSignal;
import de.swiesend.secretservice.handlers.SignalHandler;
import de.swiesend.secretservice.interfaces.Prompt;
import de.swiesend.secretservice.integration.test.Context;
import org.junit.jupiter.api.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static de.swiesend.secretservice.Static.DEFAULT_PROMPT_TIMEOUT;
import static de.swiesend.secretservice.Static.ObjectPaths.DEFAULT_COLLECTION;
import static org.junit.jupiter.api.Assertions.*;
public class PromptTest {
private Logger log = LoggerFactory.getLogger(getClass());
private Context context;
@BeforeEach
public void beforeEach(TestInfo info) {
log.info(info.getDisplayName());
context = new Context(log);
context.ensureCollection();
}
@AfterEach
public void afterEach() {
context.after();
}
@Test
@Disabled
public void prompt() {
DBusPath defaultCollection = Static.Convert.toObjectPath(DEFAULT_COLLECTION);
ArrayList<DBusPath> cs = new ArrayList<>();
cs.add(defaultCollection);
log.info("lock default collection");
Pair<List<DBusPath>, DBusPath> locked = context.service.lock(cs).get();
log.info(locked.toString());
log.info("unlock default collection");
Pair<List<DBusPath>, DBusPath> unlocked = context.service.unlock(cs).get();
log.info(unlocked.toString());
DBusPath prompt = unlocked.b;
Prompt.Completed completed = context.prompt.await(prompt, DEFAULT_PROMPT_TIMEOUT);
assertNotNull(completed);
}
@Test
@Disabled("Depends on timing and default collection lock.")
public void dismissPrompt() throws InterruptedException {
List<DBusPath> cs = Arrays.asList(context.collection.getPath());
context.service.lock(cs);
SignalHandler handler = context.prompt.getSignalHandler();
Collection defaultCollection = new Collection("login", context.service.getConnection());
boolean expected = defaultCollection.isLocked();
Thread.sleep(500L);
Pair<List<DBusPath>, DBusPath> response = context.service.unlock(cs).get();
DBusPath prompt = response.b;
assertDoesNotThrow(() ->context.prompt.prompt(prompt)); // Should not throw NoSuchObject
DBusSignal signal = handler.getLastHandledSignal();
Thread.sleep(500L);
assertFalse(signal instanceof Prompt.Completed);
context.prompt.dismiss();
Thread.sleep(500L); // await signal
Prompt.Completed completed = handler.getLastHandledSignal(Prompt.Completed.class, prompt.getPath());
assertNotNull(completed);
assertEquals(expected, completed.dismissed);
}
@Test
public void isRemote() {
assertFalse(context.prompt.isRemote());
}
@Test
public void getObjectPath() {
assertEquals("/", context.prompt.getObjectPath());
}
}