/// <summary> /// Fires the <see cref="RequestSending"/> event. /// </summary> /// <param name="action">The action that is being sent.</param> /// <param name="request">The request that is being sent.</param> protected virtual void FireRequestSending(string action, ServerRequest request) { if (RequestSending != null) { RequestSending(this, new CommunicationsEventArgs(action, request)); } }
public void EqualsMatchesRequestWithTheSameIdentifier() { ServerRequest request1 = new ServerRequest(); ServerRequest request2 = new ServerRequest(); request1.Identifier = request2.Identifier; Assert.IsTrue(request1.Equals(request2)); }
/// <summary> /// Sends a message to a remote server. /// </summary> /// <param name="action">The action to perform.</param> /// <param name="request">The request to send to the server.</param> /// <returns>The response from the server.</returns> public Response SendMessage(string action, ServerRequest request) { // Make sure there is a password if ((cryptoKey.Length == 0) || (cryptoIv.Length == 0)) InitialisePassword(); // Generate the encrypted request var encryptedRequest = new EncryptedRequest(); encryptedRequest.Action = action; var crypto = new RijndaelManaged(); crypto.Key = cryptoKey; crypto.IV = cryptoIv; encryptedRequest.EncryptedData = EncryptMessage(crypto, request.ToString()); // Send the request var response = innerConnection.SendMessage("ProcessSecureRequest", encryptedRequest); var encryptedResponse = response as EncryptedResponse; // Generate the actual response if ((response.Result == ResponseResult.Success) && (encryptedResponse != null)) { var data = DecryptMessage(crypto, encryptedResponse.EncryptedData); response = XmlConversionUtil.ProcessResponse(data); } return response; }
public void SendMessageSendsAndReceivesAMessage() { var action = "DoSomething"; var request = new ServerRequest { ServerName = "TestServer" }; var url = "http://somewhere/"; var factory = new TestClientFactory((u, a, d) => { Assert.AreEqual(url + "server/TestServer/RawXmlMessage.aspx", u.AbsoluteUri); Assert.AreEqual("POST", a); Assert.AreEqual(action, d["action"]); Assert.AreEqual(request.ToString(), d["message"]); var theResponse = new Response { RequestIdentifier = request.Identifier }; return Encoding.UTF8.GetBytes(theResponse.ToString()); }); var connection = new HttpConnection(new Uri(url), factory); var response = connection.SendMessage(action, request); Assert.IsInstanceOf<Response>(response); Assert.AreEqual(request.Identifier, response.RequestIdentifier); }
public void SendMessageAsyncSendsMessage() { var action = "DoSomething"; var request = new ServerRequest { ServerName = "TestServer" }; var url = "http://somewhere/"; var factory = new TestClientFactory((u, a, d) => { Assert.AreEqual(url + "server/TestServer/RawXmlMessage.aspx", u.AbsoluteUri); Assert.AreEqual("POST", a); Assert.AreEqual(action, d["action"]); Assert.AreEqual(request.ToString(), d["message"]); var theResponse = new Response { RequestIdentifier = request.Identifier }; return Encoding.UTF8.GetBytes(theResponse.ToString()); }); var connection = new HttpConnection(new Uri(url), factory); var completed = false; connection.SendMessageCompleted += (o, e) => { completed = true; Assert.IsFalse(e.Cancelled); Assert.IsNull(e.Error); }; connection.SendMessageAsync(action, request); Assert.IsTrue(completed); }
public void ChannelCanBeSetAndRetrieved() { var channelInfo = new object(); var message = new ServerRequest(); message.ChannelInformation = channelInfo; Assert.AreSame(channelInfo, message.ChannelInformation); }
public void InitialiseNewRequestSetsTheDefaultValues() { DateTime now = DateTime.Now; ServerRequest request = new ServerRequest(); Assert.IsFalse(string.IsNullOrEmpty(request.Identifier), "Identifier was not set"); Assert.AreEqual(Environment.MachineName, request.SourceName, "Source name doesn't match the machine name"); Assert.IsTrue((now <= request.Timestamp), "Timestamp was not set"); }
public void InitialiseResponseFromRequestSetsTheDefaultValues() { DateTime now = DateTime.Now; ServerRequest request = new ServerRequest(); ListUsersResponse response = new ListUsersResponse(request); Assert.AreEqual(ResponseResult.Unknown, response.Result, "Result wasn't set to failure"); Assert.AreEqual(request.Identifier, response.RequestIdentifier, "RequestIdentifier wasn't set to the identifier of the request"); Assert.IsTrue((now <= response.Timestamp), "Timestamp was not set"); }
public void ConvertXmlToRequestConvertsRequest() { var request = new ServerRequest("123456-789"); request.ServerName = "theServer"; var xmlString = request.ToString(); var convertedRequest = XmlConversionUtil.ConvertXmlToRequest(xmlString); Assert.AreEqual("123456-789", convertedRequest.SessionToken); Assert.AreEqual("theServer", convertedRequest.ServerName); }
public void InitialiseRequestWithSessionSetsTheCorrectValues() { string sessionToken = "the session"; DateTime now = DateTime.Now; ServerRequest request = new ServerRequest(sessionToken); Assert.IsFalse(string.IsNullOrEmpty(request.Identifier), "Identifier was not set"); Assert.AreEqual(Environment.MachineName, request.SourceName, "Source name doesn't match the machine name"); Assert.AreEqual(sessionToken, request.SessionToken, "SessionToken doesn't match the input token"); Assert.IsTrue((now <= request.Timestamp), "Timestamp was not set"); }
public void ToStringSerialisesDefaultValues() { ServerRequest request = new ServerRequest(); string actual = request.ToString(); string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<serverMessage xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" source=\"{1}\" />", request.Identifier, request.SourceName, request.Timestamp); Assert.AreEqual(expected, actual); }
private void buildProject() { this._manager = new RemoteCruiseManagerFactory() .GetCruiseServerClient("tcp://localhost:21234/CruiseManager.rem"); this._project = new ProjectRequest("Edd", this.Name); this._manager.ForceBuild(this._project); this._request = new ServerRequest(this._project.SessionToken); // Write current status this.progress(String.Empty); IsRunning = false; Console.Write("\n\n"); }
public void SendMessageEncryptsMessage() { var innerConnection = new TestConnection(); var outerConnection = new EncryptingConnection(innerConnection); var request = new ServerRequest(); var expectedResponse = new Response(request); var actionName = "DoSomething"; string iv = null; string key = null; innerConnection.SendMessageAction = (a, r) => { Response sendResponse = null; if (a == "RetrievePublicKey") { sendResponse = this.GenerateKeyResponse(r); } else if (a == "InitialiseSecureConnection") { Assert.IsInstanceOf<LoginRequest>(r); sendResponse = this.GenerateConnectioResponse(r as LoginRequest, out iv, out key); } else if (a == "ProcessSecureRequest") { Assert.IsInstanceOf<EncryptedRequest>(r); var actualRequest = r as EncryptedRequest; Assert.AreEqual(actionName, actualRequest.Action); var crypto = new RijndaelManaged(); crypto.Key = Convert.FromBase64String(key); crypto.IV = Convert.FromBase64String(iv); var requestData = DecryptMessage(crypto, actualRequest.EncryptedData); Assert.AreEqual(request.ToString(), requestData); var encryptedResponse = new EncryptedResponse(); encryptedResponse.Result = ResponseResult.Success; encryptedResponse.EncryptedData = EncryptMessage(crypto, expectedResponse.ToString()); sendResponse = encryptedResponse; } else { Assert.Fail("Unknown action: " + a); } return sendResponse; }; var response = outerConnection.SendMessage(actionName, request); Assert.IsNotNull(response); Assert.AreEqual(expectedResponse.RequestIdentifier, response.RequestIdentifier); }
public void GetSetAllPropertiesWorks() { ServerRequest request = new ServerRequest(); request.Identifier = "new id"; Assert.AreEqual("new id", request.Identifier, "Identifier fails the get/set test"); request.ServerName = "new server"; Assert.AreEqual("new server", request.ServerName, "ServerName fails the get/set test"); request.SessionToken = "new session"; Assert.AreEqual("new session", request.SessionToken, "SessionToken fails the get/set test"); request.SourceName = "new source"; Assert.AreEqual("new source", request.SourceName, "SourceName fails the get/set test"); DateTime now = DateTime.Now; request.Timestamp = now; Assert.AreEqual(now, request.Timestamp, "Timestamp fails the get/set test"); }
/// <summary> /// Initialise a new instance of <see cref="StatusSnapshotResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public StatusSnapshotResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="ProjectStatusResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public HostPerformanceResponse(ServerRequest request) : base(request) { }
public void SendMessageAsync(string action, ServerRequest request, object userState) { throw new NotImplementedException(); }
/// <summary> /// Initialise a new instance of <see cref="LoginResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public LoginResponse(ServerRequest request) : base(request) { }
/// <summary> /// Terminate a secure communications connection. /// </summary> /// <param name="request"></param> /// <returns></returns> public Response TerminateSecureConnection(ServerRequest request) { // Remove the connection details if (connections.ContainsKey(request.SourceName)) { connections.Remove(request.SourceName); } // Generate a response var response = new Response(request); response.Result = ResponseResult.Success; return response; }
/// <summary> /// Initialise a new instance of <see cref="Response"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public Response(ServerRequest request) : this() { requestIdentifier = request.Identifier; }
/// <summary> /// Retrieve the amount of free disk space. /// </summary> /// <returns></returns> public virtual DataResponse GetFreeDiskSpace(ServerRequest request) { return cruiseServer.GetFreeDiskSpace(request); }
/// <summary> /// Processes an encrypted request. /// </summary> /// <param name="request"></param> /// <returns></returns> public Response ProcessSecureRequest(ServerRequest request) { // Validate the request var encryptedRequest = request as EncryptedRequest; if (encryptedRequest == null) throw new CruiseControlException("Incoming request is not an encrypted request"); if (!connections.ContainsKey(request.SourceName)) throw new CruiseControlException("No secure connection for the source"); var connection = connections[request.SourceName]; // Decrypt the data var crypto = new RijndaelManaged(); crypto.Key = connection.Key; crypto.IV = connection.IV; string data = DecryptMessage(crypto, encryptedRequest.EncryptedData); // Find the action and message type, extract the message and invoke the method var response = ExtractAndInvokeMessage(data, encryptedRequest.Action, new RemotingChannelSecurityInformation { IsEncrypted = true }); // Encrypt the response var encryptedResponse = new EncryptedResponse(request); encryptedResponse.EncryptedData = response.ToString(); encryptedResponse.EncryptedData = EncryptMessage(crypto, encryptedResponse.EncryptedData); encryptedResponse.Result = ResponseResult.Success; return encryptedResponse; }
/// <summary> /// Lists all the users who have been defined in the system. /// </summary> /// <param name="request"></param> /// <returns> /// A list of <see cref="ListUsersResponse"/> containing the details on all the users /// who have been defined. /// </returns> public ListUsersResponse ListUsers(ServerRequest request) { return cruiseServer.ListUsers(request); }
/// <summary> /// Initialise a new instance of <see cref="ListUsersResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ListUsersResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="FileTransferResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public FileTransferResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="EncryptedResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public EncryptedResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="ProjectStatusResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ProjectStatusResponse(ServerRequest request) : base(request) { }
/// <summary> /// Retrieves the security configuration. /// </summary> /// <param name="request"></param> public DataResponse GetSecurityConfiguration(ServerRequest request) { return cruiseServer.GetSecurityConfiguration(request); }
/// <summary> /// Initialise a new instance of <see cref="Response"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public Response(ServerRequest request) : this() { requestIdentifier = request.Identifier; }
/// <summary> /// Processes a message. /// </summary> /// <param name="action">The action to use.</param> /// <param name="message">The request message.</param> /// <returns>The response message.</returns> public virtual Response ProcessMessage(string action, ServerRequest message) { Response response = new Response(); try { // Find the action Type cruiseType = this.GetType(); MethodInfo actionMethod = cruiseType.GetMethod(action, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public); if (actionMethod == null) { throw new CruiseControlException( string.Format( CultureInfo.CurrentCulture, "Unable to locate action '{0}'", action)); } // Invoke the action message.ChannelInformation = new RemotingChannelSecurityInformation(); response = actionMethod.Invoke(this, new object[] { message }) as Response; } catch (Exception error) { response.Result = ResponseResult.Failure; if ((error is TargetInvocationException) && (error.InnerException != null)) { error = error.InnerException; } response.ErrorMessages.Add( new ErrorMessage("Unable to process: " + error.Message)); } return response; }
/// <summary> /// Initialise a new instance of <see cref="DataResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public DataResponse(ServerRequest request) : base(request) { }
/// <summary> /// Gets information about the last build status, current activity and project name. /// for all projects on a cruise server /// </summary> public virtual ProjectStatusResponse GetProjectStatus(ServerRequest request) { return cruiseServer.GetProjectStatus(request); }
/// <summary> /// Initialise a new instance of <see cref="SnapshotResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public SnapshotResponse(ServerRequest request) : base(request) { }
/// <summary> /// Retrieve the public key for the server. /// </summary> /// <param name="request"></param> /// <returns></returns> public DataResponse RetrievePublicKey(ServerRequest request) { var response = new DataResponse(request); // Either generate or retrieve the key for CruiseControl.NET Server var cp = new CspParameters(); cp.KeyContainerName = "CruiseControl.NET Server"; var provider = new RSACryptoServiceProvider(cp); // Return the public key response.Data = provider.ToXmlString(false); response.Result = ResponseResult.Success; return response; }
/// <summary> /// Generates a server request. /// </summary> /// <returns></returns> private ServerRequest GenerateServerRequest() { ServerRequest request = new ServerRequest(SessionToken); request.ServerName = TargetServer; request.DisplayName = this.DisplayName; return request; }
/// <summary> /// Lists the available servers that can be monitored. /// </summary> /// <param name="request">The request.</param> /// <returns> /// A list containing one server - local. /// </returns> /// <remarks> /// This message is not secured at all. /// </remarks> public DataListResponse ListServers(ServerRequest request) { return new DataListResponse { Data = new List<string>{ "local" } }; }
/// <summary> /// Initialise a new instance of <see cref="ReadAuditResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ReadAuditResponse(ServerRequest request) : base(request) { }
public Response SendMessage(string action, ServerRequest request) { Assert.AreEqual(this.action, action); Assert.AreEqual(this.message, request.GetType()); if (!string.IsNullOrEmpty(projectName) && (request is ProjectRequest)) { Assert.AreEqual(this.projectName, (request as ProjectRequest).ProjectName); } if (response == null) { Response result = new Response(request); result.Result = ResponseResult.Success; return result; } else { return response; } }
/// <summary> /// Initializes a new instance of the <see cref="ListBuildSummaryResponse"/> class. /// </summary> /// <param name="request">The request.</param> public ListBuildSummaryResponse(ServerRequest request) : base(request) { this.summaries = new List<BuildSummary>(); }
/// <summary> /// Initialise a new instance of <see cref="DiagnoseSecurityResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public DiagnoseSecurityResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="ListPackagesResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ListPackagesResponse(ServerRequest request) : base(request) { }
/// <summary> /// Processes a message. /// </summary> /// <param name="action">The action to use.</param> /// <param name="message">The request message.</param> /// <returns>The response message.</returns> public override Response ProcessMessage(string action, ServerRequest message) { Response response = connection.SendMessage(action, message); return response; }
/// <summary> /// Initialise a new instance of <see cref="BuildParametersResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public BuildParametersResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="ExternalLinksListResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ExternalLinksListResponse(ServerRequest request) : base(request) { }
/// <summary> /// Initialise a new instance of <see cref="ExternalLinksListResponse"/> from a request. /// </summary> /// <param name="request">The request to use.</param> public ExternalLinksListResponse(ServerRequest request) : base(request) { }