|
Lines 9-14
Link Here
|
| 9 |
package org.eclipse.mylyn.tasks.tests; |
9 |
package org.eclipse.mylyn.tasks.tests; |
| 10 |
|
10 |
|
| 11 |
import java.net.URL; |
11 |
import java.net.URL; |
|
|
12 |
import java.util.Date; |
| 12 |
import java.util.Map; |
13 |
import java.util.Map; |
| 13 |
|
14 |
|
| 14 |
import junit.framework.TestCase; |
15 |
import junit.framework.TestCase; |
|
Lines 38-51
Link Here
|
| 38 |
taskRepository.setCredentials(TaskRepository.AUTH_DEFAULT, "user", "pwd"); |
39 |
taskRepository.setCredentials(TaskRepository.AUTH_DEFAULT, "user", "pwd"); |
| 39 |
assertEquals("user", taskRepository.getUserName()); |
40 |
assertEquals("user", taskRepository.getUserName()); |
| 40 |
assertEquals("pwd", taskRepository.getPassword()); |
41 |
assertEquals("pwd", taskRepository.getPassword()); |
| 41 |
|
42 |
|
| 42 |
assertEquals(null, taskRepository.getHttpUser()); |
43 |
assertEquals(null, taskRepository.getHttpUser()); |
| 43 |
assertEquals(null, taskRepository.getHttpPassword()); |
44 |
assertEquals(null, taskRepository.getHttpPassword()); |
| 44 |
} |
45 |
} |
| 45 |
|
46 |
|
| 46 |
public void testHttpPassword() throws Exception { |
47 |
public void testHttpPassword() throws Exception { |
| 47 |
password(TaskRepository.AUTH_HTTP); |
48 |
password(TaskRepository.AUTH_HTTP); |
| 48 |
|
49 |
|
| 49 |
TaskRepository taskRepository = new TaskRepository("kind", "url"); |
50 |
TaskRepository taskRepository = new TaskRepository("kind", "url"); |
| 50 |
taskRepository.setCredentials(TaskRepository.AUTH_HTTP, "user", "pwd"); |
51 |
taskRepository.setCredentials(TaskRepository.AUTH_HTTP, "user", "pwd"); |
| 51 |
assertEquals("user", taskRepository.getHttpUser()); |
52 |
assertEquals("user", taskRepository.getHttpUser()); |
|
Lines 66-88
Link Here
|
| 66 |
TaskRepository taskRepository = new TaskRepository("kind", url.toString()); |
67 |
TaskRepository taskRepository = new TaskRepository("kind", url.toString()); |
| 67 |
assertNull(taskRepository.getPassword(authType)); |
68 |
assertNull(taskRepository.getPassword(authType)); |
| 68 |
assertTrue(taskRepository.getSavePassword(authType)); |
69 |
assertTrue(taskRepository.getSavePassword(authType)); |
| 69 |
|
70 |
|
| 70 |
taskRepository.setCredentials(authType, "user", "pwd"); |
71 |
taskRepository.setCredentials(authType, "user", "pwd"); |
| 71 |
assertEquals("user", taskRepository.getUserName(authType)); |
72 |
assertEquals("user", taskRepository.getUserName(authType)); |
| 72 |
assertEquals("pwd", taskRepository.getPassword(authType)); |
73 |
assertEquals("pwd", taskRepository.getPassword(authType)); |
| 73 |
|
74 |
|
| 74 |
Map<?, ?> map = Platform.getAuthorizationInfo(url, "", "Basic"); |
75 |
Map<?, ?> map = Platform.getAuthorizationInfo(url, "", "Basic"); |
| 75 |
assertNotNull(map); |
76 |
assertNotNull(map); |
| 76 |
assertTrue(map.containsValue("user")); |
77 |
assertTrue(map.containsValue("user")); |
| 77 |
assertTrue(map.containsValue("pwd")); |
78 |
assertTrue(map.containsValue("pwd")); |
| 78 |
|
79 |
|
| 79 |
// test not saving password |
80 |
// test not saving password |
| 80 |
taskRepository.setSavePassword(authType, false); |
81 |
taskRepository.setSavePassword(authType, false); |
| 81 |
assertFalse(taskRepository.getSavePassword(authType)); |
82 |
assertFalse(taskRepository.getSavePassword(authType)); |
| 82 |
taskRepository.setCredentials(authType, "user1", "pwd1"); |
83 |
taskRepository.setCredentials(authType, "user1", "pwd1"); |
| 83 |
assertEquals("user1", taskRepository.getUserName(authType)); |
84 |
assertEquals("user1", taskRepository.getUserName(authType)); |
| 84 |
assertEquals("pwd1", taskRepository.getPassword(authType)); |
85 |
assertEquals("pwd1", taskRepository.getPassword(authType)); |
| 85 |
|
86 |
|
| 86 |
// make sure not old passwords are in the key ring |
87 |
// make sure not old passwords are in the key ring |
| 87 |
map = Platform.getAuthorizationInfo(url, "", "Basic"); |
88 |
map = Platform.getAuthorizationInfo(url, "", "Basic"); |
| 88 |
assertNotNull(map); |
89 |
assertNotNull(map); |
|
Lines 90-96
Link Here
|
| 90 |
assertFalse(map.containsValue("pwd1")); |
91 |
assertFalse(map.containsValue("pwd1")); |
| 91 |
assertFalse(map.containsValue("user")); |
92 |
assertFalse(map.containsValue("user")); |
| 92 |
assertFalse(map.containsValue("pwd")); |
93 |
assertFalse(map.containsValue("pwd")); |
| 93 |
|
94 |
|
| 94 |
taskRepository.setSavePassword(authType, true); |
95 |
taskRepository.setSavePassword(authType, true); |
| 95 |
assertTrue(taskRepository.getSavePassword(authType)); |
96 |
assertTrue(taskRepository.getSavePassword(authType)); |
| 96 |
taskRepository.setCredentials(authType, "user2", "pwd2"); |
97 |
taskRepository.setCredentials(authType, "user2", "pwd2"); |
|
Lines 98-101
Link Here
|
| 98 |
assertEquals("pwd2", taskRepository.getPassword(authType)); |
99 |
assertEquals("pwd2", taskRepository.getPassword(authType)); |
| 99 |
} |
100 |
} |
| 100 |
|
101 |
|
|
|
102 |
public void testConfigUpdateStoring() throws Exception { |
| 103 |
URL url = new URL("http://url"); |
| 104 |
TaskRepository taskRepository = new TaskRepository("kind", url.toString()); |
| 105 |
|
| 106 |
Date stamp = taskRepository.getConfigurationTimestamp(); |
| 107 |
assertTrue("unset stap returns long ago", stamp.before(new Date())); |
| 108 |
|
| 109 |
stamp = taskRepository.touchConfigurationTimestamp(); |
| 110 |
assertEquals("Time stamp touched", stamp.getTime(), taskRepository.getConfigurationTimestamp().getTime()); |
| 111 |
|
| 112 |
stamp.setTime(stamp.getTime() - 1000000L); |
| 113 |
taskRepository.setConfigurationTimestamp(stamp); |
| 114 |
assertEquals("Time stamp set", stamp.getTime(), taskRepository.getConfigurationTimestamp().getTime()); |
| 115 |
} |
| 116 |
|
| 101 |
} |
117 |
} |