示例#1
0
        public void TestCase_S05_TC01_WhoAmI_Success()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            // Invoke "WhoAmI"sub-request with correct input parameters.
            WhoAmISubRequestType  whoAmISubRequest     = SharedTestSuiteHelper.CreateWhoAmISubRequest(SequenceNumberGenerator.GetCurrentToken());
            CellStorageResponse   cellStoreageResponse = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { whoAmISubRequest });
            WhoAmISubResponseType whoAmISubResponse    = SharedTestSuiteHelper.ExtractSubResponse <WhoAmISubResponseType>(cellStoreageResponse, 0, 0, this.Site);

            this.Site.Assert.IsNotNull(whoAmISubResponse, "The object 'whoAmISubResponse' should not be null.");
            this.Site.Assert.IsNotNull(whoAmISubResponse.ErrorCode, "The object 'whoAmISubResponse.ErrorCode' should not be null.");

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // If the error code in the sub-response equals "Success", then capture MS-FSSHTTP_R1327, MS-FSSHTTP_R1434.
                Site.CaptureRequirementIfAreEqual <ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(whoAmISubResponse.ErrorCode, this.Site),
                    "MS-FSSHTTP",
                    1327,
                    @"[In WhoAmI Subrequest] The protocol server returns results based on the following conditions: Otherwise[except: the processing of the WhoAmI subrequest by the protocol server failed to get the client-specific user information or encountered an unknown exception], the protocol server sets the error code value to ""Success"" to indicate success in processing the WhoAmI subrequest.");

                // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R1434
                Site.CaptureRequirementIfAreEqual <ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(whoAmISubResponse.ErrorCode, this.Site),
                    "MS-FSSHTTP",
                    1434,
                    @"[In WhoAmISubResponseType] The protocol server sets the value of the ErrorCode attribute to ""Success"" if the protocol server succeeds in processing the WhoAmI subrequest.");

                // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R7681
                Site.CaptureRequirementIfIsNotNull(
                    whoAmISubResponse.SubResponseData,
                    "MS-FSSHTTP",
                    7681,
                    @"[In WhoAmISubResponseType] As part of processing the WhoAmI subrequest, the SubResponseData element MUST be sent as part of the SubResponse element in a cell storage service response message if the following condition is true:
                         The ErrorCode attribute that is part of the SubResponse element is set to a value of ""Success"".");

                bool isVerifyR904 = whoAmISubResponse.SubResponseData.UserName.IndexOf(this.UserName01, System.StringComparison.OrdinalIgnoreCase) >= 0;
                this.Site.Log.Add(
                    LogEntryKind.Debug,
                    "For MS-FSSHTTP_R904, expect the UserName attribute contains the value {0}, the actual UserName attribute value is {1}",
                    this.UserName01,
                    whoAmISubResponse.SubResponseData.UserName);

                // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R904
                Site.CaptureRequirementIfIsTrue(
                    isVerifyR904,
                    "MS-FSSHTTP",
                    904,
                    @"[In WhoAmISubResponseDataOptionalAttributes] UserName: [A UserNameType] that specifies the user name for the protocol client.");
            }
            else
            {
                Site.Assert.AreEqual <ErrorCodeType>(
                    ErrorCodeType.Success,
                    SharedTestSuiteHelper.ConvertToErrorCodeType(whoAmISubResponse.ErrorCode, this.Site),
                    @"[In WhoAmI Subrequest] The protocol server returns results based on the following conditions: Otherwise[except: the processing of the WhoAmI subrequest by the protocol server failed to get the client-specific user information or encountered an unknown exception], the protocol server sets the error code value to ""Success"" to indicate success in processing the WhoAmI subrequest.");

                Site.Assert.IsNotNull(
                    whoAmISubResponse.SubResponseData,
                    @"[In WhoAmISubResponseType] As part of processing the WhoAmI subrequest, the SubResponseData element MUST be sent as part of the SubResponse element in a cell storage service response message if the following condition is true:
                        The ErrorCode attribute that is part of the SubResponse element is set to a value of ""Success"".");

                bool isVerifyR904 = whoAmISubResponse.SubResponseData.UserName.IndexOf(this.UserName01, System.StringComparison.OrdinalIgnoreCase) >= 0;
                Site.Assert.IsTrue(
                    isVerifyR904,
                    @"[In WhoAmISubResponseDataOptionalAttributes] UserName: [A UserNameType] that specifies the user name for the client.");
            }
        }
        /// <summary>
        /// Capture requirements related with WhoAmI Sub-request.
        /// </summary>
        /// <param name="whoamiSubResponse">Containing the WhoAmISubResponse information</param>
        /// <param name="site">Instance of ITestSite</param>
        public static void ValidateWhoAmISubResponse(WhoAmISubResponseType whoamiSubResponse, ITestSite site)
        {
            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R765
            site.CaptureRequirement(
                "MS-FSSHTTP",
                765,
                @"[In WhoAmISubResponseType][WhoAmISubResponseType schema is:]
                     <xs:complexType name=""WhoAmISubResponseType"">
                       <xs:complexContent>
                         <xs:extension base=""tns:SubResponseType"">
                           <xs:sequence minOccurs=""0"" maxOccurs=""1"">
                              <xs:element name=""SubResponseData"" type=""tns:WhoAmISubResponseDataType""/>
                           </xs:sequence>
                         </xs:extension>
                       </xs:complexContent>
                     </xs:complexType>");

            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R1316
            site.CaptureRequirementIfAreEqual <Type>(
                typeof(WhoAmISubResponseType),
                whoamiSubResponse.GetType(),
                "MS-FSSHTTP",
                1316,
                @"[In WhoAmI Subrequest][The protocol client sends a WhoAmI SubRequest message, which is of type WhoAmISubRequestType] The protocol server responds with a WhoAmI SubResponse message, which is of type WhoAmISubResponseType as specified in section 2.3.1.22.");

            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R4692
            site.CaptureRequirementIfAreEqual <Type>(
                typeof(WhoAmISubResponseType),
                whoamiSubResponse.GetType(),
                "MS-FSSHTTP",
                4692,
                @"[In SubResponseElementGenericType] Depending on the Type attribute specified in the SubRequest element, the SubResponseElementGenericType MUST take one of the forms: WhoAmISubResponseType.");

            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R5746
            site.CaptureRequirementIfAreEqual <Type>(
                typeof(WhoAmISubResponseType),
                whoamiSubResponse.GetType(),
                "MS-FSSHTTP",
                5746,
                @"[In SubResponseType] The SubResponseElementGenericType takes one of the following forms: WhoAmISubResponseType.");

            ErrorCodeType errorCode;

            site.Assert.IsTrue(Enum.TryParse <ErrorCodeType>(whoamiSubResponse.ErrorCode, true, out errorCode), "Fail to convert the error code string {0} to the Enum type ErrorCodeType", whoamiSubResponse.ErrorCode);
            if (errorCode == ErrorCodeType.Success)
            {
                // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R268
                site.CaptureRequirementIfIsNotNull(
                    whoamiSubResponse.SubResponseData,
                    "MS-FSSHTTP",
                    268,
                    @"[In SubResponseElementGenericType][The SubResponseData element MUST be sent as part of the SubResponse element in a cell storage service response message if the ErrorCode attribute that is part of the SubResponse element is set to a value of ""Success"" and one of the following conditions is true:] The Type attribute that is specified in the SubRequest element is set to a value of ""WhoAmI"".");
            }

            // Verify requirements related with its base type: SubResponseType
            ValidateSubResponseType(whoamiSubResponse as SubResponseType, site);

            // Verify requirements related with SubResponseDataType
            if (whoamiSubResponse.SubResponseData != null)
            {
                ValidateWhoAmISubResponseDataType(whoamiSubResponse.SubResponseData, site);
            }
        }
        public void MSFSSHTTP_FSSHTTPB_S05_TC01_WhoAmI_ClaimsBased()
        {
            // Initialize the service
            this.InitializeContext(this.DefaultFileUrl, this.UserName01, this.Password01, this.Domain);

            if (Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 3086, this.Site))
            {
                // Enable the windows-based authentication
                bool isSwitchedSuccessfully = SutPowerShellAdapter.SwitchClaimsAuthentication(false);
                this.Site.Assert.IsTrue(isSwitchedSuccessfully, "The windows-based authentication should be enabled successfully.");
                this.StatusManager.RecordDisableClaimsBasedAuthentication();
            }

            int waitTime   = Common.GetConfigurationPropertyValue <int>("WaitTime", this.Site);
            int retryCount = Common.GetConfigurationPropertyValue <int>("RetryCount", this.Site);

            WhoAmISubRequestType  subRequest  = null;
            CellStorageResponse   response    = null;
            WhoAmISubResponseType subResponse = null;

            while (retryCount > 0)
            {
                // Create a WhoAmI subRequest with all valid parameters
                subRequest  = SharedTestSuiteHelper.CreateWhoAmISubRequest(SequenceNumberGenerator.GetCurrentToken());
                response    = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { subRequest });
                subResponse = SharedTestSuiteHelper.ExtractSubResponse <WhoAmISubResponseType>(response, 0, 0, this.Site);
                Site.Assert.AreEqual <ErrorCodeType>(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(subResponse.ErrorCode, this.Site), "WhoAmI subRequest should be succeed.");

                Regex regex = new Regex(@"^[a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*");
                if (regex.IsMatch(subResponse.SubResponseData.UserLogin))
                {
                    break;
                }

                retryCount--;
                if (retryCount == 0)
                {
                    Site.Assert.Fail("Additional authentication prefix should not exist in UserLogin if claim-based authentication mode is enabled");
                }

                System.Threading.Thread.Sleep(waitTime);
            }

            if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
            {
                // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R3087
                Regex regex           = new Regex(@"^[a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*");
                bool  isVerifiedR3087 = regex.IsMatch(subResponse.SubResponseData.UserLogin);

                Site.Log.Add(
                    LogEntryKind.Debug,
                    @"The UserLoginType will match pattern ^[a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*, actually its value is {0}",
                    subResponse.SubResponseData.UserLogin);

                this.Site.CaptureRequirementIfIsTrue(
                    isVerifiedR3087,
                    "MS-FSSHTTP",
                    3087,
                    @"[In Appendix B: Product Behavior] If claims-based authentication mode isn't enabled, the implementation does return the UserLogin attribute which apply the following schema:
                              <xs:simpleType name=""UserLoginType"">
                                 <xs:restriction base=""xs:string"">
                                    <xs:pattern value=""^[a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*""/>
                                 </xs:restriction>
                              </xs:simpleType>");
            }

            // Verify MS-FSSHTTP requirement: MS-FSSHTTP_R3086
            if (Common.IsRequirementEnabled("MS-FSSHTTP-FSSHTTPB", 3086, this.Site))
            {
                // Enable the claims-based authentication
                bool isSwitchedSuccessfully = SutPowerShellAdapter.SwitchClaimsAuthentication(true);
                this.Site.Assert.IsTrue(isSwitchedSuccessfully, "The claims-based authentication should be enabled successfully.");

                waitTime   = Common.GetConfigurationPropertyValue <int>("WaitTime", this.Site);
                retryCount = Common.GetConfigurationPropertyValue <int>("RetryCount", this.Site);

                while (retryCount > 0)
                {
                    // Send the WhoAmI subRequest to the protocol server
                    response    = Adapter.CellStorageRequest(this.DefaultFileUrl, new SubRequestType[] { subRequest });
                    subResponse = SharedTestSuiteHelper.ExtractSubResponse <WhoAmISubResponseType>(response, 0, 0, this.Site);
                    Site.Assert.AreEqual <ErrorCodeType>(ErrorCodeType.Success, SharedTestSuiteHelper.ConvertToErrorCodeType(subResponse.ErrorCode, this.Site), "WhoAmI subRequest should be succeed.");

                    Regex r2    = new Regex(@"([a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*)$");
                    Match match = r2.Match(subResponse.SubResponseData.UserLogin);
                    if (r2.IsMatch(subResponse.SubResponseData.UserLogin) && match.Success && match.Index > 0)
                    {
                        break;
                    }

                    retryCount--;
                    if (retryCount == 0)
                    {
                        Site.Assert.Fail("Additional authentication prefix should not exist in UserLogin if claim-based authentication mode is enabled");
                    }

                    System.Threading.Thread.Sleep(waitTime);
                }

                Regex regex2 = new Regex(@"([a-zA-Z]([a-zA-Z0-9\-_])*\\[a-zA-Z]([a-zA-Z0-9])*)$");
                Match m      = regex2.Match(subResponse.SubResponseData.UserLogin);

                if (SharedContext.Current.IsMsFsshttpRequirementsCaptured)
                {
                    Site.Log.Add(
                        LogEntryKind.Debug,
                        string.Format("The UserLogin should have prefix when the authentication is claims based, actual the prefix {0}", m.Index > 0 ? "exists" : "does not exist"));

                    this.Site.CaptureRequirementIfIsTrue(
                        m.Success && m.Index > 0,
                        "MS-FSSHTTP",
                        3086,
                        @"[In Appendix B: Product Behavior] Implementation does add an additional authentication prefix for the UserLogin attribute. (Microsoft SharePoint Foundation 2016/Microsoft SharePoint Server 2016 and above follow this behavior.)");
                }
                else
                {
                    Site.Log.Add(
                        LogEntryKind.Debug,
                        string.Format("The UserLogin should have prefix when the authentication is claims based, actual the prefix {0}", m.Index > 0 ? "exists" : "does not exist"));

                    this.Site.Assert.IsTrue(
                        m.Success && m.Index > 0,
                        @"[In Appendix B: Product Behavior] Implementation does add an additional authentication prefix for the UserLogin attribute. <28> Section 2.3.2.6: There is an additional authentication prefix if claims-based authentication mode is enabled. (Microsoft SharePoint Foundation 2016/Microsoft SharePoint Server 2016 and above follow this behavior.)");
                }
            }
        }