aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Framework/Communications/Tests/LoginServiceTests.cs215
-rw-r--r--OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs134
2 files changed, 305 insertions, 44 deletions
diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
index 6c18d06..8111add 100644
--- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
+++ b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
@@ -44,35 +44,35 @@ namespace OpenSim.Framework.Communications.Tests
44 /// Test the login service. For now, most of this will be done through the LocalLoginService as LoginService 44 /// Test the login service. For now, most of this will be done through the LocalLoginService as LoginService
45 /// is abstract 45 /// is abstract
46 /// </summary> 46 /// </summary>
47 [TestFixture] 47 [TestFixture]
48 public class LoginServiceTests 48 public class LoginServiceTests
49 { 49 {
50 /// <summary> 50 /// <summary>
51 /// Test the normal response to a login. Does not test authentication. 51 /// Test the normal response to a login. Does not test authentication.
52 /// </summary> 52 /// </summary>
53 [Test] 53 [Test]
54 public void TestNormalLoginResponse() 54 public void T010_NormalLoginResponse()
55 { 55 {
56 //log4net.Config.XmlConfigurator.Configure(); 56 //log4net.Config.XmlConfigurator.Configure();
57 57
58 string firstName = "Timmy"; 58 string firstName = "Timmy";
59 string lastName = "Mallet"; 59 string lastName = "Mallet";
60 string regionExternalName = "localhost"; 60 string regionExternalName = "localhost";
61 IPEndPoint capsEndPoint = new IPEndPoint(IPAddress.Loopback, 9123); 61 IPEndPoint capsEndPoint = new IPEndPoint(IPAddress.Loopback, 9123);
62 62
63 CommunicationsManager commsManager 63 CommunicationsManager commsManager
64 = new TestCommunicationsManager(new OpenSim.Framework.NetworkServersInfo(42, 43)); 64 = new TestCommunicationsManager(new OpenSim.Framework.NetworkServersInfo(42, 43));
65 65
66 commsManager.GridService.RegisterRegion( 66 commsManager.GridService.RegisterRegion(
67 new RegionInfo(42, 43, capsEndPoint, regionExternalName)); 67 new RegionInfo(42, 43, capsEndPoint, regionExternalName));
68 commsManager.GridService.RegionLoginsEnabled = true; 68 commsManager.GridService.RegionLoginsEnabled = true;
69 69
70 LoginService loginService 70 LoginService loginService
71 = new LocalLoginService( 71 = new LocalLoginService(
72 (UserManagerBase)commsManager.UserService, "Hello folks", commsManager.InterServiceInventoryService, 72 (UserManagerBase)commsManager.UserService, "Hello folks", commsManager.InterServiceInventoryService,
73 (LocalBackEndServices)commsManager.GridService, 73 (LocalBackEndServices)commsManager.GridService,
74 commsManager.NetworkServersInfo, false, new LibraryRootFolder(String.Empty)); 74 commsManager.NetworkServersInfo, false, new LibraryRootFolder(String.Empty));
75 75
76 Hashtable loginParams = new Hashtable(); 76 Hashtable loginParams = new Hashtable();
77 loginParams["first"] = firstName; 77 loginParams["first"] = firstName;
78 loginParams["last"] = lastName; 78 loginParams["last"] = lastName;
@@ -85,20 +85,199 @@ namespace OpenSim.Framework.Communications.Tests
85 85
86 XmlRpcResponse response = loginService.XmlRpcLoginMethod(request); 86 XmlRpcResponse response = loginService.XmlRpcLoginMethod(request);
87 Hashtable responseData = (Hashtable)response.Value; 87 Hashtable responseData = (Hashtable)response.Value;
88 88
89 Assert.That(responseData["first_name"], Is.EqualTo(firstName));
90 Assert.That(responseData["last_name"], Is.EqualTo(lastName));
91 Assert.That(
92 responseData["circuit_code"], Is.GreaterThanOrEqualTo(0) & Is.LessThanOrEqualTo(System.Int32.MaxValue));
93
94 Regex capsSeedPattern
95 = new Regex("^http://"
96 + regionExternalName
97 + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{8}0000/$");
98
99 Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
100 }
101
102 [Test]
103 public void T011_Auth_Login()
104 {
105 string firstName = "Adam";
106 string lastName = "West";
107 string regionExternalName = "localhost";
108 IPEndPoint capsEndPoint = new IPEndPoint(IPAddress.Loopback, 9123);
109
110 CommunicationsManager commsManager
111 = new TestCommunicationsManager(new OpenSim.Framework.NetworkServersInfo(42, 43));
112
113 commsManager.GridService.RegisterRegion(
114 new RegionInfo(42, 43, capsEndPoint, regionExternalName));
115 commsManager.GridService.RegionLoginsEnabled = true;
116
117 LocalUserServices lus = (LocalUserServices)commsManager.UserService;
118
119 lus.AddUser(firstName,lastName,"boingboing","abc@ftw.com",42,43);
120
121
122 LoginService loginService
123 = new LocalLoginService(
124 (UserManagerBase)lus, "Hello folks", commsManager.InterServiceInventoryService,
125 (LocalBackEndServices)commsManager.GridService,
126 commsManager.NetworkServersInfo, true, new LibraryRootFolder(String.Empty));
127
128
89 // TODO: Not check inventory part of response yet. 129 // TODO: Not check inventory part of response yet.
90 // TODO: Not checking all of login response thoroughly yet. 130 // TODO: Not checking all of login response thoroughly yet.
91 131
132 // 1) Test for positive authentication
133
134 Hashtable loginParams = new Hashtable();
135 loginParams["first"] = firstName;
136 loginParams["last"] = lastName;
137 loginParams["passwd"] = "boingboing";
138
139 ArrayList sendParams = new ArrayList();
140 sendParams.Add(loginParams);
141
142 XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams);
143
144 XmlRpcResponse response = loginService.XmlRpcLoginMethod(request);
145 Hashtable responseData = (Hashtable)response.Value;
146
147 UserProfileData uprof = lus.GetUserProfile(firstName,lastName);
148
149 UserAgentData uagent = uprof.CurrentAgent;
150 Assert.That(uagent,Is.Not.Null);
151
152 Assert.That(responseData["first_name"], Is.Not.Null);
92 Assert.That(responseData["first_name"], Is.EqualTo(firstName)); 153 Assert.That(responseData["first_name"], Is.EqualTo(firstName));
93 Assert.That(responseData["last_name"], Is.EqualTo(lastName)); 154 Assert.That(responseData["last_name"], Is.EqualTo(lastName));
155 Assert.That(responseData["agent_id"], Is.EqualTo(uagent.ProfileID.ToString()));
156 Assert.That(responseData["session_id"], Is.EqualTo(uagent.SessionID.ToString()));
157 Assert.That(responseData["secure_session_id"], Is.EqualTo(uagent.SecureSessionID.ToString()));
158 ArrayList invlibroot = (ArrayList) responseData["inventory-lib-root"];
159 Hashtable invlibroothash = (Hashtable) invlibroot[0];
160 Assert.That(invlibroothash["folder_id"],Is.EqualTo("00000112-000f-0000-0000-000100bba000"));
94 Assert.That( 161 Assert.That(
95 responseData["circuit_code"], Is.GreaterThanOrEqualTo(0) & Is.LessThanOrEqualTo(System.Int32.MaxValue)); 162 responseData["circuit_code"], Is.GreaterThanOrEqualTo(0) & Is.LessThanOrEqualTo(System.Int32.MaxValue));
163 Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
164 Assert.That(responseData["buddy-list"], Is.Empty);
165 Assert.That(responseData["start_location"], Is.EqualTo("last"));
166
167 Regex capsSeedPattern
168 = new Regex("^http://"
169 + regionExternalName
170 + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{8}0000/$");
171
172 Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True);
173
174 // 1.1) Test for budddies!
175 lus.AddUser("Friend","Number1","boingboing","abc@ftw.com",42,43);
176 lus.AddUser("Friend","Number2","boingboing","abc@ftw.com",42,43);
177
178 UserProfileData friend1 = lus.GetUserProfile("Friend","Number1");
179 UserProfileData friend2 = lus.GetUserProfile("Friend","Number2");
180 lus.AddNewUserFriend(friend1.ID,uprof.ID,1);
181 lus.AddNewUserFriend(friend1.ID,friend2.ID,2);
182
183 loginParams = new Hashtable();
184 loginParams["first"] = "Friend";
185 loginParams["last"] = "Number1";
186 loginParams["passwd"] = "boingboing";
187
188 sendParams = new ArrayList();
189 sendParams.Add(loginParams);
190
191 request = new XmlRpcRequest("login_to_simulator", sendParams);
192
193 response = loginService.XmlRpcLoginMethod(request);
194 responseData = (Hashtable)response.Value;
195
196 ArrayList friendslist = (ArrayList) responseData["buddy-list"];
197
198 Assert.That(friendslist,Is.Not.Null);
199
200
201 Hashtable buddy1 = (Hashtable) friendslist[0];
202 Hashtable buddy2 = (Hashtable) friendslist[1];
203 Assert.That(friendslist.Count, Is.EqualTo(2));
204 Assert.That(uprof.ID.ToString(), Is.EqualTo(buddy1["buddy_id"]) | Is.EqualTo(buddy2["buddy_id"]));
205 Assert.That(friend2.ID.ToString(), Is.EqualTo(buddy1["buddy_id"]) | Is.EqualTo(buddy2["buddy_id"]));
206
207 // 2) Test for negative authentication
208 //
209 string error_auth_message = "Could not authenticate your avatar. Please check your username and password, and check the grid if problems persist.";
210 string error_xml_message = "Error connecting to grid. Could not percieve credentials from login XML.";
211 string error_already_logged = "You appear to be already logged in. " +
212 "If this is not the case please wait for your session to timeout. " +
213 "If this takes longer than a few minutes please contact the grid owner. " +
214 "Please wait 5 minutes if you are going to connect to a region nearby to the region you were at previously.";
215 string error_region_unavailable = "The region you are attempting to log into is not responding. Please select another region and try again.";
216 // 2.1) Test for wrong user name
217 loginParams = new Hashtable();
218 loginParams["first"] = lastName;
219 loginParams["last"] = firstName;
220 loginParams["passwd"] = "boingboing";
221
222 sendParams = new ArrayList();
223 sendParams.Add(loginParams);
224
225 request = new XmlRpcRequest("login_to_simulator", sendParams);
226
227 response = loginService.XmlRpcLoginMethod(request);
228 responseData = (Hashtable)response.Value;
229 Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
230
231 // 2.2) Test for wrong password
232 loginParams = new Hashtable();
233 loginParams["first"] = "Friend";
234 loginParams["last"] = "Number2";
235 loginParams["passwd"] = "boing";
236
237 sendParams = new ArrayList();
238 sendParams.Add(loginParams);
239
240 request = new XmlRpcRequest("login_to_simulator", sendParams);
241
242 response = loginService.XmlRpcLoginMethod(request);
243 responseData = (Hashtable)response.Value;
244 Assert.That(responseData["message"], Is.EqualTo(error_auth_message));
245
246 // 2.3) Bad XML
247 loginParams = new Hashtable();
248 loginParams["first"] = "Friend";
249 loginParams["banana"] = "Banana";
250 loginParams["passwd"] = "boingboing";
251
252 sendParams = new ArrayList();
253 sendParams.Add(loginParams);
254
255 request = new XmlRpcRequest("login_to_simulator", sendParams);
256
257 response = loginService.XmlRpcLoginMethod(request);
258 responseData = (Hashtable)response.Value;
259 Assert.That(responseData["message"], Is.EqualTo(error_xml_message));
96 260
97 Regex capsSeedPattern 261 // 2.4) Already logged in and sucessfull post login
98 = new Regex("^http://" + regionExternalName + ":" + NetworkServersInfo.DefaultHttpListenerPort 262 loginParams = new Hashtable();
99 + "/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{8}0000/$"); 263 loginParams["first"] = "Adam";
264 loginParams["last"] = "West";
265 loginParams["passwd"] = "boingboing";
266
267 sendParams = new ArrayList();
268 sendParams.Add(loginParams);
269
270 request = new XmlRpcRequest("login_to_simulator", sendParams);
271
272 response = loginService.XmlRpcLoginMethod(request);
273 responseData = (Hashtable)response.Value;
274 Assert.That(responseData["message"], Is.EqualTo(error_already_logged));
275
276 request = new XmlRpcRequest("login_to_simulator", sendParams);
100 277
101 Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True); 278 response = loginService.XmlRpcLoginMethod(request);
279 responseData = (Hashtable)response.Value;
280 Assert.That(responseData["message"], Is.EqualTo("Hello folks"));
102 } 281 }
103 } 282 }
104} 283}
diff --git a/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs b/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs
index 6be7b3d..8dccacc 100644
--- a/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs
+++ b/OpenSim/Tests/Common/Mock/TestUserDataPlugin.cs
@@ -38,7 +38,7 @@ namespace OpenSim.Tests.Common.Mock
38 /// tests are single threaded. 38 /// tests are single threaded.
39 /// </summary> 39 /// </summary>
40 public class TestUserDataPlugin : IUserDataPlugin 40 public class TestUserDataPlugin : IUserDataPlugin
41 { 41 {
42 public string Version { get { return "0"; } } 42 public string Version { get { return "0"; } }
43 public string Name { get { return "TestUserDataPlugin"; } } 43 public string Name { get { return "TestUserDataPlugin"; } }
44 44
@@ -49,64 +49,146 @@ namespace OpenSim.Tests.Common.Mock
49 49
50 /// <summary> 50 /// <summary>
51 /// User profiles keyed by uuid 51 /// User profiles keyed by uuid
52 /// </summary> 52 /// </summary>
53 private Dictionary<UUID, UserProfileData> m_userProfilesByUuid = new Dictionary<UUID, UserProfileData>(); 53 private Dictionary<UUID, UserProfileData> m_userProfilesByUuid = new Dictionary<UUID, UserProfileData>();
54 54
55 /// <summary>
56 /// User profiles and their agents
57 /// </summary>
58 private Dictionary<UUID, UserAgentData> m_agentByProfileUuid = new Dictionary<UUID, UserAgentData>();
59
60 /// <summary>
61 /// Friends list by uuid
62 /// </summary>
63 private Dictionary<UUID, List<FriendListItem>> m_friendsListByUuid = new Dictionary<UUID, List<FriendListItem>>();
64
55 public void Initialise() {} 65 public void Initialise() {}
56 public void Dispose() {} 66 public void Dispose() {}
57 67
58 public void AddNewUserProfile(UserProfileData user) 68 public void AddNewUserProfile(UserProfileData user)
59 { 69 {
60 UpdateUserProfile(user); 70 UpdateUserProfile(user);
61 } 71 }
62 72
63 public UserProfileData GetUserByUUID(UUID user) 73 public UserProfileData GetUserByUUID(UUID user)
64 { 74 {
65 UserProfileData userProfile = null; 75 UserProfileData userProfile = null;
66 m_userProfilesByUuid.TryGetValue(user, out userProfile); 76 m_userProfilesByUuid.TryGetValue(user, out userProfile);
67 77
68 return userProfile; 78 return userProfile;
69 } 79 }
70 80
71 public UserProfileData GetUserByName(string fname, string lname) 81 public UserProfileData GetUserByName(string fname, string lname)
72 { 82 {
73 UserProfileData userProfile = null; 83 UserProfileData userProfile = null;
74 m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile); 84 m_userProfilesByName.TryGetValue(fname + " " + lname, out userProfile);
75 85
76 return userProfile; 86 return userProfile;
77 } 87 }
78 88
79 public bool UpdateUserProfile(UserProfileData user) 89 public bool UpdateUserProfile(UserProfileData user)
80 { 90 {
81 m_userProfilesByUuid[user.ID] = user; 91 m_userProfilesByUuid[user.ID] = user;
82 m_userProfilesByName[user.FirstName + " " + user.SurName] = user; 92 m_userProfilesByName[user.FirstName + " " + user.SurName] = user;
83 93
84 return true; 94 return true;
85 } 95 }
86 96
87 public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; } 97 public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query) { return null; }
88 98
89 public UserAgentData GetAgentByUUID(UUID user) { return null; } 99 public UserAgentData GetAgentByUUID(UUID user)
100 {
101 UserAgentData userAgent = null;
102 m_agentByProfileUuid.TryGetValue(user, out userAgent);
90 103
91 public UserAgentData GetAgentByName(string name) { return null; } 104 return userAgent;
105 }
92 106
93 public UserAgentData GetAgentByName(string fname, string lname) { return null; } 107 public UserAgentData GetAgentByName(string name)
108 {
109 UserProfileData userProfile = null;
110 m_userProfilesByName.TryGetValue(name, out userProfile);
111 UserAgentData userAgent = null;
112 m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
113
114 return userAgent;
115 }
116
117 public UserAgentData GetAgentByName(string fname, string lname)
118 {
119 UserProfileData userProfile = GetUserByName(fname,lname);
120 UserAgentData userAgent = null;
121 m_agentByProfileUuid.TryGetValue(userProfile.ID, out userAgent);
122
123 return userAgent;
124 }
94 125
95 public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {} 126 public void StoreWebLoginKey(UUID agentID, UUID webLoginKey) {}
96 127
97 public void AddNewUserAgent(UserAgentData agent) {} 128 public void AddNewUserAgent(UserAgentData agent)
129 {
130 m_agentByProfileUuid[agent.ProfileID] = agent;
131 }
132 public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
133 {
134 FriendListItem newfriend = new FriendListItem();
135 newfriend.FriendPerms = perms;
136 newfriend.Friend = friend;
137 newfriend.FriendListOwner = friendlistowner;
138
139 if (!m_friendsListByUuid.ContainsKey(friendlistowner))
140 {
141 List<FriendListItem> friendslist = new List<FriendListItem>();
142 m_friendsListByUuid[friendlistowner] = friendslist;
143
144 }
145 m_friendsListByUuid[friendlistowner].Add(newfriend);
146 }
98 147
99 public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms) {} 148 public void RemoveUserFriend(UUID friendlistowner, UUID friend)
100 149 {
101 public void RemoveUserFriend(UUID friendlistowner, UUID friend) {} 150 if (m_friendsListByUuid.ContainsKey(friendlistowner))
151 {
152 List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
153 foreach (FriendListItem frienditem in friendslist)
154 {
155 if (frienditem.Friend == friend)
156 {
157 friendslist.Remove(frienditem);
158 break;
159 }
160 }
161 }
162 }
102 163
103 public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms) {} 164 public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
165 {
166 if (m_friendsListByUuid.ContainsKey(friendlistowner))
167 {
168 List<FriendListItem> friendslist = m_friendsListByUuid[friendlistowner];
169 foreach (FriendListItem frienditem in friendslist)
170 {
171 if (frienditem.Friend == friend)
172 {
173 frienditem.FriendPerms = perms;
174 break;
175 }
176 }
177 }
178 }
104 179
105 public List<FriendListItem> GetUserFriendList(UUID friendlistowner) 180 public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
106 { 181 {
107 return new List<FriendListItem>(); 182 if (m_friendsListByUuid.ContainsKey(friendlistowner))
183 {
184 return m_friendsListByUuid[friendlistowner];
185 }
186 else
187 return new List<FriendListItem>();
188
189
108 } 190 }
109 191
110 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; } 192 public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos(List<UUID> uuids) { return null; }
111 193
112 public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; } 194 public bool MoneyTransferRequest(UUID from, UUID to, uint amount) { return false; }