/// <summary> /// Get PolicyKey from Provision Response /// </summary> /// <param name="response">Provision Response</param> /// <returns>Policy Key, if the response doesn't contain the PolicyKey, returns null</returns> private static string GetPolicyKeyFromResponse(ProvisionResponse response) { if (null != response.ResponseData.Policies) { Response.ProvisionPoliciesPolicy policyInResponse = response.ResponseData.Policies.Policy; if (policyInResponse != null) { return(policyInResponse.PolicyKey); } } return(null); }
public void MSASCMD_S21_TC14_CommonStatusCode_145() { Site.Assume.AreNotEqual <string>("12.1", Common.GetConfigurationPropertyValue("ActiveSyncProtocolVersion", this.Site), "This test case is not supported when the MS-ASProtocolVersion header is set to 12.1.. MS-ASProtocolVersion header value is determined using Common PTFConfig property named ActiveSyncProtocolVersion."); #region User calls Provision command to download policies from server // Calls Provision command to download policies ProvisionRequest provisionRequest = TestSuiteBase.GenerateDefaultProvisionRequest(); ProvisionResponse provisionResponse = this.CMDAdapter.Provision(provisionRequest); // Get policyKey, policyType and statusCode from server response string policyKey = null; if (null != provisionResponse.ResponseData.Policies) { Response.ProvisionPoliciesPolicy policyInResponse = provisionResponse.ResponseData.Policies.Policy; if (policyInResponse != null) { policyKey = policyInResponse.PolicyKey; } } string policyType = provisionResponse.ResponseData.Policies.Policy.PolicyType; Response.ProvisionPoliciesPolicyData data = provisionResponse.ResponseData.Policies.Policy.Data; byte statusCode = provisionResponse.ResponseData.Status; #endregion #region User calls Provision command to acknowledge policies. // Set acknowledgeStatus value to 1, means accept the policy. ProvisionRequest provisionAcknowledgeRequest = TestSuiteBase.GenerateDefaultProvisionRequest(); provisionAcknowledgeRequest.RequestData.Policies.Policy.PolicyKey = policyKey; provisionAcknowledgeRequest.RequestData.Policies.Policy.Status = "4"; // Calls Provision command ProvisionResponse provisionAcknowledgeResponse = this.CMDAdapter.Provision(provisionAcknowledgeRequest); statusCode = provisionAcknowledgeResponse.ResponseData.Status; this.Site.CaptureRequirementIfAreEqual <byte>( 145, statusCode, 4917, @"[In Common Status Codes] When the protocol version is 14.0, 14.1 or 16.0, [The meaning of the status value 145 is] The device claimed to be externally managed, but the server doesn't allow externally managed devices to sync."); #endregion }
/// <summary> /// Get policy key from Provision string response. /// </summary> /// <param name="provisionResponseString">The SendStringResponse instance of Provision command.</param> /// <returns>The policy key of the policy.</returns> public static string GetPolicyKeyFromSendString(ActiveSyncResponseBase <object> provisionResponseString) { ProvisionResponse provisionResponse = new ProvisionResponse { ResponseDataXML = provisionResponseString.ResponseDataXML }; if (!string.IsNullOrEmpty(provisionResponse.ResponseDataXML)) { provisionResponse.DeserializeResponseData(); if (provisionResponse.ResponseData.Policies != null) { Response.ProvisionPoliciesPolicy policyInResponse = provisionResponse.ResponseData.Policies.Policy; if (policyInResponse != null) { return(policyInResponse.PolicyKey); } } } return(string.Empty); }
public void MSASPROV_S01_TC01_AcknowledgeSecurityPolicySettings() { #region Switch current user to the user who has custom policy settings. // Switch to the user who has been configured with custom policy. this.SwitchUser(this.User2Information, false); #endregion #region Download the policy settings. // Download the policy settings. ProvisionResponse provisionResponse = this.CallProvisionCommand(string.Empty, "MS-EAS-Provisioning-WBXML", "1"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R394"); // Verify MS-ASPROV requirement: MS-ASPROV_R394 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, provisionResponse.ResponseData.Status, 394, @"[In Status (Provision)] Value 1 means Success."); string temporaryPolicyKey = provisionResponse.ResponseData.Policies.Policy.PolicyKey; // Get the policy element from the Provision response. Response.ProvisionPoliciesPolicy policy = provisionResponse.ResponseData.Policies.Policy; // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R310"); // Verify MS-ASPROV requirement: MS-ASPROV_R310 // The PolicyType, PolicyKey, Status and Data elements are not null, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( policy.Data != null && policy.PolicyKey != null && policy.PolicyType != null && policy.Status != 0, 310, @"[In Policy] In the initial Provision command response, the Policy element has only the following child elements: PolicyType (section 2.2.2.42) (required) PolicyKey (section 2.2.2.41) (required) Status (section 2.2.2.53) (required) Data (section 2.2.2.23) ( required)."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R417"); // Verify MS-ASPROV requirement: MS-ASPROV_R417 // The PolicyType, PolicyKey, Status and Data elements are not null, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( policy.Data != null && policy.PolicyKey != null && policy.PolicyType != null && policy.Status != 0, 417, @"[In Abstract Data Model] In order 1, the server response contains the policy type, policy key, data, and status code."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R378"); // Verify MS-ASPROV requirement: MS-ASPROV_R378 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, policy.Status, 378, @"[In Status (Policy)] Value 1 means Success."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R209"); // Verify MS-ASPROV requirement: MS-ASPROV_R209 // The Data element is not null, so this requirement can be captured. Site.CaptureRequirementIfIsNotNull( policy.Data, 209, @"[In Data (container Data Type)] It [Data element] is a required child element of the Policy element (section 2.2.2.40) in responses to initial Provision command requests, as specified in section 3.2.5.1.1."); // Because the user is not allowe to download attachment. // So if AttachmentsEnabled element is false then R206 will be verified. this.Site.CaptureRequirementIfAreEqual <bool>( false, policy.Data.EASProvisionDoc.AttachmentsEnabled, 206, @"[In AttachmentsEnabled] Value 0 means Attachments are not allowed to be downloaded."); // Because if the Data element is a container Data type, then the Data element should contain the EASProvisionDoc element. // So if the Data element contain the EASProvisionDoc element and the PolicyType element is set to "MS-EAS-Provisioning-WBXML", then R888 will be verified. this.Site.CaptureRequirementIfIsTrue( policy.Data.EASProvisionDoc != null && policy.PolicyType == "MS-EAS-Provisioning-WBXML", 888, @"[In Data (container Data Type)] This element [Data (container Data Type)] requires that the PolicyType element (section 2.2.2.42) is set to ""MS-EAS-Provisioning-WBXML""."); this.Site.CaptureRequirementIfIsTrue( !string.IsNullOrEmpty(policy.PolicyKey), 486, @"[In Provision Command] The server generates, stores, and sends the policy key when it responds to a Provision command request for policy settings."); #endregion #region Acknowledge the policy settings. // Acknowledge the policy settings. provisionResponse = this.CallProvisionCommand(temporaryPolicyKey, "MS-EAS-Provisioning-WBXML", "1"); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R678"); // Verify MS-ASPROV requirement: MS-ASPROV_R678 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, provisionResponse.ResponseData.Status, 678, @"[In Provision Command Errors] [The meaning of status value] 1 [is] Success."); bool isR441Verified = provisionResponse.ResponseData.Policies != null && provisionResponse.ResponseData.Status == 1; // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R441"); // Verify MS-ASPROV requirement: MS-ASPROV_R441 // The Policies element is not null and the value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( isR441Verified, 441, @"[In Provision Command Errors] [The cause of status value 1 is] The Policies element contains information about security policies."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R650"); // Verify MS-ASPROV requirement: MS-ASPROV_R650 // The acknowledgement Provision succeeds and PolicyKey element is not null, so this requirement can be captured. Site.CaptureRequirementIfIsNotNull( temporaryPolicyKey, 650, @"[In Responding to an Initial Request] The value of the PolicyKey element (section 2.2.2.41) is a temporary policy key that will be valid only for an acknowledgment request to acknowledge the policy settings contained in the Data element."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R657"); // Verify MS-ASPROV requirement: MS-ASPROV_R657 // The command executed successfully using the temporary PolicyKey, so this requirement can be captured. Site.CaptureRequirement( 657, @"[In Responding to a Security Policy Settings Acknowledgment] The server MUST ensure that the current policy key sent by the client in a security policy settings acknowledgment matches the temporary policy key issued by the server in the response to the initial request from this client."); // Get the policy element from the Provision response. policy = provisionResponse.ResponseData.Policies.Policy; // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R605"); // Verify MS-ASPROV requirement: MS-ASPROV_R605 // The PolicyType, PolicyKey and Status elements are not null, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( policy.PolicyKey != null && policy.PolicyType != null && policy.Status != 0, 605, @"[In Policy] In the acknowledgment Provision command response, the Policy element has the following child elements: PolicyType (section 2.2.2.42) (required) PolicyKey (section 2.2.2.41) (required) Status (section 2.2.2.53) (required)."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R419"); // Verify MS-ASPROV requirement: MS-ASPROV_R419 // The PolicyType, PolicyKey and Status elements are not null, so this requirement can be captured. Site.CaptureRequirementIfIsTrue( policy.PolicyKey != null && policy.PolicyType != null && policy.Status != 0, 419, @"[In Abstract Data Model] In order 2, the server response contains the policy type, policy key, and status code to indicate that the server recorded the client's acknowledgement."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R688"); // Verify MS-ASPROV requirement: MS-ASPROV_R688 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, policy.Status, 688, @"[In Provision Command Errors] [The meaning of status value] 1 [is] Success."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R466"); // Verify MS-ASPROV requirement: MS-ASPROV_R466 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, policy.Status, 466, @"[In Provision Command Errors] [The cause of status value 1 is] The requested policy data is included in the response."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R703"); // Verify MS-ASPROV requirement: MS-ASPROV_R703 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, policy.Status, 703, @"[In Provision Command Errors] [When the scope is] Policy, [the meaning of status value] 1 [is] Success."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R495"); // Verify MS-ASPROV requirement: MS-ASPROV_R495 // The value of Status is 1, so this requirement can be captured. Site.CaptureRequirementIfAreEqual <byte>( 1, policy.Status, 495, @"[In Provision Command Errors] [When the scope is Policy], [the cause of status value 1 is] The requested policy data is included in the response."); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R601"); // Verify MS-ASPROV requirement: MS-ASPROV_R601 // The Data element is null, so this requirement can be captured. Site.CaptureRequirementIfIsNull( policy.Data, 601, @"[In Data (container Data Type)] It [Data element] is not present in responses to acknowledgment requests, as specified in section 3.2.5.1.2."); #endregion #region Apply the final policy key got from acknowledgement Provision response. // Get the final policy key from the Provision command response. string finalPolicyKey = provisionResponse.ResponseData.Policies.Policy.PolicyKey; // Apply the final policy key for the subsequence commands. this.PROVAdapter.ApplyPolicyKey(finalPolicyKey); #endregion #region Call FolderSync command with the final policy key. FolderSyncRequest folderSyncRequest = Common.CreateFolderSyncRequest("0"); FolderSyncResponse folderSynReponse = this.PROVAdapter.FolderSync(folderSyncRequest); Site.Assert.AreEqual(folderSynReponse.StatusCode, HttpStatusCode.OK, "Server should return a HTTP expected status code [{0}] after apply Policy Key, actual is [{1}]", HttpStatusCode.OK, folderSynReponse.StatusCode); // Add the debug information Site.Log.Add(LogEntryKind.Debug, "Verify MS-ASPROV_R662"); // Verify MS-ASPROV requirement: MS-ASPROV_R662 // The FolderSync command executed successfully after the final policy key is applied, so this requirement can be captured. Site.CaptureRequirementIfIsNotNull( finalPolicyKey, 662, @"[In Responding to a Security Policy Settings Acknowledgment] The value of the PolicyKey element (section 2.2.2.41) is a permanent policy key that is valid for subsequent command requests from the client."); #endregion }