private void ExecuteRequest(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null, string token = null) { Task.Run(async() => { _capabilitiesType = capabilitiesType; _url = RemoveTrailingSlash(url); var requestUri = $"{_url}?f=json"; if (!string.IsNullOrEmpty(token)) { requestUri = $"{requestUri}&token={token}"; } var handler = new HttpClientHandler { Credentials = credentials ?? CredentialCache.DefaultCredentials }; var client = new HttpClient(handler) { Timeout = TimeSpan.FromMilliseconds(TimeOut) }; var response = await client.GetAsync(requestUri); if (!response.IsSuccessStatusCode) { OnCapabilitiesFailed(new EventArgs()); return; } try { var dataStream = await response.Content.ReadAsStringAsync(); if (_capabilitiesType == CapabilitiesType.DynamicServiceCapabilities) { _arcGisCapabilities = JsonConvert.DeserializeObject <ArcGISDynamicCapabilities>(dataStream); } else if (_capabilitiesType == CapabilitiesType.ImageServiceCapabilities) { _arcGisCapabilities = JsonConvert.DeserializeObject <ArcGISImageCapabilities>(dataStream); } _arcGisCapabilities.ServiceUrl = _url; //Hack because ArcGIS Server doesn't always return a normal StatusCode if (dataStream.Contains("{\"error\":{\"")) { OnCapabilitiesFailed(EventArgs.Empty); return; } OnFinished(EventArgs.Empty); } catch (Exception ex) { Logger.Log(LogLevel.Error, ex.Message, ex); OnCapabilitiesFailed(EventArgs.Empty); } }); }
/// <summary> /// Get the capabilities of an ArcGIS Map Service /// </summary> /// <param name="url">Url of map service example: http://url/arcgis/rest/services/test/MapServer </param> /// <param name="capabilitiesType"></param> /// <param name="credentials">Credentials to access the service </param> public void GetCapabilities(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null) { _capabilitiesType = capabilitiesType; //Check if user added a trailing slash and remove if exist, some webservers can't handle this _url = url; if (url[url.Length - 1].Equals('/')) _url = url.Remove(url.Length - 1); var requestUri = string.Format("{0}?f=json", _url); _webRequest = (HttpWebRequest)WebRequest.Create(requestUri); if (credentials == null) _webRequest.UseDefaultCredentials = true; else _webRequest.Credentials = credentials; _webRequest.BeginGetResponse(FinishWebRequest, null); }
private void ExecuteRequest(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null, string token = null) { _capabilitiesType = capabilitiesType; _url = RemoveTrailingSlash(url); var requestUri = $"{_url}?f=json"; if (!string.IsNullOrEmpty(token)) { requestUri = $"{requestUri}&token={token}"; } _webRequest = (HttpWebRequest)WebRequest.Create(requestUri); if (credentials == null) { _webRequest.UseDefaultCredentials = true; } else { _webRequest.Credentials = credentials; } _webRequest.BeginGetResponse(FinishWebRequest, null); }
/// <summary> /// Get the capabilities of an ArcGIS Map Service /// </summary> /// <param name="url">Url of map service example: http://url/arcgis/rest/services/test/MapServer </param> /// <param name="capabilitiesType"></param> /// <param name="credentials">Credentials to access the service </param> public void GetCapabilities(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null) { _capabilitiesType = capabilitiesType; //Check if user added a trailing slash and remove if exist, some webservers can't handle this _url = url; if (url[url.Length - 1].Equals('/')) { _url = url.Remove(url.Length - 1); } var requestUri = string.Format("{0}?f=json", _url); _webRequest = (HttpWebRequest)WebRequest.Create(requestUri); if (credentials == null) { _webRequest.UseDefaultCredentials = true; } else { _webRequest.Credentials = credentials; } _webRequest.BeginGetResponse(FinishWebRequest, null); }
private void ExecuteRequest(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null, string token = null) { _capabilitiesType = capabilitiesType; _url = RemoveTrailingSlash(url); var requestUri = $"{_url}?f=json"; if (!string.IsNullOrEmpty(token)) requestUri = $"{requestUri}&token={token}"; _webRequest = (HttpWebRequest)WebRequest.Create(requestUri); if (credentials == null) _webRequest.UseDefaultCredentials = true; else _webRequest.Credentials = credentials; _webRequest.BeginGetResponse(FinishWebRequest, null); }
/// <summary> /// Get the capabilities of an ArcGIS Map Service /// </summary> /// <param name="url">Url of map service example: http://url/arcgis/rest/services/test/MapServer </param> /// <param name="capabilitiesType"></param> /// <param name="credentials">Credentials to access the service </param> public void GetCapabilities(string url, CapabilitiesType capabilitiesType, ICredentials credentials = null) { ExecuteRequest(url, capabilitiesType, credentials); }
/// <summary> /// Get the capabilities of an ArcGIS Map Service /// </summary> /// <param name="url">Url of map service example: http://url/arcgis/rest/services/test/MapServer </param> /// <param name="capabilitiesType"></param> /// <param name="token">Token string to access the service </param> public void GetCapabilities(string url, CapabilitiesType capabilitiesType, string token = null) { ExecuteRequest(url, capabilitiesType, null, token); }
/// <summary> /// Get the capabilities of an ArcGIS Map Service /// </summary> /// <param name="url">Url of map service example: http://url/arcgis/rest/services/test/MapServer </param> /// <param name="capabilitiesType"></param> public void GetCapabilities(string url, CapabilitiesType capabilitiesType) { ExecuteRequest(url, capabilitiesType); }
/// <summary> /// Send ValidateNegotiateInfoRequest to Server, fill in the fields according to params. /// Verify the response. /// </summary> public void ValidateNegotiateInfoRequest(DialectType dialectType, CapabilitiesType capabilitiesType, SecurityModeType securityModeType, ClientGuidType clientGuidType) { Capabilities_Values capbilities = Connection_ClientCapabilities; if (capabilitiesType == CapabilitiesType.CapabilitiesDifferentFromNegotiate) { capbilities ^= Capabilities_Values.GLOBAL_CAP_DFS; } SecurityMode_Values securityMode = Connection_ClientSecurityMode; if (securityModeType == SecurityModeType.SecurityModeDifferentFromNegotiate) { securityMode ^= SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED; } Guid guid = clientGuidType == ClientGuidType.ClientGuidSameWithNegotiate ? Connection_ClientGuid : Guid.NewGuid(); DialectRevision[] dialects = null; if (DialectType.None != dialectType) { ModelDialectRevision dialect = Connection_Dialect; if (DialectType.DialectDifferentFromNegotiate == dialectType) { dialect = ModelDialectRevision.Smb30 == Connection_Dialect ? ModelDialectRevision.Smb21 : ModelDialectRevision.Smb30; } dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)); } else { dialects = new DialectRevision[] { 0 } }; VALIDATE_NEGOTIATE_INFO_Request validateNegotiateInfoRequest; validateNegotiateInfoRequest.Dialects = dialects; validateNegotiateInfoRequest.DialectCount = (ushort)dialects.Length; validateNegotiateInfoRequest.Capabilities = capbilities; validateNegotiateInfoRequest.SecurityMode = securityMode; validateNegotiateInfoRequest.Guid = guid; Site.Log.Add( LogEntryKind.Debug, "Dialects in ValidateNegotiateInfoRequest: {0}", Smb2Utility.GetArrayString(validateNegotiateInfoRequest.Dialects)); Site.Log.Add( LogEntryKind.Debug, "DialectCount in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.DialectCount); Site.Log.Add( LogEntryKind.Debug, "Capabilities in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Capabilities); Site.Log.Add( LogEntryKind.Debug, "SecurityMode in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.SecurityMode); Site.Log.Add( LogEntryKind.Debug, "Guid in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Guid); byte[] inputBuffer = TypeMarshal.ToBytes <VALIDATE_NEGOTIATE_INFO_Request>(validateNegotiateInfoRequest); byte[] outputBuffer; try { uint status = testClient.ValidateNegotiateInfo(treeId, inputBuffer, out outputBuffer, checker: CheckIoCtlResponse); if (Smb2Status.STATUS_SUCCESS == status) { VALIDATE_NEGOTIATE_INFO_Response validateNegotiateInfoResponse = TypeMarshal.ToStruct <VALIDATE_NEGOTIATE_INFO_Response>(outputBuffer); Site.Assert.AreEqual(negotiateResponse.DialectRevision, validateNegotiateInfoResponse.Dialect, "Dialect in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.DialectRevision.ToString(), validateNegotiateInfoResponse.Dialect.ToString()); Site.Assert.AreEqual((uint)negotiateResponse.Capabilities, (uint)validateNegotiateInfoResponse.Capabilities, "Capabilities in Negotiate response({0}) and ValidateNegotiateResponse({1}) should be the same", negotiateResponse.Capabilities.ToString(), validateNegotiateInfoResponse.Capabilities.ToString()); Site.Assert.AreEqual((ushort)negotiateResponse.SecurityMode, (ushort)validateNegotiateInfoResponse.SecurityMode, "SecurityMode in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.SecurityMode.ToString(), validateNegotiateInfoResponse.SecurityMode.ToString()); Site.Assert.AreEqual(negotiateResponse.ServerGuid, validateNegotiateInfoResponse.Guid, "ClientGuid in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.ServerGuid.ToString(), validateNegotiateInfoResponse.Guid.ToString()); } testClient.TreeDisconnect(treeId); testClient.LogOff(); testClient.Disconnect(); this.ValidateNegotiateInfoResponse((ModelSmb2Status)status, validateNegotiateInfoConfig); return; } catch { } Site.Assert.IsTrue(testClient.Smb2Client.IsServerDisconnected, "ValidateNegotiationInfo failure should be caused by transport connection termination"); TerminateConnection(); }
private static void Run() { var client = new RestClient(OGCSOSCopierConfig.SOURCE_SOS_URL); var request = new RestRequest(Method.GET); request.Parameters.Clear(); request.AddParameter("service", "SOS"); request.AddParameter("version", OGCSOSCopierConfig.SOURCE_SOS_VERSION); request.AddParameter("request", "GetCapabilities"); request.AddHeader("Accept", "application/xml"); IRestResponse response = client.Execute(request); var content = response.Content; if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { XmlSerializer serializer2 = new XmlSerializer(typeof(ExceptionReport)); ExceptionReport exceptionReport = null; using (TextReader reader = new StringReader(content)) { exceptionReport = (ExceptionReport)serializer2.Deserialize(reader); } if (exceptionReport != null && exceptionReport.Exception != null && exceptionReport.Exception[0] != null && exceptionReport.Exception[0].ExceptionText[0] != null) { throw new Exception(exceptionReport.Exception[0].ExceptionText[0]); } else { throw new Exception(); } } if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception("Source url returns " + response.StatusCode); } XmlSerializer serializer = new XmlSerializer(typeof(CapabilitiesType)); CapabilitiesType capabilitiesResponse = null; try { using (TextReader reader = new StringReader(content)) { capabilitiesResponse = (CapabilitiesType)serializer.Deserialize(reader); } } catch (Exception exp) { } if (capabilitiesResponse.contents == null || capabilitiesResponse.contents.Contents == null || capabilitiesResponse.contents.Contents.offering == null || capabilitiesResponse.contents.Contents.offering.Length == 0) { throw new Exception("Offering not found!"); } _capabilitiesResponse = capabilitiesResponse; }
public GetCapabilitiesRequestHandler() { _capabilitiesResponse = null; Run(); }
public static void ValidateNegotiateInfoRequest(DialectType dialectType, CapabilitiesType capabilitiesType, SecurityModeType securityModeType, ClientGuidType clientGuidType) { Condition.IsTrue(State == ModelState.Connected); // Those four parameters don’t need to be full-mesh. Combination.Isolated(DialectType.None == dialectType); Combination.Isolated(DialectType.DialectDifferentFromNegotiate == dialectType); Combination.Isolated(capabilitiesType == CapabilitiesType.CapabilitiesDifferentFromNegotiate); Combination.Isolated(securityModeType == SecurityModeType.SecurityModeDifferentFromNegotiate); Combination.Isolated(clientGuidType == ClientGuidType.ClientGuidDifferentFromNegotiate); if (DialectType.DialectSameWithNegotiate != dialectType) { ModelHelper.Log( LogType.Requirement, "3.3.5.15.12: The server MUST determine the greatest common dialect between the dialects it implements and the Dialects array of the VALIDATE_NEGOTIATE_INFO request." + " If no dialect is matched, or if the value is not equal to Connection.Dialect, the server MUST terminate the transport connection and free the Connection object"); ModelHelper.Log( LogType.TestInfo, "No dialect is matched between the dialects it implements and the Dialects array of the VALIDATE_NEGOTIATE_INFO request, or if the value is not equal to Connection.Dialect"); ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields); IsSameWithNegotiate = false; } if (capabilitiesType == CapabilitiesType.CapabilitiesDifferentFromNegotiate) { ModelHelper.Log( LogType.Requirement, "3.3.5.15.12: If Connection.ClientCapabilities is not equal to the Capabilities received in the VALIDATE_NEGOTIATE_INFO request structure, the server MUST terminate the transport connection and free the Connection object"); ModelHelper.Log( LogType.TestInfo, "Connection.ClientCapabilities is not equal to the Capabilities received in the VALIDATE_NEGOTIATE_INFO request"); ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields); IsSameWithNegotiate = false; } if (securityModeType == SecurityModeType.SecurityModeDifferentFromNegotiate) { ModelHelper.Log( LogType.Requirement, "3.3.5.15.12: If the SecurityMode received in the VALIDATE_NEGOTIATE_INFO request structure is not equal to Connection.ClientSecurityMode, the server MUST terminate the transport connection and free the Connection object"); ModelHelper.Log( LogType.TestInfo, "SecurityMode received in the VALIDATE_NEGOTIATE_INFO request structure is not equal to Connection.ClientSecurityMode"); ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields); IsSameWithNegotiate = false; } if (clientGuidType == ClientGuidType.ClientGuidDifferentFromNegotiate) { ModelHelper.Log( LogType.Requirement, "3.3.5.15.12: If the Guid received in the VALIDATE_NEGOTIATE_INFO request structure is not equal to the Connection.ClientGuid, the server MUST terminate the transport connection and free the Connection object"); ModelHelper.Log( LogType.TestInfo, "Guid received in the VALIDATE_NEGOTIATE_INFO request structure is not equal to the Connection.ClientGuid"); ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields); IsSameWithNegotiate = false; } }
/// <summary> /// Send ValidateNegotiateInfoRequest to Server, fill in the fields according to params. /// Verify the response. /// </summary> public void ValidateNegotiateInfoRequest(DialectType dialectType, CapabilitiesType capabilitiesType, SecurityModeType securityModeType, ClientGuidType clientGuidType) { Capabilities_Values capbilities = Connection_ClientCapabilities; if (capabilitiesType == CapabilitiesType.CapabilitiesDifferentFromNegotiate) capbilities ^= Capabilities_Values.GLOBAL_CAP_DFS; SecurityMode_Values securityMode = Connection_ClientSecurityMode; if (securityModeType == SecurityModeType.SecurityModeDifferentFromNegotiate) securityMode ^= SecurityMode_Values.NEGOTIATE_SIGNING_ENABLED; Guid guid = clientGuidType == ClientGuidType.ClientGuidSameWithNegotiate ? Connection_ClientGuid : Guid.NewGuid(); DialectRevision[] dialects = null; if (DialectType.None != dialectType) { ModelDialectRevision dialect = Connection_Dialect; if (DialectType.DialectDifferentFromNegotiate == dialectType) dialect = ModelDialectRevision.Smb30 == Connection_Dialect ? ModelDialectRevision.Smb21 : ModelDialectRevision.Smb30; dialects = Smb2Utility.GetDialects(ModelUtility.GetDialectRevision(dialect)); } else dialects = new DialectRevision[] { 0 }; VALIDATE_NEGOTIATE_INFO_Request validateNegotiateInfoRequest; validateNegotiateInfoRequest.Dialects = dialects; validateNegotiateInfoRequest.DialectCount = (ushort)dialects.Length; validateNegotiateInfoRequest.Capabilities = capbilities; validateNegotiateInfoRequest.SecurityMode = securityMode; validateNegotiateInfoRequest.Guid = guid; Site.Log.Add( LogEntryKind.Debug, "Dialects in ValidateNegotiateInfoRequest: {0}", Smb2Utility.GetArrayString(validateNegotiateInfoRequest.Dialects)); Site.Log.Add( LogEntryKind.Debug, "DialectCount in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.DialectCount); Site.Log.Add( LogEntryKind.Debug, "Capabilities in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Capabilities); Site.Log.Add( LogEntryKind.Debug, "SecurityMode in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.SecurityMode); Site.Log.Add( LogEntryKind.Debug, "Guid in ValidateNegotiateInfoRequest: {0}", validateNegotiateInfoRequest.Guid); byte[] inputBuffer = TypeMarshal.ToBytes<VALIDATE_NEGOTIATE_INFO_Request>(validateNegotiateInfoRequest); byte[] outputBuffer; try { uint status = testClient.ValidateNegotiateInfo(treeId, inputBuffer, out outputBuffer, checker: CheckIoCtlResponse); if (Smb2Status.STATUS_SUCCESS == status) { VALIDATE_NEGOTIATE_INFO_Response validateNegotiateInfoResponse = TypeMarshal.ToStruct<VALIDATE_NEGOTIATE_INFO_Response>(outputBuffer); Site.Assert.AreEqual(negotiateResponse.DialectRevision, validateNegotiateInfoResponse.Dialect, "Dialect in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.DialectRevision.ToString(), validateNegotiateInfoResponse.Dialect.ToString()); Site.Assert.AreEqual((uint)negotiateResponse.Capabilities, (uint)validateNegotiateInfoResponse.Capabilities, "Capabilities in Negotiate response({0}) and ValidateNegotiateResponse({1}) should be the same", negotiateResponse.Capabilities.ToString(), validateNegotiateInfoResponse.Capabilities.ToString()); Site.Assert.AreEqual((ushort)negotiateResponse.SecurityMode, (ushort)validateNegotiateInfoResponse.SecurityMode, "SecurityMode in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.SecurityMode.ToString(), validateNegotiateInfoResponse.SecurityMode.ToString()); Site.Assert.AreEqual(negotiateResponse.ServerGuid, validateNegotiateInfoResponse.Guid, "ClientGuid in Negotiate response({0}) and ValidateNegotiateInfo response({1}) should be the same", negotiateResponse.ServerGuid.ToString(), validateNegotiateInfoResponse.Guid.ToString()); } testClient.TreeDisconnect(treeId); testClient.LogOff(); testClient.Disconnect(); this.ValidateNegotiateInfoResponse((ModelSmb2Status)status, validateNegotiateInfoConfig); return; } catch { } Site.Assert.IsTrue(testClient.Smb2Client.IsServerDisconnected, "ValidateNegotiationInfo failure should be caused by transport connection termination"); TerminateConnection(); }