129 lines
2.5 KiB
C#
129 lines
2.5 KiB
C#
|
#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
|
||
|
|
||
|
|
||
|
|