|
@@ -22,33 +22,46 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.addons.identd;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.harness.TestConfigManagerMap;
|
26
|
|
-import com.dmdirc.config.IdentityManager;
|
|
25
|
+import com.dmdirc.Server;
|
|
26
|
+import com.dmdirc.ServerManager;
|
|
27
|
+import com.dmdirc.config.ConfigManager;
|
|
28
|
+import com.dmdirc.parser.irc.IRCClientInfo;
|
|
29
|
+import com.dmdirc.parser.irc.IRCParser;
|
|
30
|
+
|
|
31
|
+import java.util.ArrayList;
|
|
32
|
+import java.util.List;
|
27
|
33
|
|
28
|
|
-import org.junit.BeforeClass;
|
29
|
34
|
import org.junit.Test;
|
|
35
|
+
|
30
|
36
|
import static org.junit.Assert.*;
|
31
|
37
|
import static org.mockito.Mockito.*;
|
32
|
38
|
|
33
|
39
|
public class IdentClientTest {
|
34
|
40
|
|
35
|
|
- @BeforeClass
|
36
|
|
- public static void setUpClass() throws Exception {
|
37
|
|
- IdentityManager.getIdentityManager().initialise();
|
38
|
|
- }
|
39
|
|
-
|
40
|
41
|
protected IdentClient getClient() {
|
41
|
42
|
IdentdPlugin plugin = mock(IdentdPlugin.class);
|
|
43
|
+ ServerManager sm = mock(ServerManager.class);
|
|
44
|
+ Server server = mock(Server.class);
|
|
45
|
+ IRCParser parser = mock(IRCParser.class);
|
|
46
|
+ IRCClientInfo client = mock(IRCClientInfo.class);
|
|
47
|
+ final List<Server> servers = new ArrayList<Server>();
|
|
48
|
+ servers.add(server);
|
42
|
49
|
|
43
|
50
|
when(plugin.getDomain()).thenReturn("plugin-Identd");
|
44
|
|
-
|
45
|
|
- return new IdentClient(null, null, plugin);
|
|
51
|
+ when(sm.getServers()).thenReturn(servers);
|
|
52
|
+ when(server.getParser()).thenReturn(parser);
|
|
53
|
+ when(parser.getLocalPort()).thenReturn(60);
|
|
54
|
+ when(parser.getLocalClient()).thenReturn(client);
|
|
55
|
+ when(client.getNickname()).thenReturn("nickname");
|
|
56
|
+ when(client.getUsername()).thenReturn("username");
|
|
57
|
+
|
|
58
|
+ return new IdentClient(null, null, plugin, sm);
|
46
|
59
|
}
|
47
|
60
|
|
48
|
61
|
@Test
|
49
|
62
|
public void testInvalidIdent() {
|
50
|
|
- final String response = getClient().getIdentResponse("invalid request!",
|
51
|
|
- IdentityManager.getGlobalConfig());
|
|
63
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
64
|
+ final String response = getClient().getIdentResponse("invalid request!", cm);
|
52
|
65
|
|
53
|
66
|
assertContains("Illegal requests must result in an ERROR response",
|
54
|
67
|
response, "ERROR");
|
|
@@ -56,8 +69,8 @@ public class IdentClientTest {
|
56
|
69
|
|
57
|
70
|
@Test
|
58
|
71
|
public void testQuoting() {
|
59
|
|
- final String response = getClient().getIdentResponse("in\\valid:invalid",
|
60
|
|
- IdentityManager.getGlobalConfig());
|
|
72
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
73
|
+ final String response = getClient().getIdentResponse("in\\valid:invalid", cm);
|
61
|
74
|
|
62
|
75
|
assertStartsWith("Special chars in illegal requests must be quoted",
|
63
|
76
|
response, "in\\\\valid\\:invalid");
|
|
@@ -65,8 +78,8 @@ public class IdentClientTest {
|
65
|
78
|
|
66
|
79
|
@Test
|
67
|
80
|
public void testQuoting2() {
|
68
|
|
- final String response = getClient().getIdentResponse("in\\\\valid\\ inv\\:alid",
|
69
|
|
- IdentityManager.getGlobalConfig());
|
|
81
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
82
|
+ final String response = getClient().getIdentResponse("in\\\\valid\\ inv\\:alid", cm);
|
70
|
83
|
|
71
|
84
|
assertStartsWith("Escaped characters in illegal requests shouldn't be doubly-escaped",
|
72
|
85
|
response, "in\\\\valid\\ inv\\:alid");
|
|
@@ -74,8 +87,8 @@ public class IdentClientTest {
|
74
|
87
|
|
75
|
88
|
@Test
|
76
|
89
|
public void testNonNumericPort() {
|
77
|
|
- final String response = getClient().getIdentResponse("abc, def",
|
78
|
|
- IdentityManager.getGlobalConfig());
|
|
90
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
91
|
+ final String response = getClient().getIdentResponse("abc, def", cm);
|
79
|
92
|
|
80
|
93
|
assertContains("Non-numeric ports must result in an ERROR response",
|
81
|
94
|
response, "ERROR");
|
|
@@ -84,8 +97,8 @@ public class IdentClientTest {
|
84
|
97
|
}
|
85
|
98
|
|
86
|
99
|
private void doPortTest(final String ports) {
|
87
|
|
- final String response = getClient().getIdentResponse(ports,
|
88
|
|
- IdentityManager.getGlobalConfig());
|
|
100
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
101
|
+ final String response = getClient().getIdentResponse(ports, cm);
|
89
|
102
|
|
90
|
103
|
assertContains("Illegal ports must result in an ERROR response",
|
91
|
104
|
response, "ERROR");
|
|
@@ -105,10 +118,10 @@ public class IdentClientTest {
|
105
|
118
|
|
106
|
119
|
@Test
|
107
|
120
|
public void testAlwaysOn() {
|
108
|
|
- final TestConfigManagerMap tcm = new TestConfigManagerMap();
|
109
|
|
- tcm.settings.put("plugin-Identd.advanced.alwaysOn", "false");
|
|
121
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
122
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(false);
|
110
|
123
|
|
111
|
|
- final String response = getClient().getIdentResponse("50, 50", tcm);
|
|
124
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
112
|
125
|
assertContains("Unknown port requests must return an ERROR response",
|
113
|
126
|
response, "ERROR");
|
114
|
127
|
assertContains("Unknown port requests must return a NO-USER response",
|
|
@@ -117,11 +130,11 @@ public class IdentClientTest {
|
117
|
130
|
|
118
|
131
|
@Test
|
119
|
132
|
public void testHidden() {
|
120
|
|
- final TestConfigManagerMap tcm = new TestConfigManagerMap();
|
121
|
|
- tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
|
122
|
|
- tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "true");
|
|
133
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
134
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
135
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.isHiddenUser")).thenReturn(true);
|
123
|
136
|
|
124
|
|
- final String response = getClient().getIdentResponse("50, 50", tcm);
|
|
137
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
125
|
138
|
assertContains("Hidden requests must return an ERROR response",
|
126
|
139
|
response, "ERROR");
|
127
|
140
|
assertContains("Hidden requests must return a HIDDEN-USER response",
|
|
@@ -130,45 +143,45 @@ public class IdentClientTest {
|
130
|
143
|
|
131
|
144
|
@Test
|
132
|
145
|
public void testSystemNameQuoting() {
|
133
|
|
- final TestConfigManagerMap tcm = new TestConfigManagerMap();
|
134
|
|
- tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
|
135
|
|
- tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
|
136
|
|
- tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "true");
|
137
|
|
- tcm.settings.put("plugin-Identd.advanced.customSystem", "a:b\\c,d");
|
138
|
|
- tcm.settings.put("plugin-Identd.general.useCustomName", "false");
|
139
|
|
- tcm.settings.put("plugin-Identd.general.customName", "");
|
140
|
|
-
|
141
|
|
- final String response = getClient().getIdentResponse("50, 50", tcm);
|
|
146
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
147
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
148
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.isHiddenUser")).thenReturn(false);
|
|
149
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(true);
|
|
150
|
+ when(cm.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("a:b\\c,d");
|
|
151
|
+ when(cm.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(false);
|
|
152
|
+ when(cm.getOption("plugin-Identd", "general.customName")).thenReturn("");
|
|
153
|
+
|
|
154
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
142
|
155
|
assertContains("Special characters must be quoted in system names",
|
143
|
156
|
response, "a\\:b\\\\c\\,d");
|
144
|
157
|
}
|
145
|
158
|
|
146
|
159
|
@Test
|
147
|
160
|
public void testCustomNameQuoting() {
|
148
|
|
- final TestConfigManagerMap tcm = new TestConfigManagerMap();
|
149
|
|
- tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
|
150
|
|
- tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
|
151
|
|
- tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "false");
|
152
|
|
- tcm.settings.put("plugin-Identd.advanced.customSystem", "");
|
153
|
|
- tcm.settings.put("plugin-Identd.general.useCustomName", "true");
|
154
|
|
- tcm.settings.put("plugin-Identd.general.customName", "a:b\\c,d");
|
155
|
|
-
|
156
|
|
- final String response = getClient().getIdentResponse("50, 50", tcm);
|
|
161
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
162
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
163
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.isHiddenUser")).thenReturn(false);
|
|
164
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
165
|
+ when(cm.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("");
|
|
166
|
+ when(cm.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
|
167
|
+ when(cm.getOption("plugin-Identd", "general.customName")).thenReturn("a:b\\c,d");
|
|
168
|
+
|
|
169
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
157
|
170
|
assertContains("Special characters must be quoted in custom names",
|
158
|
171
|
response, "a\\:b\\\\c\\,d");
|
159
|
172
|
}
|
160
|
173
|
|
161
|
174
|
@Test
|
162
|
175
|
public void testCustomNames() {
|
163
|
|
- final TestConfigManagerMap tcm = new TestConfigManagerMap();
|
164
|
|
- tcm.settings.put("plugin-Identd.advanced.alwaysOn", "true");
|
165
|
|
- tcm.settings.put("plugin-Identd.advanced.isHiddenUser", "false");
|
166
|
|
- tcm.settings.put("plugin-Identd.advanced.useCustomSystem", "true");
|
167
|
|
- tcm.settings.put("plugin-Identd.advanced.customSystem", "system");
|
168
|
|
- tcm.settings.put("plugin-Identd.general.useCustomName", "true");
|
169
|
|
- tcm.settings.put("plugin-Identd.general.customName", "name");
|
170
|
|
-
|
171
|
|
- final String response = getClient().getIdentResponse("50, 60", tcm);
|
|
176
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
177
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
178
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.isHiddenUser")).thenReturn(false);
|
|
179
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(true);
|
|
180
|
+ when(cm.getOption("plugin-Identd", "advanced.customSystem")).thenReturn("system");
|
|
181
|
+ when(cm.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
|
182
|
+ when(cm.getOption("plugin-Identd", "general.customName")).thenReturn("name");
|
|
183
|
+
|
|
184
|
+ final String response = getClient().getIdentResponse("50, 60", cm);
|
172
|
185
|
final String[] bits = response.split(":");
|
173
|
186
|
|
174
|
187
|
assertTrue("Responses must include port pair",
|
|
@@ -179,6 +192,149 @@ public class IdentClientTest {
|
179
|
192
|
assertEquals("Must use custom name", "name", bits[3].trim());
|
180
|
193
|
}
|
181
|
194
|
|
|
195
|
+ @Test
|
|
196
|
+ public void testOSWindows() {
|
|
197
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
198
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
199
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
200
|
+ System.setProperty("user.name", "test");
|
|
201
|
+ System.setProperty("os.name", "windows");
|
|
202
|
+
|
|
203
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
204
|
+ assertEquals("50 , 50 : USERID : WIN32 : test", response);
|
|
205
|
+ }
|
|
206
|
+
|
|
207
|
+ @Test
|
|
208
|
+ public void testOSMac() {
|
|
209
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
210
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
211
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
212
|
+ System.setProperty("user.name", "test");
|
|
213
|
+ System.setProperty("os.name", "mac");
|
|
214
|
+
|
|
215
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
216
|
+ assertEquals("50 , 50 : USERID : MACOS : test", response);
|
|
217
|
+ }
|
|
218
|
+
|
|
219
|
+ @Test
|
|
220
|
+ public void testOSLinux() {
|
|
221
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
222
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
223
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
224
|
+ System.setProperty("user.name", "test");
|
|
225
|
+ System.setProperty("os.name", "linux");
|
|
226
|
+
|
|
227
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
228
|
+ assertEquals("50 , 50 : USERID : UNIX : test", response);
|
|
229
|
+ }
|
|
230
|
+
|
|
231
|
+ @Test
|
|
232
|
+ public void testOSBSD() {
|
|
233
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
234
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
235
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
236
|
+ System.setProperty("user.name", "test");
|
|
237
|
+ System.setProperty("os.name", "bsd");
|
|
238
|
+
|
|
239
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
240
|
+ assertEquals("50 , 50 : USERID : UNIX-BSD : test", response);
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ @Test
|
|
244
|
+ public void testOSOS2() {
|
|
245
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
246
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
247
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
248
|
+ System.setProperty("user.name", "test");
|
|
249
|
+ System.setProperty("os.name", "os/2");
|
|
250
|
+
|
|
251
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
252
|
+ assertEquals("50 , 50 : USERID : OS/2 : test", response);
|
|
253
|
+ }
|
|
254
|
+
|
|
255
|
+ @Test
|
|
256
|
+ public void testOSUnix() {
|
|
257
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
258
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
259
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
260
|
+ System.setProperty("user.name", "test");
|
|
261
|
+ System.setProperty("os.name", "unix");
|
|
262
|
+
|
|
263
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
264
|
+ assertEquals("50 , 50 : USERID : UNIX : test", response);
|
|
265
|
+ }
|
|
266
|
+
|
|
267
|
+ @Test
|
|
268
|
+ public void testOSIrix() {
|
|
269
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
270
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
271
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
272
|
+ System.setProperty("user.name", "test");
|
|
273
|
+ System.setProperty("os.name", "irix");
|
|
274
|
+
|
|
275
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
276
|
+ assertEquals("50 , 50 : USERID : IRIX : test", response);
|
|
277
|
+ }
|
|
278
|
+
|
|
279
|
+ @Test
|
|
280
|
+ public void testOSUnknown() {
|
|
281
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
282
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
283
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
284
|
+ System.setProperty("user.name", "test");
|
|
285
|
+ System.setProperty("os.name", "test");
|
|
286
|
+
|
|
287
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
288
|
+ assertEquals("50 , 50 : USERID : UNKNOWN : test", response);
|
|
289
|
+ }
|
|
290
|
+
|
|
291
|
+ @Test
|
|
292
|
+ public void testNameSystem() {
|
|
293
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
294
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
295
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.useCustomSystem")).thenReturn(false);
|
|
296
|
+ System.setProperty("user.name", "test");
|
|
297
|
+ System.setProperty("os.name", "test");
|
|
298
|
+
|
|
299
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
300
|
+ assertEquals("50 , 50 : USERID : UNKNOWN : test", response);
|
|
301
|
+ }
|
|
302
|
+
|
|
303
|
+ @Test
|
|
304
|
+ public void testNameCustom() {
|
|
305
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
306
|
+ when(cm.getOptionBool("plugin-Identd", "advanced.alwaysOn")).thenReturn(true);
|
|
307
|
+ when(cm.getOptionBool("plugin-Identd", "general.useCustomName")).thenReturn(true);
|
|
308
|
+ when(cm.getOption("plugin-Identd", "general.customName")).thenReturn("name");
|
|
309
|
+ System.setProperty("user.name", "test");
|
|
310
|
+ System.setProperty("os.name", "test");
|
|
311
|
+
|
|
312
|
+ final String response = getClient().getIdentResponse("50, 50", cm);
|
|
313
|
+ assertEquals("50 , 50 : USERID : UNKNOWN : name", response);
|
|
314
|
+ }
|
|
315
|
+
|
|
316
|
+ @Test
|
|
317
|
+ public void testNameNickname() {
|
|
318
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
319
|
+ when(cm.getOptionBool("plugin-Identd", "general.useNickname")).thenReturn(true);
|
|
320
|
+ System.setProperty("user.name", "test");
|
|
321
|
+ System.setProperty("os.name", "test");
|
|
322
|
+
|
|
323
|
+ final String response = getClient().getIdentResponse("60, 50", cm);
|
|
324
|
+ assertEquals("60 , 50 : USERID : UNKNOWN : nickname", response);
|
|
325
|
+ }
|
|
326
|
+
|
|
327
|
+ @Test
|
|
328
|
+ public void testNameUsername() {
|
|
329
|
+ final ConfigManager cm = mock(ConfigManager.class);
|
|
330
|
+ when(cm.getOptionBool("plugin-Identd", "general.useUsername")).thenReturn(true);
|
|
331
|
+ System.setProperty("user.name", "test");
|
|
332
|
+ System.setProperty("os.name", "test");
|
|
333
|
+
|
|
334
|
+ final String response = getClient().getIdentResponse("60, 50", cm);
|
|
335
|
+ assertEquals("60 , 50 : USERID : UNKNOWN : username", response);
|
|
336
|
+ }
|
|
337
|
+
|
182
|
338
|
private static void assertContains(final String msg, final String haystack,
|
183
|
339
|
final String needle) {
|
184
|
340
|
assertTrue(msg, haystack.indexOf(needle) > -1);
|