public void Contexts_ValidArgs3_ReturnslistOfContexts() //Null Userlogin { var c1 = new SecContext { Name = "c1", Description = "context1" }; var c2 = new SecContext { Name = "c2", Description = "context2" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.AddEntry(_myApp.Name, c2, obj1, null, group1.Name); var l = CaravanDataSource.Security.GetContexts(_myApp.Name); Assert.That(l.Count(), Is.EqualTo(2)); Assert.That(l.Contains(c1)); Assert.That(l.Contains(c2)); }
public void AddGroup_InsertSameGroupInDifferentApps_ReturnsOK() { var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp2.Name, group1); var q = (from g in CaravanDataSource.Security.GetGroups(_myApp.Name) where g.Name == group1.Name select g).ToList(); Assert.That(q.First().Name, Is.EqualTo("my_group")); var q2 = (from g in CaravanDataSource.Security.GetGroups(_myApp2.Name) where g.Name == group1.Name select g).ToList(); Assert.That(q2.First().Name, Is.EqualTo("my_group")); }
public void AddGroup_GroupAlreadyExisting_ThrowsGroupExistingException_Async() { var failCount = 0; try { Parallel.ForEach(Enumerable.Range(1, 2), i => { var group = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group); }); } catch (Exception exception) { failCount++; } Assert.AreEqual(1, failCount, "_GroupAlreadyExisting"); }
public void Group_ValidArgs_ReturnsOK_Async(int userCount) { Parallel.ForEach(Enumerable.Range(1, userCount), i => { var group = new SecGroup { Name = "g1" + i }; CaravanDataSource.Security.AddGroup(_myApp.Name, group); }); for (var i = 1; i <= userCount; ++i) { var ret = CaravanDataSource.Security.GetGroupByName(_myApp.Name, "g1" + i); Assert.That(ret, Is.Not.Null); } }
public void AddGroup_validArgs_InsertCorrectGroup() { var group1 = new SecGroup { Name = "my_group" }; var group2 = new SecGroup { Name = "other_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); var q1 = (from g in CaravanDataSource.Security.GetGroups(_myApp.Name) where g.Name == group1.Name select g).ToList(); Assert.That(q1.First().Name, Is.EqualTo("my_group")); var q2 = (from g in CaravanDataSource.Security.GetGroups(_myApp.Name) where g.Name == group2.Name select g).ToList(); Assert.That(q2.First().Name, Is.EqualTo("other_group")); var q3 = (from g in CaravanDataSource.Security.GetGroups(_myApp2.Name) where g.Name == group1.Name || g.Name == group2.Name select g).ToList(); Assert.That(q3.Count(), Is.EqualTo(0)); }
public void AddUserToGroup_EmptyGroupName_ThrowsArgumentException() { var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" }; var group1 = new SecGroup { Name = "mygroup" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, ""); }
public void Groups_ValidArgs_ReturnsListOfGroups_Async(int userCount) { Parallel.ForEach(Enumerable.Range(1, userCount), i => { var group = new SecGroup { Name = "g1" + i }; CaravanDataSource.Security.AddGroup(_myApp.Name, group); }); for (var i = 1; i <= userCount; ++i) { var q = CaravanDataSource.Security.GetGroups(_myApp.Name).Where(g => g.Name == ("g1" + i)); Assert.IsNotNull(q.FirstOrDefault()); } var retValue = CaravanDataSource.Security.GetGroups(_myApp.Name); Assert.That(retValue.Count(), Is.EqualTo(userCount)); var retValue2 = CaravanDataSource.Security.GetGroups(_myApp2.Name); Assert.That(retValue2.Count(), Is.EqualTo(0)); }
public void Entries_NullUserLoginAsFourthParam_Throws() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.GetEntriesForObjectAndUser(_myApp.Name, c1.Name, obj1.Name, null); }
public void Addentry_ValidArgsNullGroupName_EntryAdded() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); var l = CaravanDataSource.Security.GetEntries(_myApp.Name, c1.Name); Assert.That(l.Count(), Is.EqualTo(1)); Assert.That(l.First().ContextName, Is.EqualTo("c1")); Assert.That(l.First().ObjectName, Is.EqualTo("obj1")); Assert.That(l.First().UserLogin, Is.EqualTo("mylogin")); }
public void Entries_NoEntries_ReturnsZero() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); var l = CaravanDataSource.Security.GetEntries(_myApp.Name, c1.Name); Assert.That(l.Count(), Is.EqualTo(0)); }
public void Entries_EmptyContextName_throwsArgumentException() { //var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.GetEntries(_myApp.Name, ""); }
public void Entries_validArgs_ReturnsListOfEntries()//associo un gruppo e un utente allo stesso oggetto { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); var l = CaravanDataSource.Security.GetEntries(_myApp.Name, c1.Name); var l1 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name); var l3 = CaravanDataSource.Security.GetEntriesForUser(_myApp.Name, c1.Name, user1.Login); Assert.That(l.Count(), Is.EqualTo(2)); Assert.That(l3.Count(), Is.EqualTo(1)); Assert.That(l1.Count(), Is.EqualTo(2)); }
public void Objects_EmptyAppName_ThrowsArgumentException() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.GetObjects(""); }
public void Objects_ValidArgs_ReturnsListOfObjects() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); var l = CaravanDataSource.Security.GetObjects(_myApp.Name); Assert.That(l.Count(), Is.EqualTo(1)); var l1 = CaravanDataSource.Security.GetObjects(_myApp2.Name); Assert.That(l1.Count(), Is.EqualTo(0)); }
public void AddUserToGroup_ValidArgs_UserAddedInCorrectGroup() { var user1 = new SecUser { FirstName = "pippo", Login = "******", Email = "*****@*****.**" }; var group1 = new SecGroup { Name = "mygroup" }; var group2 = new SecGroup { Name = "mygroup2" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, group1.Name); user1 = CaravanDataSource.Security.GetUserByLogin(_myApp.Name, user1.Login); group1 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group1.Name); group2 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group2.Name); Assert.True(user1.Groups.Any(g => g.Equals(group1))); Assert.False(user1.Groups.Any(g => g.Equals(group2))); Assert.AreEqual(1, user1.Groups.Length); Assert.True(group1.Users.Any(g => g.Equals(user1))); Assert.False(group2.Users.Any(g => g.Equals(user1))); Assert.AreEqual(1, group1.Users.Length); Assert.AreEqual(0, group2.Users.Length); }
public void AddEntry_Insert2DifferentUsersOnTheSameObject_EntryAdded() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var user2 = new SecUser { FirstName = "user2", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddUser(_myApp.Name, user2); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user2.Login, null); var l = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name); Assert.That(l.Count(), Is.EqualTo(2)); var l1 = CaravanDataSource.Security.GetEntriesForObjectAndUser(_myApp.Name, c1.Name, obj1.Name, user1.Login); Assert.That(l1.Count(), Is.EqualTo(1)); var l2 = CaravanDataSource.Security.GetEntriesForObjectAndUser(_myApp.Name, c1.Name, obj1.Name, user2.Login); Assert.That(l2.Count(), Is.EqualTo(1)); }
public void AddUserToGroup_ValidArgs_UserAddedInCorrectGroup_Async(int userCount) { var group1 = new SecGroup { Name = "mygroup" }; var group2 = new SecGroup { Name = "mygroup2" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); Parallel.ForEach(Enumerable.Range(1, userCount), i => { var user1 = new SecUser { FirstName = "pippo" + i, Login = "******" + i }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddUserToGroup(_myApp.Name, user1.Login, group1.Name); }); group1 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group1.Name); group2 = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group2.Name); Assert.AreEqual(userCount, group1.Users.Length); Assert.AreEqual(0, group2.Users.Length); for (var i = 1; i <= userCount; ++i) { var q = (from u in CaravanDataSource.Security.GetUsers(_myApp.Name) where u.Login == ("blabla" + i) select u.Groups).ToList(); Assert.That(q.Count, Is.EqualTo(1)); Assert.True(q.First().Contains(group1)); Assert.False(q.First().Contains(group2)); } }
public void AddEntry_InsertDifferentGroupsOnTheSameObject_EntryAdded() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var group2 = new SecGroup { Name = "group2" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group2.Name); var l1 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name); Assert.That(l1.Count(), Is.EqualTo(2)); }
public void Groups_ValidArgs_ReturnsListOfGroups() { var group1 = new SecGroup { Name = "g1" }; var group2 = new SecGroup { Name = "g2" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); var retValue = CaravanDataSource.Security.GetGroups(_myApp.Name); Assert.That(retValue.Count(), Is.EqualTo(2)); var retValue2 = CaravanDataSource.Security.GetGroups(_myApp2.Name); Assert.That(retValue2.Count(), Is.EqualTo(0)); }
public void AddEntry_InsertTheSameGroupOnDifferentObjects_EntryAdded() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; var obj2 = new SecObject { Name = "obj2", Description = "oggetto2", Type = "button" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, null, group1.Name); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj2, null, group1.Name); var l1 = CaravanDataSource.Security.GetEntries(_myApp.Name, c1.Name); Assert.That(l1.Count(), Is.EqualTo(2)); var l2 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name); Assert.That(l2.Count(), Is.EqualTo(1)); Assert.That(l2.First().GroupName, Is.EqualTo("my_group")); var l3 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj2.Name); Assert.That(l3.Count(), Is.EqualTo(1)); Assert.That(l3.First().GroupName, Is.EqualTo("my_group")); }
public void Group_ValidArgs_ReturnsOK() { var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); var ret = CaravanDataSource.Security.GetGroupByName(_myApp.Name, group1.Name); Assert.That(ret.Name, Is.EqualTo("my_group")); Assert.That(ret, Is.Not.Null); }
public void AddEntry_UserAlreadyExisting_Throws()//same app,context,obj, user { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); }
public void Group_EmptyGroupName_ThrowsArgumentException() { var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.GetGroupByName(_myApp.Name, ""); }
public void AddEntry_InsertTwiceTheSameUserDifferentObject_EntriesAdded()//same context and App; different object { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var user2 = new SecUser { FirstName = "user2", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; var obj2 = new SecObject { Name = "obj2", Description = "oggetto2", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddUser(_myApp.Name, user2); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj2, user1.Login, null); var l = CaravanDataSource.Security.GetEntriesForUser(_myApp.Name, c1.Name, user1.Login); Assert.That(l.Count(), Is.EqualTo(2)); }
public void AddGroup_validArgs_InsertCorrectGroup_Async(int groupCount) { Parallel.ForEach(Enumerable.Range(1, groupCount), i => { var group = new SecGroup { Name = "my_group" + i }; CaravanDataSource.Security.AddGroup(_myApp.Name, group); }); for (var i = 1; i <= groupCount; ++i) { var q1 = (from g in CaravanDataSource.Security.GetGroups(_myApp.Name) where g.Name == "my_group" + i select g).ToList(); Assert.IsNotNull(q1.FirstOrDefault()); Assert.That(q1.Count, Is.EqualTo(1)); } }
public void RemoveEntry_ValidArgs_EntryRemoved() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var user2 = new SecUser { FirstName = "user2", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; var obj2 = new SecObject { Name = "obj2", Description = "oggetto2", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddUser(_myApp.Name, user2); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj2, user1.Login, null); CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj1.Name, user1.Login, null); CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj2.Name, user1.Login, null); var l = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj1.Name); Assert.That(l.Count(), Is.EqualTo(0)); var l1 = CaravanDataSource.Security.GetEntriesForObject(_myApp.Name, c1.Name, obj2.Name); Assert.That(l1.Count(), Is.EqualTo(0)); }
public void AddGroup_GroupAlreadyExisting_ThrowsGroupExistingException() { var group1 = new SecGroup { Name = "my_group" }; var group2 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddGroup(_myApp.Name, group2); }
public void RemoveEntry_EmptyGroupName_Throws() { var c1 = new SecContext { Name = "c1", Description = "context1" }; var group1 = new SecGroup { Name = "my_group" }; var user1 = new SecUser { FirstName = "user1", Login = "******" }; var obj1 = new SecObject { Name = "obj1", Description = "oggetto1", Type = "button" }; CaravanDataSource.Security.AddUser(_myApp.Name, user1); CaravanDataSource.Security.AddGroup(_myApp.Name, group1); CaravanDataSource.Security.AddEntry(_myApp.Name, c1, obj1, user1.Login, null); CaravanDataSource.Security.RemoveEntry(_myApp.Name, c1.Name, obj1.Name, user1.Login, ""); }
public void AddGroup_NullAppName_ThrowsArgumentException() { var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(null, group1); }
public void UpdateGroup_EmptyGroupName_ThrowsArgumentException() { var group1 = new SecGroup { Name = "my_group" }; CaravanDataSource.Security.AddGroup(_myApp.Name, group1); group1.Name = ""; CaravanDataSource.Security.UpdateGroup(_myApp.Name, "my_group", new SecGroupUpdates { Name = group1.Name.ToOption() }); }