aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
diff options
context:
space:
mode:
authorSean Dague2009-01-12 15:33:56 +0000
committerSean Dague2009-01-12 15:33:56 +0000
commitd770bea2912e9fe02644183dce424193fe87ab7d (patch)
treef20c8af0363b21142738048ebe41e834db431adc /OpenSim/Framework/Communications/Tests/LoginServiceTests.cs
parentCause permissions on root prims to not override folded permissions anymore (diff)
downloadopensim-SC_OLD-d770bea2912e9fe02644183dce424193fe87ab7d.zip
opensim-SC_OLD-d770bea2912e9fe02644183dce424193fe87ab7d.tar.gz
opensim-SC_OLD-d770bea2912e9fe02644183dce424193fe87ab7d.tar.bz2
opensim-SC_OLD-d770bea2912e9fe02644183dce424193fe87ab7d.tar.xz
Enhanced LoginServiceTests to test for authentication and response
Expanded TestUserDataPlugin to cover new methods From: Arthur Rodrigo S Valadares <arthursv@linux.vnet.ibm.com>
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Communications/Tests/LoginServiceTests.cs215
1 files changed, 197 insertions, 18 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}