Beispiel #1
0
        public void Union()
        {
            StrongNamePublicKeyBlob      blob = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));

            StrongNameIdentityPermission union = (StrongNameIdentityPermission)snip.Union(null);

            Compare(snip, union, "snip U null");

            StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None);

            union = (StrongNameIdentityPermission)snip.Union(empty);
            Compare(snip, union, "snip U empty");

            union = (StrongNameIdentityPermission)snip.Union(snip);
            Compare(snip, union, "snip U snip");

            // note: can't be tested with PermissionState.Unrestricted

            StrongNameIdentityPermission samePk = new StrongNameIdentityPermission(blob, null, null);

            union = (StrongNameIdentityPermission)snip.Union(samePk);
#if !NET_2_0
            // can't compare the properties with multiple entries
            Compare(snip, union, "snip U samePk");
#endif
            Assert.IsTrue(snip.IsSubsetOf(union), "snip.IsSubsetOf (union)");

            union = (StrongNameIdentityPermission)samePk.Union(snip);
#if !NET_2_0
            // can't compare the properties with multiple entries
            Compare(snip, union, "samePk U snip");
#endif
            Assert.IsTrue(samePk.IsSubsetOf(union), "snip.IsSubsetOf (union)");
        }
Beispiel #2
0
        public void Union_DifferentPermissions()
        {
            StrongNameIdentityPermission a = new StrongNameIdentityPermission(PermissionState.None);
            SecurityPermission           b = new SecurityPermission(PermissionState.None);

            a.Union(b);
        }
Beispiel #3
0
    //</Snippet2>
    //<Snippet3>
    // Union creates a new permission that is the union of the current permission and the specified permission.
    private bool UnionDemo()
    {
        bool returnValue = true;

        StrongNameIdentityPermission snIdPerm1, snIdPerm2;
        IPermission snIdPerm3;

        snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
        snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));

        snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Union(snIdPerm2);

        try
        {
            Console.WriteLine("The union of MyCompany.MyDepartment.*" +
                              "and MyCompany.MyDepartment.MyFile is " +
                              ((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
        }
        catch (Exception e)
        {
            Console.WriteLine("An expected exception was thrown: " + e.Message);
        }

        return(returnValue);
    }
Beispiel #4
0
	// Union creates a new permission that is the union of the current permission and the specified permission. 
	private bool UnionDemo()
	{

		bool returnValue = true;

		StrongNameIdentityPermission snIdPerm1, snIdPerm2;
		IPermission snIdPerm3;

		snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0"));
		snIdPerm2 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.MyFile", new Version("1.0.0.0"));
		Console.WriteLine("About to unionise");
		snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Union(snIdPerm2);
		Console.WriteLine("We unionised but the union leaders are in league with the company management!");
		try
		{
			Console.WriteLine("The union of MyCompany.MyDepartment.*" +
			"and MyCompany.MyDepartment.MyFile is " +
			((StrongNameIdentityPermission)snIdPerm3).Name.ToString());
		}
		catch (Exception e)
		{
			Console.WriteLine("An expected exception was thrown: " + e.Message);
		}


		return returnValue;

	}
Beispiel #5
0
        private StrongNameIdentityPermission GetUnion()
        {
            StrongNamePublicKeyBlob      blob   = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip   = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));
            StrongNamePublicKeyBlob      blob2  = new StrongNamePublicKeyBlob(new byte[16]);
            StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission(blob2, "mono", new Version(1, 2, 3, 4));

            return((StrongNameIdentityPermission)snip.Union(diffPk));
        }
Beispiel #6
0
        public static void StrongNameIdentityPermissionCallMethods()
        {
            StrongNameIdentityPermission snip  = new StrongNameIdentityPermission(new Permissions.PermissionState());
            StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new Version(1, 2));
            IPermission ip       = snip.Copy();
            IPermission ip2      = snip.Intersect(ip);
            bool        testbool = snip.IsSubsetOf(ip);

            ip2 = snip.Union(ip);
            SecurityElement se = new SecurityElement("");

            snip.FromXml(se);
            se = snip.ToXml();
        }
Beispiel #7
0
        public void Union_SamePublicKey_DifferentVersion()
        {
            StrongNamePublicKeyBlob      blob        = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip        = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));
            StrongNameIdentityPermission diffVersion = new StrongNameIdentityPermission(blob, null, new Version(1, 2));
            StrongNameIdentityPermission result      = (StrongNameIdentityPermission)snip.Union(diffVersion);

            Assert.IsNotNull(result, "DifferentVersion");
            // new XML format is used to contain more than one site
            SecurityElement se = result.ToXml();

            Assert.AreEqual(2, se.Children.Count, "Childs");
            Assert.AreEqual("1.2.3.4", (se.Children [0] as SecurityElement).Attribute("AssemblyVersion"), "AssemblyVersion#1");
            Assert.AreEqual("1.2", (se.Children [1] as SecurityElement).Attribute("AssemblyVersion"), "AssemblyVersion#2");
            // strangely it is still versioned as 'version="1"'.
            Assert.AreEqual("1", se.Attribute("version"), "Version");
        }
Beispiel #8
0
        public void Union_DifferentPk()
        {
            StrongNamePublicKeyBlob      blob   = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip   = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));
            StrongNamePublicKeyBlob      blob2  = new StrongNamePublicKeyBlob(new byte [16]);
            StrongNameIdentityPermission diffPk = new StrongNameIdentityPermission(blob2, "mono", new Version(1, 2, 3, 4));
            StrongNameIdentityPermission result = (StrongNameIdentityPermission)snip.Union(diffPk);

            Assert.IsNotNull(result, "DifferentPk");
            // new XML format is used to contain more than one site
            SecurityElement se = result.ToXml();

            Assert.AreEqual(2, se.Children.Count, "Childs");
            Assert.AreEqual("00000000000000000400000000000000", (se.Children [0] as SecurityElement).Attribute("PublicKeyBlob"), "Blob#1");
            Assert.AreEqual("00000000000000000000000000000000", (se.Children [1] as SecurityElement).Attribute("PublicKeyBlob"), "Blob#2");
            // strangely it is still versioned as 'version="1"'.
            Assert.AreEqual("1", se.Attribute("version"), "Version");
        }
Beispiel #9
0
        public void Union_SamePublicKey_DifferentName()
        {
            StrongNamePublicKeyBlob      blob     = new StrongNamePublicKeyBlob(ecma);
            StrongNameIdentityPermission snip     = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4));
            StrongNameIdentityPermission diffName = new StrongNameIdentityPermission(blob, "novell", null);
            StrongNameIdentityPermission result   = (StrongNameIdentityPermission)snip.Union(diffName);

#if NET_2_0
            Assert.IsNotNull(result, "DifferentName");
            // new XML format is used to contain more than one site
            SecurityElement se = result.ToXml();
            Assert.AreEqual(2, se.Children.Count, "Childs");
            Assert.AreEqual("mono", (se.Children [0] as SecurityElement).Attribute("Name"), "Name#1");
            Assert.AreEqual("novell", (se.Children [1] as SecurityElement).Attribute("Name"), "Name#2");
            // strangely it is still versioned as 'version="1"'.
            Assert.AreEqual("1", se.Attribute("version"), "Version");
#else
            Assert.IsNull(result, "DifferentName");
#endif
        }
Beispiel #10
0
 public static void StrongNameIdentityPermissionCallMethods()
 {
     StrongNameIdentityPermission snip = new StrongNameIdentityPermission(new Permissions.PermissionState());
     StrongNameIdentityPermission snip2 = new StrongNameIdentityPermission(new Permissions.StrongNamePublicKeyBlob(new byte[1]), "test", new System.Version(1, 2));
     IPermission ip = snip.Copy();
     IPermission ip2 = snip.Intersect(ip);
     bool testbool = snip.IsSubsetOf(ip);
     ip2 = snip.Union(ip);
     SecurityElement se = new SecurityElement("");
     snip.FromXml(se);
     se = snip.ToXml();
 }