Inheritance: System.Management.Automation.ArgumentTransformationAttribute
Ejemplo n.º 1
0
        public void TransformTest()
        {
            var attr = new SidAttribute();

            // Test null input.
            Assert.IsNull(attr.Transform(null, null));

            // Test another object.
            Assert.AreEqual(1, attr.Transform(null, 1));

            // Test a string.
            Assert.AreEqual(CurrentSID, attr.Transform(null, CurrentUsername));
        }
Ejemplo n.º 2
0
        public void TransformTest()
        {
            var attr = new SidAttribute();

            // Test null input.
            Assert.IsNull(attr.Transform(null, null));

            // Test another object.
            Assert.AreEqual(1, attr.Transform(null, 1));

            // Test a string.
            Assert.AreEqual(CurrentSID, attr.Transform(null, CurrentUsername));
        }
Ejemplo n.º 3
0
        public void TryParseUsernameTest()
        {
            string param = null;

            // Test a string without backslashes.
            Assert.IsFalse(SidAttribute.TryParseUsername(@"foo", out param));
            Assert.IsNull(param);

            // Test a string with backslashes but not a valid username.
            Assert.IsFalse(SidAttribute.TryParseUsername(@"foo\bar\baz", out param));
            Assert.IsNull(param);

            // Test a valid username.
            Assert.IsTrue(SidAttribute.TryParseUsername(CurrentUsername, out param));
            Assert.AreEqual <string>(CurrentSID, param);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Transforms user account identifiers to security identifiers.
        /// </summary>
        /// <param name="engineIntrinsics">Provides access to the APIs for managing the transformation context.</param>
        /// <param name="inputData">The parameter argument that is to be transformed.</param>
        /// <returns>The transformed object.</returns>
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            // null may be allowed, so pass it through.
            if (inputData == null)
            {
                return(null);
            }

            // Convert account information to SDDL format.
            string username;

            if (LanguagePrimitives.TryConvertTo <string>(inputData, out username))
            {
                string sddl;
                if (SidAttribute.TryParseUsername(username, out sddl))
                {
                    return(sddl);
                }
            }

            // Fallback to returning the original input data to further transformations.
            return(inputData);
        }