Exemple #1
0
        public static void OpenRequest(
            ClientGuidType clientGuidType,
            PathNameType pathNameType,
            CreateType createType,
            ShareType shareType,
            AppInstanceIdType appInstanceIdType)
        {
            Condition.IsTrue(State == ModelState.Connected);
            Condition.IsNotNull(Open);

            // Isolate below params to limite the expanded test cases.
            Combination.Isolated(clientGuidType == ClientGuidType.SameClientGuid);
            Combination.Isolated(pathNameType == PathNameType.DifferentPathName);
            Combination.Isolated(shareType == ShareType.DifferentShareDifferentLocal);
            Combination.Isolated(shareType == ShareType.DifferentShareSameLocal);
            Combination.Isolated(appInstanceIdType == AppInstanceIdType.InvalidAppInstanceId);
            Combination.Isolated(appInstanceIdType == AppInstanceIdType.NoAppInstanceId);

            // "AppInstanceId is zero" is only applicable for the first Create Request.
            // For the second Create Request, only valid/notvalid/none make sense.
            Condition.IsFalse(appInstanceIdType == AppInstanceIdType.AppInstanceIdIsZero);

            // CreateDurableThenDisconnect is only applicable for the first Create Request.
            Condition.IsFalse(createType == CreateType.CreateDurableThenDisconnect);

            // If the client doesn't disconnect from the server after sending the first Create Request,
            // then the second Create Request does not need to contain reconnect context.
            // And vice versa.
            Condition.IfThen(Open.CreateTypeWhenPrepare != CreateType.CreateDurableThenDisconnect, createType != CreateType.ReconnectDurable);
            Condition.IfThen(Open.CreateTypeWhenPrepare == CreateType.CreateDurableThenDisconnect, createType == CreateType.ReconnectDurable);

            if (createType == CreateType.ReconnectDurable)
            {
                ModelHelper.Log(LogType.Requirement,
                                "3.3.5.9.13: If the create request also includes the SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context, " +
                                "the server MUST process the SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context as specified in section 3.3.5.9.12, " +
                                "and this section MUST be skipped.");
                ModelHelper.Log(LogType.TestInfo, "SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context is included.");
                return;
            }

            if (!ModelUtility.IsSmb3xFamily(MaxSmbVersionSupported))
            {
                ModelHelper.Log(LogType.Requirement,
                                "2.2.13.2.13: The SMB2_CREATE_APP_INSTANCE_ID context is valid only for the SMB 3.x dialect family.");
                ModelHelper.Log(LogType.TestInfo, "The dialect version of the server is {0}.", MaxSmbVersionSupported);
                return;
            }

            if (appInstanceIdType == AppInstanceIdType.ValidAppInstanceId && Open.AppInstanceId != AppInstanceIdType.NoAppInstanceId &&
                pathNameType == PathNameType.SamePathName &&
                shareType == ShareType.SameShare &&
                clientGuidType == ClientGuidType.DifferentClientGuid)
            {
                ModelHelper.Log(LogType.Requirement,
                                "3.3.5.9.13: The server MUST attempt to locate an Open in GlobalOpenTable where:");
                ModelHelper.Log(LogType.Requirement,
                                "\tAppInstanceId in the request is equal to Open.AppInstanceId.");
                ModelHelper.Log(LogType.Requirement,
                                "\tTarget path name is equal to Open.PathName.");
                ModelHelper.Log(LogType.Requirement,
                                "\tOpen.TreeConnect.Share is equal to TreeConnect.Share.");
                ModelHelper.Log(LogType.Requirement,
                                "\tOpen.Session.Connection.ClientGuid is not equal to the current Connection.ClientGuid.");
                ModelHelper.Log(LogType.TestInfo, "All the above conditions are met.");

                ModelHelper.Log(LogType.Requirement,
                                "If an Open is found, the server MUST calculate the maximal access that the user, " +
                                "identified by Session.SecurityContext, has on the file being opened<277>. " +
                                "If the maximal access includes GENERIC_READ access, the server MUST close the open as specified in 3.3.4.17.");
                // The user used in this model is administrator, so maximal access always includes GENERIC_READ access.
                ModelHelper.Log(LogType.TestInfo, "The maximal access includes GENERIC_READ access. So open is closed.");

                // close open
                Open = null;
            }
            else
            {
                ModelHelper.Log(LogType.TestInfo, "appInstanceIdType is {0}.", appInstanceIdType.ToString());
                ModelHelper.Log(LogType.TestInfo, "pathNameType is {0}.", pathNameType.ToString());
                ModelHelper.Log(LogType.TestInfo, "shareType is {0}.", shareType.ToString());
                ModelHelper.Log(LogType.TestInfo, "clientGuidType is {0}.", clientGuidType.ToString());
                ModelHelper.Log(LogType.TestInfo, "All the above conditions do not match the requirement, so open will not be closed.");

                ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields);
            }
        }
        public void OpenRequest(
            ClientGuidType clientGuidType,
            PathNameType pathNameType,
            CreateType createType,
            ShareType shareType,
            AppInstanceIdType appInstanceIdType)
        {
            Smb2FunctionalClient testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            uint   treeId;
            string share;

            switch (shareType)
            {
            case ShareType.SameShare:
                share = testConfig.BasicFileShare;
                break;

            case ShareType.DifferentShareSameLocal:
                share = testConfig.SameWithSMBBasic;
                break;

            case ShareType.DifferentShareDifferentLocal:
                share = testConfig.DifferentFromSMBBasic;
                break;

            default:
                throw new ArgumentException("shareType");
            }

            ConnectToShare(
                clientDialect,
                testClient,
                clientGuidType == ClientGuidType.SameClientGuid ? this.connection_ClientGuid : Guid.NewGuid(),
                share,
                out treeId);

            FILEID fileId;

            Smb2CreateContextResponse[] createContextResponse;
            uint   status;
            string fileNameInOpen;

            if (pathNameType == PathNameType.SamePathName)
            {
                fileNameInOpen = fileName;
            }
            else
            {
                fileNameInOpen = fileName + different;
                AddTestFileName(Smb2Utility.GetUncPath(testConfig.SutComputerName, share), fileNameInOpen);
            }

            status = testClient.Create(
                treeId,
                fileNameInOpen,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                createContexts: CreateContexts(appInstanceIdType, createType, false),
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) => { });

            testClient.Disconnect();
            testClient = null;

            // Check if the Open is closed.
            // If status is success, and fileId is the same with the previous one, then the Open is not closed.
            // Otherwise, use some other way to check if the Open is closed.
            bool ifClosed;

            if (status == Smb2Status.STATUS_SUCCESS && fileId.Persistent == this.open_FileId.Persistent)
            {
                ifClosed = false;
            }
            else
            {
                ifClosed = CheckIfOpenClosed(clientDialect, createType);
            }
            this.OpenResponse(ifClosed ? OpenStatus.OpenClosed : OpenStatus.OpenNotClosed);
        }
        /// <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();
        }
        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;
            }
        }
        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;
            }
        }
        public static void OpenRequest(
            ClientGuidType clientGuidType,
            PathNameType pathNameType,
            CreateType createType,
            ShareType shareType,
            AppInstanceIdType appInstanceIdType)
        {
            Condition.IsTrue(State == ModelState.Connected);
            Condition.IsNotNull(Open);

            // Isolate below params to limite the expanded test cases.
            Combination.Isolated(clientGuidType == ClientGuidType.SameClientGuid);
            Combination.Isolated(pathNameType == PathNameType.DifferentPathName);
            Combination.Isolated(shareType == ShareType.DifferentShareDifferentLocal);
            Combination.Isolated(shareType == ShareType.DifferentShareSameLocal);
            Combination.Isolated(appInstanceIdType == AppInstanceIdType.InvalidAppInstanceId);
            Combination.Isolated(appInstanceIdType == AppInstanceIdType.NoAppInstanceId);

            // "AppInstanceId is zero" is only applicable for the first Create Request.
            // For the second Create Request, only valid/notvalid/none make sense.
            Condition.IsFalse(appInstanceIdType == AppInstanceIdType.AppInstanceIdIsZero);

            // CreateDurableThenDisconnect is only applicable for the first Create Request.
            Condition.IsFalse(createType == CreateType.CreateDurableThenDisconnect);

            // If the client doesn't disconnect from the server after sending the first Create Request,
            // then the second Create Request does not need to contain reconnect context.
            // And vice versa.
            Condition.IfThen(Open.CreateTypeWhenPrepare != CreateType.CreateDurableThenDisconnect, createType != CreateType.ReconnectDurable);
            Condition.IfThen(Open.CreateTypeWhenPrepare == CreateType.CreateDurableThenDisconnect, createType == CreateType.ReconnectDurable);

            if (createType == CreateType.ReconnectDurable)
            {
                ModelHelper.Log(LogType.Requirement,
                    "3.3.5.9.13: If the create request also includes the SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context, " +
                    "the server MUST process the SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context as specified in section 3.3.5.9.12, " +
                    "and this section MUST be skipped.");
                ModelHelper.Log(LogType.TestInfo, "SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 create context is included.");
                return;
            }

            if (!ModelUtility.IsSmb3xFamily(MaxSmbVersionSupported))
            {
                ModelHelper.Log(LogType.Requirement,
                    "2.2.13.2.13: The SMB2_CREATE_APP_INSTANCE_ID context is valid only for the SMB 3.x dialect family.");
                ModelHelper.Log(LogType.TestInfo, "The dialect version of the server is {0}.", MaxSmbVersionSupported);
                return;
            }

            if (appInstanceIdType == AppInstanceIdType.ValidAppInstanceId && Open.AppInstanceId != AppInstanceIdType.NoAppInstanceId
                && pathNameType == PathNameType.SamePathName
                && shareType == ShareType.SameShare
                && clientGuidType == ClientGuidType.DifferentClientGuid)
            {
                ModelHelper.Log(LogType.Requirement,
                    "3.3.5.9.13: The server MUST attempt to locate an Open in GlobalOpenTable where:");
                ModelHelper.Log(LogType.Requirement,
                    "\tAppInstanceId in the request is equal to Open.AppInstanceId.");
                ModelHelper.Log(LogType.Requirement,
                    "\tTarget path name is equal to Open.PathName.");
                ModelHelper.Log(LogType.Requirement,
                    "\tOpen.TreeConnect.Share is equal to TreeConnect.Share.");
                ModelHelper.Log(LogType.Requirement,
                    "\tOpen.Session.Connection.ClientGuid is not equal to the current Connection.ClientGuid.");
                ModelHelper.Log(LogType.TestInfo, "All the above conditions are met.");

                ModelHelper.Log(LogType.Requirement,
                    "If an Open is found, the server MUST calculate the maximal access that the user, " +
                    "identified by Session.SecurityContext, has on the file being opened<277>. " +
                    "If the maximal access includes GENERIC_READ access, the server MUST close the open as specified in 3.3.4.17.");
                // The user used in this model is administrator, so maximal access always includes GENERIC_READ access.
                ModelHelper.Log(LogType.TestInfo, "The maximal access includes GENERIC_READ access. So open is closed.");

                // close open
                Open = null;
            }
            else
            {
                ModelHelper.Log(LogType.TestInfo, "appInstanceIdType is {0}.", appInstanceIdType.ToString());
                ModelHelper.Log(LogType.TestInfo, "pathNameType is {0}.", pathNameType.ToString());
                ModelHelper.Log(LogType.TestInfo, "shareType is {0}.", shareType.ToString());
                ModelHelper.Log(LogType.TestInfo, "clientGuidType is {0}.", clientGuidType.ToString());
                ModelHelper.Log(LogType.TestInfo, "All the above conditions do not match the requirement, so open will not be closed.");

                ModelHelper.Log(LogType.TestTag, TestTag.UnexpectedFields);
            }
        }
        public void OpenRequest(
            ClientGuidType clientGuidType,
            PathNameType pathNameType,
            CreateType createType,
            ShareType shareType,
            AppInstanceIdType appInstanceIdType)
        {
            Smb2FunctionalClient testClient = new Smb2FunctionalClient(testConfig.Timeout, testConfig, this.Site);
            uint treeId;
            string share;
            switch (shareType)
            {
                case ShareType.SameShare:
                    share = testConfig.BasicFileShare;
                    break;
                case ShareType.DifferentShareSameLocal:
                    share = testConfig.SameWithSMBBasic;
                    break;
                case ShareType.DifferentShareDifferentLocal:
                    share = testConfig.DifferentFromSMBBasic;
                    cleanFileInDifferentShare = true;
                    break;
                default:
                    throw new ArgumentException("shareType");
            }

            ConnectToShare(
                clientDialect,
                testClient,
                clientGuidType == ClientGuidType.SameClientGuid ? this.connection_ClientGuid : Guid.NewGuid(),
                share,
                out treeId);

            FILEID fileId;
            Smb2CreateContextResponse[] createContextResponse;
            uint status;
            string fileNameInOpen;
            if (pathNameType == PathNameType.SamePathName)
            {
                fileNameInOpen = fileName;
            }
            else
            {
                fileNameInOpen = fileName + different;
                cleanFileWithDifferentName = true;
            }

            status = testClient.Create(
                treeId,
                fileNameInOpen,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out createContextResponse,
                createContexts: CreateContexts(appInstanceIdType, createType, false),
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) => { });

            // The file is not created, no need to delete.
            if (status != Smb2Status.STATUS_SUCCESS)
            {
                cleanFileInDifferentShare = false;
                cleanFileWithDifferentName = false;
            }

            testClient.Disconnect();
            testClient = null;

            // Check if the Open is closed.
            // If status is success, and fileId is the same with the previous one, then the Open is not closed.
            // Otherwise, use some other way to check if the Open is closed.
            bool ifClosed;
            if (status == Smb2Status.STATUS_SUCCESS && fileId.Persistent == this.open_FileId.Persistent)
                ifClosed = false;
            else
                ifClosed = CheckIfOpenClosed(clientDialect, createType);
            this.OpenResponse(ifClosed ? OpenStatus.OpenClosed : OpenStatus.OpenNotClosed);
        }
        /// <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();
        }