private void IsMatchMailServer(string requestChannel) { IRouter mtaRouter = new Workshare.Policy.Routing.MtaRouter.MtaRouter(); PolicyType policyType = PolicyType.Mta; IUniversalRoutingEntity sourceEntity = new UniversalRoutingEntity(); sourceEntity.PolicyType = policyType; sourceEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; if (!string.IsNullOrEmpty(requestChannel)) sourceEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, requestChannel); IRoutingItem routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); sourceEntity.Items.Add(routingItem); IUniversalRoutingEntity targetEntity = new UniversalRoutingEntity(); targetEntity.PolicyType = policyType; targetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); targetEntity.Items.Add(routingItem); //invalid data Assert.IsFalse(mtaRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(null, targetEntity), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, targetEntity), "Expected nominal case to return false"); }
public void TestIsMatchBlackberry() { IRouter mtaRouter = new Workshare.Policy.Routing.MtaRouter.MtaRouter(); PolicyType policyType = PolicyType.Mta; IUniversalRoutingEntity sourceEntity = new UniversalRoutingEntity(); sourceEntity.PolicyType = policyType; sourceEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Blackberry); IRoutingItem routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); sourceEntity.Items.Add(routingItem); IUniversalRoutingEntity targetEntity = new UniversalRoutingEntity(); targetEntity.PolicyType = policyType; targetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("[email protected]"); routingItem.Properties.Add(SMTPItemPropertyKeys.DisplayName, "[email protected]"); targetEntity.Items.Add(routingItem); //invalid data Assert.IsFalse(mtaRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(sourceEntity, null), "Expected null data to return false"); Assert.IsFalse(mtaRouter.IsMatch(null, targetEntity), "Expected null data to return false"); Assert.IsTrue(mtaRouter.IsMatch(sourceEntity, targetEntity), "Expected nominal case to return true"); }
internal static IUniversalRoutingEntity GetUniversalRoutingEntity(RoutingEntity routingEntity) { if (null == routingEntity) return null; UniversalRoutingEntity routing = new UniversalRoutingEntity(); routing.PolicyType = (PolicyType)Enum.Parse(typeof(PolicyType), routingEntity.PolicyType); routing.RoutingType = routingEntity.RoutingType; routing.Items = new Collection<IRoutingItem>(); if (routingEntity.Items != null) { foreach (Workshare.PolicyContent.RoutingItem routingItem in routingEntity.Items) { Workshare.Policy.Routing.RoutingItem item = new Workshare.Policy.Routing.RoutingItem(routingItem.Content); item.Properties = new Dictionary<string, string>(); if (routingItem.Properties != null) { foreach (CustomProperty custProp in routingItem.Properties) { item.Properties[custProp.Name] = custProp.Value; } } routing.Items.Add(item); } } routing.Properties = new Dictionary<string, string>(); if (routingEntity.Properties != null) { foreach (CustomProperty property in routingEntity.Properties) { routing.Properties[property.Name] = property.Value; } } return routing; }
public UniversalRoutingEntity(UniversalRoutingEntity source) { m_policyType = source.PolicyType; m_routingType = source.RoutingType; m_properties = new Dictionary<string,string>(); foreach (KeyValuePair<string,string> property in source.Properties) { m_properties.Add(property.Key, property.Value); } m_items = new Collection<IRoutingItem>(); foreach (IRoutingItem sourceRoutingItem in source.Items) { RoutingItem routingItem = new RoutingItem(sourceRoutingItem.Content); foreach (KeyValuePair<string, string> property in sourceRoutingItem.Properties) { routingItem.Properties.Add(property.Key, property.Value); } m_items.Add(routingItem); } }
public Collection<IUniversalRoutingEntity> GenerateResponseFromUro() { if (m_uro == null) return null; m_sourceEntity = new UniversalRoutingEntity(); m_sourceEntity.RoutingType = RoutingTypes.Source; m_destinationEntity = new UniversalRoutingEntity(); m_destinationEntity.RoutingType = RoutingTypes.Destination; switch (m_uro.PolicyType) { case PolicyType.ClientEmail: case PolicyType.Mta: ProcessSMTPRouting(); break; case PolicyType.NetMon: ProcessHTTPRouting(); break; case PolicyType.ActiveContent: ProcessActiveContentRouting(); break; case PolicyType.ClientRemovableMedia : ProcessRemovableDeviceRouting(); break; case PolicyType.NetworkContentDiscovery: //Nothing to do. The default source and destination routing entities will suffice. break; default: throw new ArgumentException(""); } Collection<IUniversalRoutingEntity> routingInfo = new Collection<IUniversalRoutingEntity>(); routingInfo.Add(m_sourceEntity); routingInfo.Add(m_destinationEntity); return routingInfo; }
public static void GenerateURORoutingDetails(UniversalRequestObject uro, PolicyType policyType) { UniversalRoutingEntity source = new UniversalRoutingEntity(); source.PolicyType = policyType; source.RoutingType = RoutingTypes.Destination; source.Items.Add(new RoutingItem("*****@*****.**")); UniversalRoutingEntity destination = new UniversalRoutingEntity(); destination.PolicyType = policyType; destination.RoutingType = RoutingTypes.Destination; destination.Items.Add(new RoutingItem("*****@*****.**")); destination.Properties[SMTPPropertyKeys.RequestChannel] = policyType.ToString() ; source.Properties[SMTPPropertyKeys.RequestChannel] = policyType.ToString(); uro.Source = source; uro.Destination = destination; }
public IUniversalRoutingEntity ToUniversalRoutingEntity(string policyType, string routingType, string[] items) { IUniversalRoutingEntity routingEntity = new UniversalRoutingEntity(); PolicyType pt = (PolicyType)Enum.Parse(typeof(PolicyType), policyType); routingEntity.PolicyType = pt; routingEntity.RoutingType = routingType; //routingEntity.Properties = BuildPropertyDictionaryFromString(properties); Collection<IRoutingItem> routingItems = routingEntity.Items; foreach (string item in items) { IRoutingItem routingItem = BuildRoutingItemFromString(item); routingItems.Add(routingItem); } return routingEntity; }
public void TestIsMatch() { IRouter deviceRouter = new Workshare.Policy.Routing.DeviceRouter.DeviceRouter(); IUniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; IRoutingItem routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); sourceEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); sourceEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); sourceEntity1.Items.Add(routingItem); IUniversalRoutingEntity targetEntity1 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientRemovableMedia; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType0"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity1.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity1.Items.Add(routingItem); IUniversalRoutingEntity targetEntity2 = new UniversalRoutingEntity(); targetEntity2.PolicyType = PolicyType.ClientRemovableMedia; targetEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity2.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity2.Items.Add(routingItem); IUniversalRoutingEntity targetEntity3 = new UniversalRoutingEntity(); targetEntity3.PolicyType = PolicyType.ClientRemovableMedia; targetEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity3.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeName2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeName); targetEntity3.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity3.Items.Add(routingItem); IUniversalRoutingEntity targetEntity4 = new UniversalRoutingEntity(); targetEntity4.PolicyType = PolicyType.ClientRemovableMedia; targetEntity4.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity4.Items.Add(routingItem); IUniversalRoutingEntity targetEntity5 = new UniversalRoutingEntity(); targetEntity5.PolicyType = PolicyType.ClientRemovableMedia; targetEntity5.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType1"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity5.Items.Add(routingItem); routingItem = new RoutingItem("MyVolumeId2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.VolumeID); targetEntity5.Items.Add(routingItem); IUniversalRoutingEntity targetEntity6 = new UniversalRoutingEntity(); targetEntity6.PolicyType = PolicyType.ClientRemovableMedia; targetEntity6.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; routingItem = new RoutingItem("MyDeviceType2"); routingItem.Properties.Add(RemovableDeviceItemPropertyKeys.ContentType, RemovableDeviceItemContentTypes.DeviceType); targetEntity6.Items.Add(routingItem); //invalid data Assert.IsFalse(deviceRouter.IsMatch(null, null), "Expected null data to return false"); Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, null), "Expected null data to return false"); Assert.IsFalse(deviceRouter.IsMatch(null, targetEntity1), "Expected null data to return false"); //nominal case. Matching Type, Id and Name are explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected nominal case to return true"); //Matching, but no volume names explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity2), "Expected unstated volume name to return true"); //Not matching, as volume name is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity3), "Expected incorrect volume name to return false"); //Matching, but no volume name or id explicitly listed in target Assert.IsTrue(deviceRouter.IsMatch(sourceEntity1, targetEntity4), "Expected unstated volume id or name to return true"); //Not matching, as volume id is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity5), "Expected incorrect volume id to return false"); //Not matching, as device type is not listed in target Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity6), "Expected incorrect device type to return false"); //different routing types on entities sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching routing types on entities to return false"); //different request types on entities sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity1.PolicyType = PolicyType.ActiveContent; Assert.IsFalse(deviceRouter.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching request types on entities to return false"); }
public void TestIsMatch() { //setup Workshare.Policy.Routing.LDAPRouter router = new Workshare.Policy.Routing.LDAPRouter(); UniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientEmail; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem1 = new RoutingItem("[email protected]"); sourceEntity1.Items.Add(smtpRoutingItem1); UniversalRoutingEntity sourceEntity2 = new UniversalRoutingEntity(); sourceEntity2.PolicyType = PolicyType.ClientEmail; sourceEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem2 = new RoutingItem("[email protected]"); sourceEntity2.Items.Add(smtpRoutingItem2); RoutingItem smtpRoutingItem3 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem3); UniversalRoutingEntity sourceEntity3 = new UniversalRoutingEntity(); sourceEntity3.PolicyType = PolicyType.ClientEmail; sourceEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpRoutingItem4 = new RoutingItem("*****@*****.**"); sourceEntity3.Items.Add(smtpRoutingItem4); UniversalRoutingEntity targetEntity1 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientEmail; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; RoutingItem smtpTargetRoutingItem1 = new RoutingItem("[email protected]"); targetEntity1.Items.Add(smtpTargetRoutingItem1); RoutingItem smtpTargetRoutingItem2 = new RoutingItem("c=US;a= ;p=WSDEV;o=Exchange;s=Pair;g=SF"); targetEntity1.Items.Add(smtpTargetRoutingItem2); UniversalRoutingEntity targetEntity2 = new UniversalRoutingEntity(); targetEntity1.PolicyType = PolicyType.ClientEmail; targetEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //test invalid inputs Assert.IsFalse(router.IsMatch(sourceEntity1, null)); Assert.IsFalse(router.IsMatch(null, targetEntity1)); Assert.IsFalse(router.IsMatch(null, null)); //nominal - all addresses are in target Assert.IsTrue(router.IsMatch(sourceEntity1, targetEntity1), "Expected all addresses in target to return true"); //some, but not all, addresses are in target Assert.IsFalse(router.IsMatch(sourceEntity2, targetEntity1), "Expected some addresses in target to return false"); //no addresses are in target Assert.IsFalse(router.IsMatch(sourceEntity3, targetEntity1), "Expected no addresses in target to return false"); //test mismatching request type sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching request types to return false"); sourceEntity1.PolicyType = PolicyType.ClientEmail; //test mismatching routing type sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected mismatching routing types to return false"); sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //no target routing items Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity2), "Expected no target routing items to return false"); //no source routing items sourceEntity1.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity1, targetEntity1), "Expected no source routing items to return false"); }
IUniversalRoutingEntity GetUniversalEntity(string type, string email, string displayname, string addresstype) { IUniversalRoutingEntity destination = new UniversalRoutingEntity(); destination.PolicyType = PolicyType.ClientEmail; destination.Properties["RequestChannel"] = "Outlook"; destination.RoutingType = type; destination.Items.Add(new RoutingItem(email)); destination.Items[0].Properties["DisplayName"] = displayname; destination.Items[0].Properties["AddressType"] = addresstype; destination.Items[0].Properties["Internal"] = "False"; destination.Items[0].Properties["Modified"] = "False"; return destination; }
public void TestIsMatch() { //set up activation context here so that the real code doesn't try to read the manifest from the nunit shadow cache using (WsActivationContext wsac = new WsActivationContext()) { //test setup Workshare.Policy.Routing.InternalExternalRouter router = new Workshare.Policy.Routing.InternalExternalRouter(); UniversalRoutingEntity sourceEntity1 = new UniversalRoutingEntity(); sourceEntity1.PolicyType = PolicyType.ClientEmail; sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity1.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem1 = new RoutingItem("*****@*****.**"); smtpRoutingItem1.Properties[SMTPItemPropertyKeys.Internal] = true.ToString(); sourceEntity1.Items.Add(smtpRoutingItem1); UniversalRoutingEntity smtpTargetEntity = new UniversalRoutingEntity(); smtpTargetEntity.PolicyType = PolicyType.ClientEmail; smtpTargetEntity.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; smtpTargetEntity.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpTargetRoutingItem = new RoutingItem("Recipients:Internal"); smtpTargetEntity.Items.Add(smtpTargetRoutingItem); //test null data Assert.IsFalse(router.IsMatch(sourceEntity1, null), "Expected null data to return false"); Assert.IsFalse(router.IsMatch(null, smtpTargetEntity), "Expected null data to return false"); Assert.IsFalse(router.IsMatch(null, null), "Expected null data to return false"); //nominal case - includes internal only Assert.IsTrue(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected nominal internal address to return true"); // mixture of internal and external UniversalRoutingEntity sourceEntity2 = new UniversalRoutingEntity(); sourceEntity2.PolicyType = PolicyType.ClientEmail; sourceEntity2.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity2.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem2 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem2); RoutingItem smtpRoutingItem3 = new RoutingItem("*****@*****.**"); sourceEntity2.Items.Add(smtpRoutingItem3); Assert.IsFalse(router.IsMatch(sourceEntity2, smtpTargetEntity), "Expected mixture of internal and external address to return false"); //external only UniversalRoutingEntity sourceEntity3 = new UniversalRoutingEntity(); sourceEntity3.PolicyType = PolicyType.ClientEmail; sourceEntity3.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; sourceEntity3.Properties.Add(SMTPPropertyKeys.RequestChannel, RequestChannels.Outlook); RoutingItem smtpRoutingItem4 = new RoutingItem("*****@*****.**"); sourceEntity3.Items.Add(smtpRoutingItem4); Assert.IsFalse(router.IsMatch(sourceEntity3, smtpTargetEntity), "Expected external address to return false"); //mismatching request type sourceEntity1.PolicyType = PolicyType.ClientRemovableMedia; Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected mismatching request type to return false"); sourceEntity1.PolicyType = PolicyType.ClientEmail; //mismatching routing type sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Destination; Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected mismatching routing type to return false"); sourceEntity1.RoutingType = Workshare.Policy.Routing.RoutingTypes.Source; //no routing items in source sourceEntity2.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity2, smtpTargetEntity), "Expected no routing items in source to return false"); //no routing items in target smtpTargetEntity.Items.Clear(); Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected no routing items in destination to return false"); //no request channel property sourceEntity1.Properties.Remove(SMTPPropertyKeys.RequestChannel); Assert.IsFalse(router.IsMatch(sourceEntity1, smtpTargetEntity), "Expected missing requestchannel property to return false"); } }
public object Clone() { UniversalRoutingEntity ure = new UniversalRoutingEntity(this); return ure; }