/// <summary>
        /// Validates incoming Hello message
        /// </summary>
        /// <param name="message">Hello message</param>
        /// <param name="reason">reason why message is invalid, null if message is valid</param>
        /// <returns>true, if message is valid</returns>
        protected bool ValidateHelloMessage(SoapMessage <WSD.HelloType> message, string[] scopes, out string reason)
        {
            bool res = true;

            reason = null;
            try
            {
                //check Types namespace

                WSD.HelloType hello = message.Object;
                if (hello.Types == null)
                {
                    reason = Resources.ErrorNoTypes_Text;
                    return(false);
                }
                if (!DiscoveryUtils.CheckDeviceHelloType(message, out reason))
                {
                    return(false);
                }
                if (hello.EndpointReference == null)
                {
                    reason = Resources.ErrorNoEndpointReference_Text;
                    return(false);
                }
                if (hello.Scopes == null)
                {
                    reason = Resources.ErrorNoScopes_Text;
                    return(false);
                }
                if (hello.Scopes.Text == null)
                {
                    reason = Resources.ErrorNoScopesText_Text;
                    return(false);
                }
                //check mandatory scopes
                string missingScope = DiscoveryUtils.GetMissingMandatoryScope(hello.Scopes.Text);
                if (!string.IsNullOrEmpty(missingScope))
                {
                    reason = string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope);
                    return(false);
                }
                //check optional scopes
                if (scopes != null)
                {
                    missingScope = DiscoveryUtils.GetMissingScope(hello.Scopes.Text, scopes);
                    if (!string.IsNullOrEmpty(missingScope))
                    {
                        reason = string.Format(Resources.ErrorMissingScope_Format, missingScope);
                        return(false);
                    }
                }
            }
            catch (Exception e)
            {
                reason = e.Message;
                res    = false;
            }
            return(res);
        }
Example #2
0
        public void SearchDeviceScopeTypesTest()
        {
            RunTest(() =>
            {
                TestTool.Proxies.Onvif.Scope[] scopes = GetScopes();
                string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes);
                Assert(string.IsNullOrEmpty(missingScope),
                       string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope),
                       "Validating device scopes");

                SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, DiscoveryUtils.GetManadatoryScopes());

                string reason = null;
                Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);
            });
        }
Example #3
0
 public void UnicastProbeMessageTest()
 {
     RunTest(() =>
     {
         //5.3
         Scope[] scopes      = GetScopes();
         string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes);
         Assert(string.IsNullOrEmpty(missingScope),
                string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope),
                "Validating device scopes");
         SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(false, DiscoveryUtils.GetManadatoryScopes());
         string reason = null;
         Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);
         //5.4
         probeMatch = ProbeDeviceStep(false, null);
         Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);
         //5.5
         InvalidProbeDeviceStep(false, new string[] { "InvalidScope1", "InvalidScope1" });
     });
 }
        protected void SearchDeviceScopeTypesTestWithTransofrmation(XmlTransformation transformation)
        {
            RunTest(
                () =>
            {
                Scope[] scopes      = GetScopes();
                string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes);
                Assert(string.IsNullOrEmpty(missingScope),
                       string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope),
                       "Validating device scopes");

                XmlNamespacesTransformer transformer = new XmlNamespacesTransformer(transformation, false);

                SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(
                    true,
                    //new DiscoveryUtils.DiscoveryType[][] { DiscoveryUtils.GetOnvif10Type() },
                    null,
                    DiscoveryUtils.GetManadatoryScopes(), null, transformer.ProcessMessage);

                string reason = null;
                Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);
            });
        }
Example #5
0
        public void DeviceScopesConfigurationTest()
        {
            bool scopesAdded = false;

            string[]      newScopes         = null;
            bool          scopesReplaced    = false;
            List <string> oldNonfixedScopes = new List <string>();

            RunTest <string[]>(
                new Backup <string[]>(() => { return(null); }),
                () =>
            {
                //get and validate fixed scopes
                Scope[] scopes = GetScopes();

                string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes);
                Assert(string.IsNullOrEmpty(missingScope),
                       string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope),
                       "Validating device scopes");

                //set fixed scopes fault validation
                SetFixedScopes(scopes);

                //set configurable scopes
                List <string> newNonfixedScopes = new List <string>();
                newNonfixedScopes.Add("onvif://www.onvif.org/" + Guid.NewGuid().ToString());
                foreach (Scope scope in scopes)
                {
                    if (scope.ScopeDef == ScopeDefinition.Configurable)
                    {
                        oldNonfixedScopes.Add(scope.ScopeItem);
                        foreach (string mandatoryScope in DiscoveryUtils.GetManadatoryScopes())
                        {
                            if (scope.ScopeItem.Contains(mandatoryScope))
                            {
                                if (!newNonfixedScopes.Contains(mandatoryScope))
                                {
                                    newNonfixedScopes.Add(mandatoryScope);
                                }
                            }
                        }
                    }
                }
                SetScopes(newNonfixedScopes.ToArray());

                // fix for 10767
                Sleep(2000);

                scopesReplaced = true;

                //add new scopes
                //begin wait before sending AddScopes, because Hello can be sent by NVT before response to AddScopes
                newScopes         = new string[] { "onvif://www.onvif.org/" + Guid.NewGuid().ToString(), "onvif://www.onvif.org/" + Guid.NewGuid().ToString() };
                bool canAddScopes = true;
                SoapMessage <WSD.HelloType> hello = null;
                try
                {
                    hello = ReceiveHelloMessage(
                        true,
                        true,
                        () => {
                        AddScopes(newScopes);
                        scopesAdded = true;
                    });
                }
                catch (FaultException fault)
                {
                    if (fault.IsValidOnvifFault("Receiver/Action/TooManyScopes"))
                    {
                        StepPassed();
                        canAddScopes = false;
                    }
                    else
                    {
                        throw;
                    }
                }
                //According to CR26, if device cannot add scopes, consider test as passed.
                if (canAddScopes)
                {
                    List <string> currentScopes = new List <string>(ScopesToStringArray(scopes)
                                                                    .Except(oldNonfixedScopes).Concat(newNonfixedScopes).Concat(newScopes));
                    string reason;
                    Assert(ValidateHelloMessage(hello, currentScopes.ToArray(), out reason), reason, "Hello message validation");

                    //probe new scopes
                    SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, newScopes);

                    Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);

                    //delete create scopes
                    hello = ReceiveHelloMessage(
                        true,
                        true,
                        () =>
                    {
                        RemoveScopes(newScopes);
                        scopesAdded = false;
                    });

                    Assert(ValidateHelloMessage(hello, currentScopes.Except(newScopes).ToArray(), out reason),
                           reason, "Hello message validation");

                    //probe deleted scopes
                    InvalidProbeDeviceStep(true, newScopes);
                }
            },
                (param) =>
            {
                if (scopesAdded && (newScopes != null))
                {
                    RemoveScopes(newScopes);
                }
                if (scopesReplaced && oldNonfixedScopes.Count > 0)
                {
                    if (oldNonfixedScopes.Count > 0)
                    {
                        SetScopes(oldNonfixedScopes.ToArray());
                    }
                }
            });
        }
        public void DeviceScopesConfigurationTest()
        {
            bool scopesAdded = false;

            string[] newScopes = null;

            RunTest <string[]>(
                new Backup <string[]>(() => { return(null); }),
                () =>
            {
                //get and validate fixed scopes
                Scope[] scopes = GetScopes();

                string missingScope = DiscoveryUtils.GetMissingMandatoryScope(scopes);
                Assert(string.IsNullOrEmpty(missingScope),
                       string.Format(Resources.ErrorMissingMandatoryScope_Format, missingScope),
                       "Validating device scopes");

                //set fixed scopes fault validation
                SetFixedScopes(scopes);

                //add new scopes
                //begin wait before sending AddScopes, because Hello can be sent by NVT before response to AddScopes
                newScopes         = new string[] { "onvif://www.onvif.org/" + Guid.NewGuid().ToString(), "onvif://www.onvif.org/" + Guid.NewGuid().ToString() };
                bool canAddScopes = true;
                SoapMessage <WSD.HelloType> hello = null;
                try
                {
                    hello = ReceiveHelloMessage(
                        true,
                        true,
                        () => {
                        AddScopes(newScopes);
                        scopesAdded = true;
                    });
                }
                catch (FaultException fault)
                {
                    if (fault.IsValidOnvifFault("Receiver/Action/TooManyScopes"))
                    {
                        StepPassed();
                        canAddScopes = false;
                    }
                    else
                    {
                        throw;
                    }
                }
                //According to CR26, if device cannot add scopes, consider test as passed.
                if (canAddScopes)
                {
                    string reason;
                    Assert(ValidateHelloMessage(hello, newScopes, out reason), reason, "Hello message validation");

                    //probe new scopes
                    SoapMessage <WSD.ProbeMatchesType> probeMatch = ProbeDeviceStep(true, newScopes, null);

                    Assert(ValidateProbeMatchMessage(probeMatch, out reason), reason, Resources.StepValidateProbeMatch_Title);

                    //delete create scopes
                    hello = ReceiveHelloMessage(
                        true,
                        true,
                        () =>
                    {
                        RemoveScopes(newScopes);
                        scopesAdded = false;
                    });

                    Assert(ValidateHelloMessage(hello, null, out reason), reason, "Hello message validation");

                    //probe deleted scopes
                    InvalidProbeDeviceStep(true, newScopes);
                }
            },
                (param) =>
            {
                if (scopesAdded && (newScopes != null))
                {
                    RemoveScopes(newScopes);
                }
            });
        }