aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorSean Dague2008-10-15 18:15:43 +0000
committerSean Dague2008-10-15 18:15:43 +0000
commitfa8c0d7683d567743f5138813f08a502aff8e3d0 (patch)
tree7ac4d9dbb9979fcc4734e4a1898c24287bc3b6d3 /OpenSim
parentRemoved some comments (diff)
downloadopensim-SC_OLD-fa8c0d7683d567743f5138813f08a502aff8e3d0.zip
opensim-SC_OLD-fa8c0d7683d567743f5138813f08a502aff8e3d0.tar.gz
opensim-SC_OLD-fa8c0d7683d567743f5138813f08a502aff8e3d0.tar.bz2
opensim-SC_OLD-fa8c0d7683d567743f5138813f08a502aff8e3d0.tar.xz
- Makes MySQL reject inserting UUID 0
- Makes SQLite mimick MySQL default behavior on first and last name already on db: it does not insert the new record. - Added tests for UUID 0 and for new UUID with existing first and last name.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/MySQL/MySQLUserData.cs5
-rw-r--r--OpenSim/Data/SQLite/SQLiteUserData.cs35
-rw-r--r--OpenSim/Data/Tests/BasicUserTest.cs24
3 files changed, 59 insertions, 5 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs
index c668d56..3a088cf 100644
--- a/OpenSim/Data/MySQL/MySQLUserData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserData.cs
@@ -582,6 +582,11 @@ namespace OpenSim.Data.MySQL
582 /// <param name="user">The user profile to create</param> 582 /// <param name="user">The user profile to create</param>
583 public override void AddNewUserProfile(UserProfileData user) 583 public override void AddNewUserProfile(UserProfileData user)
584 { 584 {
585 UUID zero = UUID.Zero;
586 if (user.ID == zero)
587 {
588 return;
589 }
585 MySQLSuperManager dbm = GetLockedConnection(); 590 MySQLSuperManager dbm = GetLockedConnection();
586 591
587 try 592 try
diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs
index 420b6e5..448ef85 100644
--- a/OpenSim/Data/SQLite/SQLiteUserData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserData.cs
@@ -481,6 +481,37 @@ namespace OpenSim.Data.SQLite
481 481
482 } 482 }
483 483
484 private bool ExistsFirstLastName(String fname, String lname)
485 {
486 string FindUser = "select * from users where (username=:username and surname=:surname)";
487 using (SqliteCommand cmd = new SqliteCommand(FindUser, g_conn))
488 {
489 cmd.Parameters.Add(new SqliteParameter(":username", fname));
490 cmd.Parameters.Add(new SqliteParameter(":surname", lname));
491 try
492 {
493 using (IDataReader reader = cmd.ExecuteReader())
494 {
495 if(reader.Read())
496 {
497 reader.Close();
498 return true;
499 }
500 else
501 {
502 reader.Close();
503 return false;
504 }
505 }
506 }
507 catch (Exception ex)
508 {
509 m_log.Error("[USER DB]: Exception searching for user's first and last name: " + ex.ToString());
510 return false;
511 }
512 }
513 }
514
484 /// <summary> 515 /// <summary>
485 /// Creates a new user profile 516 /// Creates a new user profile
486 /// </summary> 517 /// </summary>
@@ -488,6 +519,10 @@ namespace OpenSim.Data.SQLite
488 override public void AddNewUserProfile(UserProfileData user) 519 override public void AddNewUserProfile(UserProfileData user)
489 { 520 {
490 DataTable users = ds.Tables["users"]; 521 DataTable users = ds.Tables["users"];
522 UUID zero = UUID.Zero;
523 if (ExistsFirstLastName(user.FirstName, user.SurName) || user.ID == zero)
524 return;
525
491 lock (ds) 526 lock (ds)
492 { 527 {
493 DataRow row = users.Rows.Find(Util.ToRawUuidString(user.ID)); 528 DataRow row = users.Rows.Find(Util.ToRawUuidString(user.ID));
diff --git a/OpenSim/Data/Tests/BasicUserTest.cs b/OpenSim/Data/Tests/BasicUserTest.cs
index 24cb215..dc8ccc3 100644
--- a/OpenSim/Data/Tests/BasicUserTest.cs
+++ b/OpenSim/Data/Tests/BasicUserTest.cs
@@ -45,6 +45,7 @@ namespace OpenSim.Data.Tests
45 public UUID user1; 45 public UUID user1;
46 public UUID user2; 46 public UUID user2;
47 public UUID user3; 47 public UUID user3;
48 public UUID user4;
48 public UUID webkey; 49 public UUID webkey;
49 public UUID zero = UUID.Zero; 50 public UUID zero = UUID.Zero;
50 public Random random; 51 public Random random;
@@ -55,6 +56,8 @@ namespace OpenSim.Data.Tests
55 56
56 public UUID region1; 57 public UUID region1;
57 58
59 public string fname0;
60 public string lname0;
58 public string fname1; 61 public string fname1;
59 public string lname1; 62 public string lname1;
60 public string fname2; 63 public string fname2;
@@ -76,11 +79,14 @@ namespace OpenSim.Data.Tests
76 user1 = UUID.Random(); 79 user1 = UUID.Random();
77 user2 = UUID.Random(); 80 user2 = UUID.Random();
78 user3 = UUID.Random(); 81 user3 = UUID.Random();
82 user4 = UUID.Random();
79 agent1 = UUID.Random(); 83 agent1 = UUID.Random();
80 agent2 = UUID.Random(); 84 agent2 = UUID.Random();
81 agent3 = UUID.Random(); 85 agent3 = UUID.Random();
82 webkey = UUID.Random(); 86 webkey = UUID.Random();
83 region1 = UUID.Random(); 87 region1 = UUID.Random();
88 fname0 = RandomName(random);
89 lname0 = RandomName(random);
84 fname1 = RandomName(random); 90 fname1 = RandomName(random);
85 lname1 = RandomName(random); 91 lname1 = RandomName(random);
86 fname2 = RandomName(random); 92 fname2 = RandomName(random);
@@ -115,19 +121,16 @@ namespace OpenSim.Data.Tests
115 [Test] 121 [Test]
116 public void T010_CreateUser() 122 public void T010_CreateUser()
117 { 123 {
118 UserProfileData u1 = NewUser(user1,fname1,lname1); // Must first and last names be unique? 124 UserProfileData u1 = NewUser(user1,fname1,lname1);
119 //UserProfileData u0 = NewUser(zero,fname1,lname1); // Zero causes some weird behaviors
120 UserProfileData u2 = NewUser(user2,fname2,lname2); 125 UserProfileData u2 = NewUser(user2,fname2,lname2);
121 UserProfileData u3 = NewUser(user3,fname3,lname3); 126 UserProfileData u3 = NewUser(user3,fname3,lname3);
122 //db.AddNewUserProfile(u0); 127 Console.WriteLine("Users are {0} {1} {2}",user1,user2,user3);
123 db.AddNewUserProfile(u1); 128 db.AddNewUserProfile(u1);
124 db.AddNewUserProfile(u2); 129 db.AddNewUserProfile(u2);
125 db.AddNewUserProfile(u3); 130 db.AddNewUserProfile(u3);
126 //UserProfileData u1z = db.GetUserByUUID(zero);
127 UserProfileData u1a = db.GetUserByUUID(user1); 131 UserProfileData u1a = db.GetUserByUUID(user1);
128 UserProfileData u2a = db.GetUserByUUID(user2); 132 UserProfileData u2a = db.GetUserByUUID(user2);
129 UserProfileData u3a = db.GetUserByUUID(user3); 133 UserProfileData u3a = db.GetUserByUUID(user3);
130 //Assert.That(zero,Is.EqualTo(u1z.ID));
131 Assert.That(user1,Is.EqualTo(u1a.ID)); 134 Assert.That(user1,Is.EqualTo(u1a.ID));
132 Assert.That(user2,Is.EqualTo(u2a.ID)); 135 Assert.That(user2,Is.EqualTo(u2a.ID));
133 Assert.That(user3,Is.EqualTo(u3a.ID)); 136 Assert.That(user3,Is.EqualTo(u3a.ID));
@@ -164,6 +167,17 @@ namespace OpenSim.Data.Tests
164 u1 = db.GetUserByUUID(user1); 167 u1 = db.GetUserByUUID(user1);
165 Assert.That(u1.WebLoginKey,Is.EqualTo(webkey)); 168 Assert.That(u1.WebLoginKey,Is.EqualTo(webkey));
166 } 169 }
170
171 [Test]
172 public void T014_ExpectedNullReferenceReturns()
173 {
174 UserProfileData u0 = NewUser(zero,fname0,lname0);
175 UserProfileData u4 = NewUser(user4,fname2,lname2);
176 db.AddNewUserProfile(u0);
177 db.AddNewUserProfile(u4);
178 Assert.That(db.GetUserByUUID(zero),Is.Null);
179 Assert.That(db.GetUserByUUID(user4),Is.Null);
180 }
167 181
168 [Test] 182 [Test]
169 public void T020_CreateAgent() 183 public void T020_CreateAgent()