public void FaultMessageForInvalidRequestTest() { RunTest(() => { Profile[] profiles = GetProfiles(); Assert((profiles != null && profiles.Length > 0), "No profile available", "Check if DUT returned at least one profile"); StreamSetup setup = new StreamSetup(); setup.Transport = new Transport(); setup.Transport.Protocol = TransportProtocol.UDP; setup.Stream = StreamType.RTPUnicast; MessageSpoiler spoiler = new MessageSpoiler(); Dictionary <string, string> namespaces = new Dictionary <string, string>(); namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope"); namespaces.Add("media", "http://www.onvif.org/ver10/media/wsdl"); namespaces.Add("onvif", "http://www.onvif.org/ver10/schema"); Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("/s:Envelope/s:Body/media:GetStreamUri/media:StreamSetup/onvif:Transport/onvif:Protocol", "RTP"); spoiler.Namespaces = namespaces; spoiler.NodesToReplace = replacements; SetBreakingBehaviour(spoiler); try { GetStreamUri(setup, profiles[0].token); } catch (FaultException exception) { bool fault = exception.IsValidOnvifFault(); string reason = "A SOAP 1.2 fault message is invalid"; SaveStepFault(exception); if (!fault) { AssertException ex = new AssertException(reason); StepFailed(ex); throw ex; } else { StepPassed(); } } //RunStep( // () => // { // Client.GetStreamUri(setup, profiles[0].token); // }, // "Get Stream URI - negative test", // "Sender/InvalidArgVal/InvalidStreamSetup"); ResetBreakingBehaviour(); }); }
/// <summary> /// Sets up the channel to spoil the messages (for fault tests) /// </summary> /// <param name="spoiler">Object to process the message.</param> protected void SetBreakingBehaviour(ServiceEndpoint endpoint, MessageSpoiler spoiler) { Binding binding = endpoint.Binding; TestTool.HttpTransport.HttpTransportBindingElement traceElement = (HttpTransport.HttpTransportBindingElement)binding.CreateBindingElements()[1]; if (spoiler != null) { traceElement.Contollers.Add(spoiler); } else { traceElement.Contollers.RemoveAll(c => c is ISoapMessageMutator); } }
public void CapabilitiesFaultTest() { RunTest(() => { MessageSpoiler spoiler = new MessageSpoiler(); Dictionary <string, string> namespaces = new Dictionary <string, string>(); namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope"); namespaces.Add("onvif", "http://www.onvif.org/ver10/device/wsdl"); Dictionary <string, string> replacements = new Dictionary <string, string>(); replacements.Add("/s:Envelope/s:Body/onvif:GetCapabilities/onvif:Category", "XYZ"); spoiler.Namespaces = namespaces; spoiler.NodesToReplace = replacements; SetBreakingBehaviour(spoiler); bool fault = false; string reason = "No SOAP fault returned from the DUT"; try { GetCapabilities(new CapabilityCategory[] { CapabilityCategory.All }); } catch (FaultException exception) { fault = exception.IsValidOnvifFault(); reason = "A SOAP 1.2 fault message is invalid"; SaveStepFault(exception); if (!fault) { AssertException ex = new AssertException(reason); StepFailed(ex); throw ex; } else { StepPassed(); } } }); }
public void UserTokenProfileTest() { bool createUser = false; RunTest(() => { if (string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(_username)) { throw new AssertException("Please enter valid credentials on management tab"); } MessageSpoiler spoiler = new MessageSpoiler(); Dictionary <string, string> namespaces = new Dictionary <string, string>(); namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope"); namespaces.Add("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); namespaces.Add("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); string operationName = _operator.GetSecureAPI(); createUser = operationName == "CreateUsers"; spoiler.Namespaces = namespaces; spoiler.NodesToDelete = new List <string>(); SetBreakingBehaviour(spoiler); spoiler.NodesToDelete.Add("/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsse:Nonce"); RunStep(() => { InvokeOperation(operationName); }, "Sending request to the Device with omitted Nonce", "Sender/NotAuthorized", true); spoiler.NodesToDelete.Clear(); spoiler.NodesToDelete.Add("/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsu:Created"); RunStep(() => { InvokeOperation(operationName); }, "Sending request to the Device with omitted Created", "Sender/NotAuthorized", true); spoiler.NodesToDelete.Clear(); spoiler.AttributesToDelete = new Dictionary <string, string>(); spoiler.AttributesToDelete["/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsse:Password"] = "******"; RunStep(() => { InvokeOperation(operationName); }, "Sending request to the Device with omitted Password/Type", "Sender/NotAuthorized", true); ResetBreakingBehaviour(); RunStep(() => { InvokeOperation(operationName); }, "Sending valid request to the Device"); if (createUser) { DeleteTestUser(); } }, () => { if (createUser) { DeleteTestUser(); } }); }
public void UserTokenProfileTest() { bool createUser = false; RunTest(() => { Assert(!(string.IsNullOrEmpty(_password) || string.IsNullOrEmpty(_username)), "This test cannot be performed without credentials supplied", "Check if credentials were defined"); if (_credentialsProvider != null) { _credentialsProvider.Security = Security.WS; } MessageSpoiler spoiler = new MessageSpoiler(); Dictionary <string, string> namespaces = new Dictionary <string, string>(); namespaces.Add("s", "http://www.w3.org/2003/05/soap-envelope"); namespaces.Add("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); namespaces.Add("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); string operationName = _secureOperation; createUser = operationName == "CreateUsers"; spoiler.Namespaces = namespaces; spoiler.NodesToDelete = new List <string>(); SetBreakingBehaviour(spoiler); spoiler.NodesToDelete.Add("/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsse:Nonce"); RunStep(() => { InvokeOperation(operationName); }, "Sending request to NVT with omitted Nonce", "Sender/NotAuthorized", true); spoiler.NodesToDelete.Clear(); spoiler.NodesToDelete.Add("/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsu:Created"); RunStep(() => { InvokeOperation(operationName); }, "Sending request to NVT with omitted Created", "Sender/NotAuthorized", true); spoiler.NodesToDelete.Clear(); spoiler.AttributesToDelete = new Dictionary <string, string>(); spoiler.AttributesToDelete["/s:Envelope/s:Header/wsse:Security/wsse:UsernameToken/wsse:Password"] = "******"; RunStep(() => { InvokeOperation(operationName); }, "Sending request to NVT with omitted Password/Type", "Sender/NotAuthorized", true); ResetBreakingBehaviour(); RunStep(() => { InvokeOperation(operationName); }, "Sending valid request to NVT"); if (createUser) { DeleteTestUser(); } }, () => { if (createUser) { DeleteTestUser(); } }); }