Exemple #1
0
        public void testPropertyReferenceDenialNoException()
        {
            string[]    strPermissions = { "ViewUsernames" };
            Object2Json o2j;

            LogonDetails sensitiveData = new LogonDetails();

            sensitiveData.Password = "******";
            sensitiveData.Username = "******";
            User user = new User();

            user.Id           = "123";
            user.Nickname     = "Dark Lord";
            user.LogonDetails = sensitiveData;
            //to do check no check code specified situation
            string json;
            JsonExpectationBlock expectation;

            o2j         = createSecureObjectToJson(strPermissions, false, new PropertyReflectionNodeExpander());
            json        = o2j.toJson(user);
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("Id", user.Id, true);
                theMock.JsonLeaf("Nickname", user.Nickname, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testPropertyReferenceDenialNoException (deny)");

            //check that the right permission gives access
            strPermissions = new string[] { "PasswordAdministration" };
            o2j            = createSecureObjectToJson(strPermissions, false, new PropertyReflectionNodeExpander());
            json           = o2j.toJson(user);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("Id", user.Id, true);
                theMock.JsonLeaf("Nickname", user.Nickname, true);
                theMock.JsonStartObject("LogonDetails", json.IndexOf('{', 2));
                theMock.JsonLeaf("Username", user.LogonDetails.Username, true);
                //theMock.JsonLeaf("password", user.logonDetails.password, true);
                theMock.JsonEndObject(testjson.IndexOf("}"));
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testPropertyReferenceDenialNoException (permit)");
        }
Exemple #2
0
        public void testPropertyDenialException()
        {
            string[]    strPermissions = { "viewUsernames" };
            Object2Json o2j            = createSecureObjectToJson(strPermissions, true, new PropertyReflectionNodeExpander());

            LogonDetails sensitiveData = new LogonDetails();

            sensitiveData.Password = "******";
            //to do check no check code specified situation
            object    returnValue;
            Exception exception;

            TestUtil.run(out returnValue, out exception, () =>
            {
                string json = o2j.toJson(sensitiveData);
                return(null);
            });
            Assert.AreEqual(typeof(SecurityException), exception.GetType(), "expect security exception");
            Assert.IsTrue(exception.Message.IndexOf("ViewPasswords") >= 0);
        }
Exemple #3
0
        public void testFieldLeafDenialNoException()
        {
            string []   strPermissions = { "ViewUsernames" };
            Object2Json o2j;

            LogonDetails sensitiveData = new LogonDetails();

            sensitiveData.password = "******";
            sensitiveData.username = "******";
            //to do check no check code specified situation
            string json;
            JsonExpectationBlock expectation;

            o2j  = createSecureObjectToJson(strPermissions, false, new FieldReflectionNodeExpander());
            json = o2j.toJson(sensitiveData);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("username", sensitiveData.username, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testFieldLeafDenialNoException (deny)");

            //check that the right permission gives access
            strPermissions = new string[] { "ViewPasswords" };
            o2j            = createSecureObjectToJson(strPermissions, false, new FieldReflectionNodeExpander());
            json           = o2j.toJson(sensitiveData);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("password", sensitiveData.password, true);
                theMock.JsonLeaf("username", sensitiveData.username, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testFieldLeafDenialNoException (permit)");
        }
        public void testFieldLeafDenialNoException()
        {
            string []strPermissions = {"ViewUsernames"};
            Object2Json o2j;

            LogonDetails sensitiveData = new LogonDetails();
            sensitiveData.password = "******";
            sensitiveData.username = "******";
            //to do check no check code specified situation
            string json;
            JsonExpectationBlock expectation;

            o2j = createSecureObjectToJson(strPermissions, false, new FieldReflectionNodeExpander());
            json = o2j.toJson(sensitiveData);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("username", sensitiveData.username, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testFieldLeafDenialNoException (deny)");

            //check that the right permission gives access
            strPermissions = new string[] {"ViewPasswords"};
            o2j = createSecureObjectToJson(strPermissions, false, new FieldReflectionNodeExpander());
            json = o2j.toJson(sensitiveData);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("password", sensitiveData.password, true);
                theMock.JsonLeaf("username", sensitiveData.username, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testFieldLeafDenialNoException (permit)");
        }
        public void testPropertyReferenceDenialNoException()
        {
            string[] strPermissions = { "ViewUsernames" };
            Object2Json o2j;

            LogonDetails sensitiveData = new LogonDetails();
            sensitiveData.Password = "******";
            sensitiveData.Username = "******";
            User user = new User();
            user.Id = "123";
            user.Nickname = "Dark Lord";
            user.LogonDetails = sensitiveData;
            //to do check no check code specified situation
            string json;
            JsonExpectationBlock expectation;

            o2j = createSecureObjectToJson(strPermissions, false, new PropertyReflectionNodeExpander());
            json = o2j.toJson(user);
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("Id", user.Id, true);
                theMock.JsonLeaf("Nickname", user.Nickname, true);
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testPropertyReferenceDenialNoException (deny)");

            //check that the right permission gives access
            strPermissions = new string[] { "PasswordAdministration" };
            o2j = createSecureObjectToJson(strPermissions, false, new PropertyReflectionNodeExpander());
            json = o2j.toJson(user);
            //test json structure
            expectation = (theMock, testjson) =>
            {
                theMock.JsonStartObject(null, 0);
                theMock.JsonLeaf("Id", user.Id, true);
                theMock.JsonLeaf("Nickname", user.Nickname, true);
                theMock.JsonStartObject("LogonDetails", json.IndexOf('{', 2));
                theMock.JsonLeaf("Username", user.LogonDetails.Username, true);
                //theMock.JsonLeaf("password", user.logonDetails.password, true);
                theMock.JsonEndObject(testjson.IndexOf("}"));
                theMock.JsonEndObject(testjson.LastIndexOf("}"));
            };
            TestUtil.testJsonStructure(json, expectation, "testPropertyReferenceDenialNoException (permit)");
        }
        public void testPropertyDenialException()
        {
            string[] strPermissions = { "viewUsernames" };
            Object2Json o2j = createSecureObjectToJson(strPermissions, true, new PropertyReflectionNodeExpander());

            LogonDetails sensitiveData = new LogonDetails();
            sensitiveData.Password = "******";
            //to do check no check code specified situation
            object returnValue;
            Exception exception;
            TestUtil.run(out returnValue, out exception, () =>
            {
                string json = o2j.toJson(sensitiveData);
                return null;
            });
            Assert.AreEqual(typeof(SecurityException), exception.GetType(), "expect security exception");
            Assert.IsTrue(exception.Message.IndexOf("ViewPasswords") >= 0);
        }