public void ToStringSerialisesAllValues()
 {
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse();
     response.ErrorMessages.Add(new ErrorMessage("Error 1"));
     response.ErrorMessages.Add(new ErrorMessage("Error 2"));
     response.RequestIdentifier = "request";
     response.Result = ResponseResult.Success;
     response.Timestamp = DateTime.Now;
     SecurityCheckDiagnostics diagnostics = new SecurityCheckDiagnostics();
     diagnostics.IsAllowed = true;
     diagnostics.Permission = "testing";
     diagnostics.Project = "test project";
     diagnostics.User = "******";
     response.Diagnostics.Add(diagnostics);
     string actual = response.ToString();
     string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<diagnoseSecurityResponse 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}\" result=\"{1}\">" +
         "<error>Error 1</error>" +
         "<error>Error 2</error>" +
         "<diagnosis permission=\"testing\" project=\"test project\" " +
         "user=\"test user\" allowed=\"true\" />" +
         "</diagnoseSecurityResponse>",
         response.RequestIdentifier,
         response.Result,
         response.Timestamp);
     Assert.AreEqual(expected, actual);
 }
 public void InitialiseNewResponseSetsTheDefaultValues()
 {
     DateTime now = DateTime.Now;
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse();
     Assert.AreEqual(ResponseResult.Unknown, response.Result, "Result wasn't set to failure");
     Assert.IsTrue((now <= response.Timestamp), "Timestamp was not set");
 }
 public void DiagnoseSecurityPermissions()
 {
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse();
     response.Result = ResponseResult.Success;
     CruiseServerClient client = new CruiseServerClient(
         new ServerStub("DiagnoseSecurityPermissions", typeof(DiagnoseSecurityRequest), null, response));
     client.DiagnoseSecurityPermissions("johnDoe");
 }
 public void InitialiseResponseFromRequestSetsTheDefaultValues()
 {
     DateTime now = DateTime.Now;
     ServerRequest request = new ServerRequest();
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse(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 ToStringSerialisesDefaultValues()
 {
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse();
     string actual = response.ToString();
     string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<diagnoseSecurityResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
         "timestamp=\"{1:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" result=\"{0}\" />",
         response.Result,
         response.Timestamp);
     Assert.AreEqual(expected, actual);
 }
 public void InitialiseResponseFromResponseSetsTheDefaultValues()
 {
     DateTime now = DateTime.Now;
     DiagnoseSecurityResponse response1 = new DiagnoseSecurityResponse();
     response1.Result = ResponseResult.Success;
     response1.RequestIdentifier = "original id";
     response1.Timestamp = DateTime.Now.AddMinutes(-1);
     DiagnoseSecurityResponse response2 = new DiagnoseSecurityResponse(response1);
     Assert.AreEqual(ResponseResult.Success, response2.Result, "Result wasn't set to failure");
     Assert.AreEqual("original id", response2.RequestIdentifier, "RequestIdentifier wasn't set to the identifier of the request");
     Assert.IsTrue((response1.Timestamp == response2.Timestamp), "Timestamp was not set");
 }
예제 #7
0
 /// <summary>
 /// Checks the security permissions for a user against one or more projects.
 /// </summary>
 /// <param name="request"></param>
 /// <returns>A set of diagnostics information.</returns>
 public DiagnoseSecurityResponse DiagnoseSecurityPermissions(DiagnoseSecurityRequest request)
 {
     List<SecurityCheckDiagnostics> diagnoses = new List<SecurityCheckDiagnostics>();
     DiagnoseSecurityResponse response = new DiagnoseSecurityResponse(RunServerRequest(request,
         SecurityPermission.ViewSecurity,
         SecurityEvent.DiagnoseSecurityPermissions,
         delegate
         {
             Array permissions = Enum.GetValues(typeof(SecurityPermission));
             foreach (string projectName in request.Projects)
             {
                 if (string.IsNullOrEmpty(projectName))
                 {
                     Log.Info(string.Format(CultureInfo.CurrentCulture, "DiagnoseServerPermission for user {0}", request.UserName));
                 }
                 else
                 {
                     Log.Info(string.Format(CultureInfo.CurrentCulture, "DiagnoseProjectPermission for user {0} project {1}", request.UserName, projectName));
                 }
                 foreach (SecurityPermission permission in permissions)
                 {
                     SecurityCheckDiagnostics diagnostics = new SecurityCheckDiagnostics();
                     diagnostics.Permission = permission.ToString();
                     diagnostics.Project = projectName;
                     diagnostics.User = request.UserName;
                     diagnostics.IsAllowed = DiagnosePermission(request.UserName, projectName, permission);
                     diagnoses.Add(diagnostics);
                 }
             }
         }));
     response.Diagnostics = diagnoses;
     return response;
 }