Moving micasa 1.5 trunk to Novell forge.

This commit is contained in:
Cameron (Kamran) Mashayekhi
2005-10-11 19:51:00 +00:00
parent 082db33275
commit efe0a5e13c
691 changed files with 116628 additions and 0 deletions

123
c_micasad/test/cache/TestKeyChain.cs vendored Normal file
View File

@@ -0,0 +1,123 @@
#if DEBUG
using System;
using System.Text;
using System.Collections;
//using System.InvalidOperationException;
using NUnit.Framework;
using sscs.common;
namespace sscs.cache
{
[TestFixture]
public class TestKeyChain
{
Secret mysec;
KeyChain mykc;
string secval;
byte[] secbyte;
[SetUp]
public void Init()
{
mykc = new KeyChain("TestingID");
secval= "novell123";
secbyte = Encoding.ASCII.GetBytes(secval);
mysec = new Secret();
mysec.SetKey("testkey");
mysec.SetValue(secbyte);
}
[Test]
public void TestAddSecret()
{
mykc.AddSecret(mysec);
Secret returnsecret = mykc.GetSecret("testkey");
Assert.AreEqual("novell123", Encoding.ASCII.GetString(returnsecret.GetValue("testkey")));
}
[Test]
public void TestAddSecretWithDup()
{
//Add one more with same secret id
byte[] newvalue = Encoding.ASCII.GetBytes("miCASA");
mysec.SetValue(newvalue);
mykc.AddSecret(mysec);
Secret returnsecret = mykc.GetSecret("testkey");
Assert.AreEqual("miCASA", Encoding.ASCII.GetString(returnsecret.GetValue("testkey")));
}
[Test]
[ExpectedException(typeof(SecretNotFoundException))]
public void TestRemoveSecret()
{
mykc.RemoveSecret("testkey");
//Try and get the same.
//Secret sec = mykc.GetSecret("testkey");
}
[Test]
[ExpectedException(typeof(InvalidOperationException))]
public void TestGetAllSecretsWhenNone()
{
// IDictionaryEnumerator myenum = (IDictionaryEnumerator)mykc.GetAllSecrets();
//Object temp = myenum.Current;
}
[Test]
public void TestGetAllSecrets()
{
int count = 0;
byte[] val1 = Encoding.ASCII.GetBytes("val1");
byte[] val2 = Encoding.ASCII.GetBytes("val2");
byte[] val3 = Encoding.ASCII.GetBytes("val3");
Secret sec1 = new Secret("key1", val1);
Secret sec2 = new Secret("key2", val2);
Secret sec3 = new Secret("key3", val3);
mykc.AddSecret(sec1);
mykc.AddSecret(sec2);
mykc.AddSecret(sec3);
IDictionaryEnumerator myenum =(IDictionaryEnumerator) mykc.GetAllSecrets();
while(myenum.MoveNext())
{
count++;
}
Assert.AreEqual(3, mykc.GetNumSecrets());
Assert.AreEqual(3, count);
}
}
}
#endif

55
c_micasad/test/cache/TestSecret.cs vendored Normal file
View File

@@ -0,0 +1,55 @@
#if DEBUG
using System;
using System.Text;
using NUnit.Framework;
namespace sscs.cache
{
[TestFixture]
public class TestSecret
{
[Test]
public void DefaultAddSecret()
{
string someotherstr = "newvalue";
byte[] newval = Encoding.ASCII.GetBytes(someotherstr);
Secret mysec = new Secret();
mysec.SetKey("newkey");
mysec.SetValue(newval);
mysec.SetEpasswd("enhanced");
mysec.SetKey("alternatekey");
Assert.AreEqual("newvalue", Encoding.ASCII.GetString(mysec.GetValue("alternatekey")));
}
[Test]
public void TestAddSecret()
{
string somestr = "novell123";
string someotherstr = "newvalue";
byte[] mybyte = Encoding.ASCII.GetBytes(somestr);
byte[] newval = Encoding.ASCII.GetBytes(someotherstr);
Secret mysec = new Secret("mail", mybyte);
mysec.SetKey("newkey");
mysec.SetValue(newval);
Assert.AreEqual("newkey", mysec.GetKey());
Assert.AreEqual("newvalue", Encoding.ASCII.GetString(mysec.GetValue()));
}
//TBD: Need to Add Timestamp related cases, could be done when we use it
}
}
#endif

128
c_micasad/test/cache/TestSecretStore.cs vendored Normal file
View File

@@ -0,0 +1,128 @@
#if DEBUG
using System;
using System.Text;
using System.Collections;
//using System.InvalidOperationException;
using NUnit.Framework;
using sscs.common;
namespace sscs.cache
{
[TestFixture]
public class TestSecretStore
{
User theuser = null;
UnixUserIdentifier UserId = null;
SecretStore mysec = null;
KeyChain mykc = null;
byte[] secbyte = null;
Secret mysecret = null;
[SetUp]
public void Init()
{
mykc = new KeyChain("TestingID");
mysecret = new Secret();
mysecret.SetKey("testkey");
secbyte = Encoding.ASCII.GetBytes("NOVELL");
mysecret.SetValue(secbyte);
mykc.AddSecret(mysecret);
UserId = new UnixUserIdentifier(420);
theuser = new UnixUser(UserId);
mysec = new SecretStore(theuser);
}
[Test]
public void TestIntialState()
{
Assert.AreEqual(0, mysec.GetNumKeyChains());
// Assert.AreEqual(0, mysec.getRefCount());
Assert.AreEqual(0, mysec.GetSecretStoreState());
}
[Test]
public void TestAddKeyChain()
{
mysec.AddKeyChain(mykc);
Assert.AreEqual(1, mysec.GetNumKeyChains());
Secret returnsec = (mysec.GetKeyChain("TestingID")).GetSecret("testkey");;
Assert.AreEqual("NOVELL", Encoding.ASCII.GetString(returnsec.GetValue("testkey")));
}
[Test]
public void TestRemoveKeyChain()
{
mysec.RemoveKeyChain("TestingID");
Assert.AreEqual(0, mysec.GetNumKeyChains());
Assert.AreEqual(false, mysec.CheckIfKeyChainExists("TestingID"));
}
[Test]
[ExpectedException(typeof(KeyChainDoesNotExistException))]
public void TestRemoveKeyChainAgain()
{
mysec.GetKeyChain("TestingID");
}
[Test]
public void TestGetKeyChainEnumerator()
{
KeyChain mykc1 = new KeyChain("kc1");
KeyChain mykc2 = new KeyChain("kc2");
KeyChain mykc3 = new KeyChain("kc3");
Secret mysecret1 = new Secret("key1", secbyte);
Secret mysecret2 = new Secret("key2", secbyte);
Secret mysecret3 = new Secret("key3", secbyte);
mykc1.AddSecret(mysecret1);
mykc2.AddSecret(mysecret2);
mykc3.AddSecret(mysecret3);
mysec.AddKeyChain(mykc1);
mysec.AddKeyChain(mykc2);
mysec.AddKeyChain(mykc3);
Assert.AreEqual(3, mysec.GetNumKeyChains());
}
}
}
#endif