// 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; }
private void Compare(StrongNameIdentityPermission p1, StrongNameIdentityPermission p2, string prefix) { Assert.AreEqual(p1.Name, p2.Name, prefix + ".Name"); Assert.AreEqual(p1.PublicKey, p2.PublicKey, prefix + ".PublicKey"); Assert.AreEqual(p1.Version, p2.Version, prefix + ".Version"); Assert.IsFalse(Object.ReferenceEquals(p1, p2), "ReferenceEquals"); }
public void Intersect() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); StrongNameIdentityPermission intersect = (StrongNameIdentityPermission)snip.Intersect(null); Assert.IsNull(intersect, "snip N null"); StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None); intersect = (StrongNameIdentityPermission)snip.Intersect(empty); #if NET_2_0 Assert.IsNull(intersect, "snip N empty"); #else Compare(empty, intersect, "snip U empty"); #endif intersect = (StrongNameIdentityPermission)snip.Intersect(snip); Compare(snip, intersect, "snip U snip"); StrongNameIdentityPermission samePk = new StrongNameIdentityPermission(blob, "novell", new Version(1, 2)); intersect = (StrongNameIdentityPermission)snip.Intersect(samePk); Assert.IsNull(intersect, "(snip N samePk)"); // strange, I would have expected a SNIP with the same public key... }
//</Snippet3> //<Snippet4> // Intersect creates and returns a new permission that is the intersection of the current // permission and the permission specified. private bool IntersectDemo() { bool returnValue = true; StrongNameIdentityPermission snIdPerm1, snIdPerm2, 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")); try { snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Intersect(snIdPerm2); Console.WriteLine("The intersection of MyCompany.MyDepartment.*" + "MyCompany.MyDepartment.MyFile is " + ((StrongNameIdentityPermission)snIdPerm3).Name.ToString()); } catch (Exception e) { Console.WriteLine("An exception was thrown: " + e); returnValue = false; } return(returnValue); }
public void Name_Empty() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); snip.Name = String.Empty; }
//</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); }
public void PermissionStateNone() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); Assert.AreEqual(String.Empty, snip.Name, "Name"); Assert.IsNull(snip.PublicKey, "PublicKey"); Assert.AreEqual("0.0", snip.Version.ToString(), "Version"); SecurityElement se = snip.ToXml(); #if NET_2_0 Assert.IsNull(se.Attribute("Name"), "Xml-Name"); Assert.IsNull(se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion"); #else Assert.AreEqual(String.Empty, se.Attribute("Name"), "Xml-Name"); Assert.AreEqual("0.0", se.Attribute("AssemblyVersion"), "Xml-AssemblyVersion"); #endif Assert.IsNull(se.Attribute("PublicKeyBlob"), "Xml-PublicKeyBlob"); // because Name == String.Empty, which is illegal using the other constructor StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy(); Assert.AreEqual(String.Empty, copy.Name, "Copy-Name"); #if NET_2_0 // Strangely once copied the Name becomes equals to String.Empty in 2.0 [FDBK19351] Assert.IsNull(se.Attribute("AssemblyVersion"), "Copy-Version"); #else Assert.AreEqual("0.0", copy.Version.ToString(), "Copy-Version"); #endif Assert.IsNull(copy.PublicKey, "Copy-PublicKey"); }
public void Intersect_DifferentPermissions() { StrongNameIdentityPermission a = new StrongNameIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); Assert.IsNull(a.Intersect(b)); }
public void IsSubsetOf_DifferentPermissions() { StrongNameIdentityPermission a = new StrongNameIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); a.IsSubsetOf(b); }
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)"); }
public void Union_DifferentPermissions() { StrongNameIdentityPermission a = new StrongNameIdentityPermission(PermissionState.None); SecurityPermission b = new SecurityPermission(PermissionState.None); a.Union(b); }
public void PublicKey_Null() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); snip.PublicKey = null; }
public void FromXml_WrongTag() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); se.Tag = "IMono"; snip.FromXml(se); }
public void FromXml_WrongTagCase() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); se.Tag = "IPERMISSION"; // instead of IPermission snip.FromXml(se); }
public void PublicKey_Multiple_Set() { StrongNameIdentityPermission union = GetUnion(); union.PublicKey = new StrongNamePublicKeyBlob(ecma); Assert.AreEqual(String.Empty, union.Name, "Name"); Assert.IsNotNull(union.PublicKey, "PublicKey"); Assert.AreEqual("0.0", union.Version.ToString(), "Version"); }
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)); }
public void FromXml_WrongVersion() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); se.Attributes.Remove("version"); se.Attributes.Add("version", "2"); snip.FromXml(se); }
public void Version_Multiple_Set() { StrongNameIdentityPermission union = GetUnion(); union.Version = new Version("1.2.3.4"); Assert.AreEqual(String.Empty, union.Name, "Name"); Assert.IsNull(union.PublicKey, "PublicKey"); Assert.AreEqual("1.2.3.4", union.Version.ToString(), "Version"); }
public void Name_Multiple_Set() { StrongNameIdentityPermission union = GetUnion(); union.Name = "oops"; Assert.AreEqual("oops", union.Name, "Name"); Assert.IsNull(union.PublicKey, "PublicKey"); Assert.AreEqual("0.0", union.Version.ToString(), "Version"); }
public void Name_Empty() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); snip.Name = String.Empty; #if !NET_2_0 Assert.AreEqual(String.Empty, snip.Name, "Name"); #endif }
public void FromXml_NoVersion() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", se.Attribute("class")); snip.FromXml(w); }
public void IsSubsetOf() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); Assert.IsFalse(snip.IsSubsetOf(null), "snip.IsSubsetOf (null)"); StrongNameIdentityPermission empty = new StrongNameIdentityPermission(PermissionState.None); Assert.IsTrue(empty.IsSubsetOf(null), "empty.IsSubsetOf (null)"); }
public void Version() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); Assert.AreEqual("1.2.3.4", snip.Version.ToString(), "Version-1"); snip.Version = null; Assert.IsNull(snip.Version, "Version-2"); snip.Version = new Version(1, 2, 3); Assert.AreEqual("1.2.3", snip.Version.ToString(), "Version-3"); }
public void Name() { StrongNamePublicKeyBlob blob = new StrongNamePublicKeyBlob(ecma); StrongNameIdentityPermission snip = new StrongNameIdentityPermission(blob, "mono", new Version(1, 2, 3, 4)); Assert.AreEqual("mono", snip.Name, "Name-1"); snip.Name = null; Assert.IsNull(snip.Name, "Name-2"); snip.Name = "mono"; Assert.AreEqual("mono", snip.Name, "Name-3"); }
public void CreatePermission_OnlyPublicKey() { StrongNameIdentityPermissionAttribute a = new StrongNameIdentityPermissionAttribute(SecurityAction.Assert); a.PublicKey = pk; StrongNameIdentityPermission p = (StrongNameIdentityPermission)a.CreatePermission(); Assert.IsNull(p.Name, "Name"); Assert.AreEqual(pk, p.PublicKey.ToString(), "PublicKey"); Assert.IsNull(p.Version, "Version"); }
public void FromXml_NoClass() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("version", se.Attribute("version")); snip.FromXml(w); // doesn't even care of the class attribute presence }
public void FromXml_NameEmpty() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); snip.FromXml(se); snip.PublicKey = new StrongNamePublicKeyBlob(ecma); snip.Version = new Version("1.2.3.4"); se = snip.ToXml(); snip.FromXml(se); }
public void Copy_NameEmpty() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); snip.PublicKey = new StrongNamePublicKeyBlob(ecma); snip.Version = new Version("1.2.3.4"); // because Name == String.Empty, which is illegal using the other constructor // but (somewhat) required to copy the teo other informations StrongNameIdentityPermission copy = (StrongNameIdentityPermission)snip.Copy(); Assert.IsTrue(copy.Equals(snip), "Equals"); }
public void CreatePermission() { StrongNameIdentityPermissionAttribute a = new StrongNameIdentityPermissionAttribute(SecurityAction.Assert); a.Name = "mono"; a.PublicKey = pk; a.Version = "1.2.3.4"; StrongNameIdentityPermission p = (StrongNameIdentityPermission)a.CreatePermission(); Assert.AreEqual("mono", p.Name, "Name"); Assert.AreEqual(pk, p.PublicKey.ToString(), "PublicKey"); Assert.AreEqual("1.2.3.4", p.Version.ToString(), "Version"); }
public void FromXml_WrongClass() { StrongNameIdentityPermission snip = new StrongNameIdentityPermission(PermissionState.None); SecurityElement se = snip.ToXml(); SecurityElement w = new SecurityElement(se.Tag); w.AddAttribute("class", "Wrong" + se.Attribute("class")); w.AddAttribute("version", se.Attribute("version")); snip.FromXml(w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
//</Snippet5> //<Snippet6> // ToXml creates an XML encoding of the permission and its current state; //FromXml reconstructs a permission with the specified state from the XML encoding. private bool ToFromXmlDemo() { bool returnValue = true; StrongNameIdentityPermission snIdPerm1, snIdPerm2; snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0")); snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None); snIdPerm2.FromXml(snIdPerm1.ToXml()); Console.WriteLine("Result of ToFromXml = " + snIdPerm2.ToString() + "\n"); return(returnValue); }
// IsSubsetOf determines whether the current permission is a subset of the specified permission. private bool IsSubsetOfDemo() { bool returnValue = true; StrongNameIdentityPermission snIdPerm1, snIdPerm2; 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")); if (snIdPerm1.IsSubsetOf(snIdPerm2)) { Console.WriteLine("MyCompany.MyDepartment.* is a subset " + "of MyCompany.MyDepartment.MyFile \n"); } else { Console.WriteLine("MyCompany.MyDepartment.*" + " is not a subset of MyCompany.MyDepartment.MyFile \n"); } return returnValue; }
// Intersect creates and returns a new permission that is the intersection of the current // permission and the permission specified. private bool IntersectDemo() { bool returnValue = true; StrongNameIdentityPermission snIdPerm1, snIdPerm2, 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")); try { snIdPerm3 = (StrongNameIdentityPermission)snIdPerm1.Intersect(snIdPerm2); Console.WriteLine("The intersection of MyCompany.MyDepartment.*" + "MyCompany.MyDepartment.MyFile is " + ((StrongNameIdentityPermission)snIdPerm3).Name.ToString()); } catch (Exception e) { Console.WriteLine("An exception was thrown: " + e); returnValue = false; } return returnValue; }
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(); }
// ToXml creates an XML encoding of the permission and its current state; //FromXml reconstructs a permission with the specified state from the XML encoding. private bool ToFromXmlDemo() { bool returnValue = true; StrongNameIdentityPermission snIdPerm1, snIdPerm2; snIdPerm1 = new StrongNameIdentityPermission(blob, "MyCompany.MyDepartment.*", new Version("1.0.0.0")); snIdPerm2 = new StrongNameIdentityPermission(PermissionState.None); snIdPerm2.FromXml(snIdPerm1.ToXml()); Console.WriteLine("Result of ToFromXml = " + snIdPerm2.ToString() + "\n"); return returnValue; }