示例#1
0
        public void DeclareSecurePropertyTest()
        {
            var testPW    = "testpassword123YYY###$$$";
            var testThing = new TheThing();

            TheThing.SetSafePropertyString(testThing, "Password", testPW);

            var testPWReadNotEncrypted = TheThing.GetSafePropertyString(testThing, "Password");

            Assert.AreSame(testPW, testPWReadNotEncrypted, "Failed to read ununecrypted property");

            testThing.DeclareSecureProperty("Password", ePropertyTypes.TString);

            var testPWReadNotEncryptedObject = testThing.GetProperty("Password").Value;

            Assert.IsTrue(testPWReadNotEncryptedObject is string, $"Encrypted password is not of type string. Type: {testPWReadNotEncryptedObject.GetType()}");
            var testPWReadObjectString = testPWReadNotEncryptedObject as string;

            Assert.AreNotSame(testPW, testPWReadObjectString, "Password not encrypted after transition from unsecure to secure property");

            Assert.IsTrue((testPWReadNotEncryptedObject as string).StartsWith("&^CDESP1^&:"), "Encrypted string does not have expected encryption prefix");
            var testPWReadDecryptedString = TheThing.GetSafePropertyString(testThing, "Password");

            Assert.AreEqual(testPW, testPWReadDecryptedString, "Password not preserved after transition from unsecure to secure property");
        }