Exemplo n.º 1
0
        public static void ClassInitialize(TestContext testContext)
        {
            // A method is used to initialize the variables.
            TestClassBase.Initialize(testContext);
            if (null == MSCopysAdapter)
            {
                MSCopysAdapter = BaseTestSite.GetAdapter <IMS_COPYSAdapter>();
            }

            if (null == MSCOPYSSutControlAdapter)
            {
                MSCOPYSSutControlAdapter = BaseTestSite.GetAdapter <IMS_COPYSSUTControlAdapter>();
            }

            if (null == FilesUrlRecordOfDestination)
            {
                FilesUrlRecordOfDestination = new List <string>();
            }

            if (string.IsNullOrEmpty(SourceFileContentBase64Value))
            {
                string sourceFileContent        = Common.GetConfigurationPropertyValue("SourceFileContents", BaseTestSite);
                byte[] souceFileContentBinaries = Encoding.UTF8.GetBytes(sourceFileContent);
                SourceFileContentBase64Value = Convert.ToBase64String(souceFileContentBinaries);
            }
        }
Exemplo n.º 2
0
 protected override void TestInitialize()
 {
     base.TestInitialize();
     fileName = SmbdUtilities.CreateRandomFileName();
     sutProtocolControlAdapter = BaseTestSite.GetAdapter <ISutProtocolControlAdapter>();
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
Exemplo n.º 3
0
        public static void BaseInitialize(TestContext context)
        {
            TestClassBase.Initialize(context);

            // load ptfconfig properties
            EnvironmentConfig.LoadParameters(BaseTestSite);
            EnvironmentConfig.CheckParameters(BaseTestSite);

            // initialize controller adapter
            SutAdapter      = BaseTestSite.GetAdapter <ISUTControlAdapter>();
            AsyncSutAdapter = new SUTControlAdapterAsync(SutAdapter);

            // initialize client adapter
            ClientAdapter = BaseTestSite.GetAdapter <IMSADFSPIPClientAdapter>();
            if (!m_sslCertBinded)
            {
                ClientAdapter.BindCertificate(new X509Certificate2(
                                                  EnvironmentConfig.TLSServerCertificatePath,
                                                  EnvironmentConfig.TLSServerCertificatePassword));
                m_sslCertBinded = true;
            }

            // initialize server data model and handler factory
            ServerDataModel = ServerDataModel.InitiateServerDataModel();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read and write the file within the locking byte range when lock or unlock is taken
        /// </summary>
        /// <param name="isLocked">Set true to indicate that access the file when lock operation is taken</param>
        private void ValidateByteLockRangeFromAnotherClient(bool isLocked)
        {
            Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);

            client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);

            status = client.Negotiate(
                TestConfig.RequestDialects,
                TestConfig.IsSMB1NegotiateEnabled,
                capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES);

            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            uint treeId;

            status = client.TreeConnect(uncSharePath, out treeId);

            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fileId;

            status = client.Create(
                treeId,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts);

            string data;
            Random random = new Random();
            uint   offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
            uint   length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));

            status = client.Read(treeId, fileId, offset, length, out data);

            status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
            if (isLocked)
            {
                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content to locked range of file from different client is not expected to success");
                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_FILE_LOCK_CONFLICT,
                    status,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
            }
            else
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content in file failed with error code=" + Smb2Status.GetStatusCode(status));
            }
        }
        public void RpcAdapterGetAdapter()
        {
            IMyRpcAdapter myRpcAdapter = BaseTestSite.GetAdapter <IMyRpcAdapter>();

            BaseTestSite.Assert.IsNotNull(myRpcAdapter, "Get rpc adapter should succeed.");
            myRpcAdapter.Reset();
        }
Exemplo n.º 6
0
 public static void TestSuiteClassInitialize(TestContext testContext)
 {
     // A method is used to initialize the variables.
     TestClassBase.Initialize(testContext);
     CPSWSAdapter      = BaseTestSite.GetAdapter <IMS_CPSWSAdapter>();
     SutControlAdapter = BaseTestSite.GetAdapter <IMS_CPSWSSUTControlAdapter>();
 }
Exemplo n.º 7
0
        public static void ClassInitialize(TestContext testContext)
        {
            TestClassBase.Initialize(testContext);

            adapter    = BaseTestSite.GetAdapter <IMS_WEBSSAdapter>();
            sutAdapter = BaseTestSite.GetAdapter <IMS_WEBSSSUTControlAdapter>();
        }
Exemplo n.º 8
0
        protected override void TestInitialize()
        {
            base.TestInitialize();

            testConfig    = new ServerFailoverTestConfig(BaseTestSite);
            sutController = BaseTestSite.GetAdapter <ISutControlAdapter>();
        }
 public void CaptureRequirementAddRequirement()
 {
     BaseTestSite.Log.Add(
         LogEntryKind.Checkpoint,
         RequirementId.Make(BaseTestSite.DefaultProtocolDocShortName, 0, "Add a requirement."));
     BaseTestSite.CaptureRequirement(0, "Add a requirement.");
 }
Exemplo n.º 10
0
        /// <summary>
        /// Read and write file within byte lock range when the file is locked or unlocked
        /// </summary>
        /// <param name="isLocked">Set true to indicate that byte lock range is taken on the file</param>
        /// <param name="serverName">Name of file server to access</param>
        /// <param name="targetFileName">Target file name to read and write</param>
        private void ValidateByteLockRangeFromAnotherClient(bool isLocked, string serverName, string targetFileName)
        {
            uint status = 0;

            Smb2FunctionalClient client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);

            client = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);
            client.ConnectToServer(TestConfig.UnderlyingTransport, serverName, currentAccessIp);

            status = client.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);

            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                serverName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);

            uint treeId;

            status = client.TreeConnect(uncSharePath, out treeId);

            Smb2CreateContextResponse[] serverCreateContexts;
            FILEID fileId;

            status = client.Create(
                treeId,
                targetFileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts);

            string data;
            Random random = new Random();
            uint   offset = (uint)random.Next(0, TestConfig.WriteBufferLengthInKb * 1024 - 1);
            uint   length = (uint)random.Next(0, (int)(TestConfig.WriteBufferLengthInKb * 1024 - offset));

            status = client.Read(treeId, fileId, offset, length, out data);

            status = client.Write(treeId, fileId, contentWrite, checker: (header, response) => { });
            if (isLocked)
            {
                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content to locked range of file from different client is not expected to success");
                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_FILE_LOCK_CONFLICT,
                    status,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Id,
                    RequirementCategory.STATUS_FILE_LOCK_CONFLICT.Description);
            }
            else
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    status,
                    "Write content in file should succeed, actual status is {0}", Smb2Status.GetStatusCode(status));
            }
        }
 public void CaptureRequirementIsInstanceOfPassed()
 {
     BaseTestSite.CaptureRequirementIfIsInstanceOfType(
         2,
         typeof(System.Int32),
         11,
         "The type of the instance should be System.Int32.");
 }
 public void CaptureRequirementIsNotInstanceOfFailed()
 {
     BaseTestSite.CaptureRequirementIfIsNotInstanceOfType(
         2,
         typeof(System.Int32),
         14,
         "The type of the instance should not be System.Int32.");
 }
 public void CaptureRequirementIsInstanceOfFailed()
 {
     BaseTestSite.CaptureRequirementIfIsInstanceOfType(
         2,
         typeof(System.String),
         12,
         "The type of the instance should be System.String.");
 }
Exemplo n.º 14
0
 protected override void TestInitialize()
 {
     base.TestInitialize();
     sutProtocolControlAdapter = BaseTestSite.GetAdapter <ISutProtocolControlAdapter>();
     this.smbdAdapter          = new SmbdAdapter(BaseTestSite, LogSmbdEndpointEvent);
     fileNameList = new List <string>();
     SmbdUtilities.LogTestCaseDescription(BaseTestSite);
 }
 public void CaptureRequirementIsNotInstanceOfPassed()
 {
     BaseTestSite.CaptureRequirementIfIsNotInstanceOfType(
         2,
         typeof(System.String),
         13,
         "The type of the instance should not be System.String.");
 }
 protected override void TestInitialize()
 {
     ldapAdapter       = BaseTestSite.GetAdapter <ILdapAdapter>();
     sutControlAdapter = BaseTestSite.GetAdapter <IDrsrSutControlAdapter>();
     updateStorage     = UpdatesStorage.GetInstance();
     drsTestClient.Reset();
     EnvironmentConfig.ExpectSuccess = true;
     base.TestInitialize();
 }
Exemplo n.º 17
0
        protected override void TestInitialize()
        {
            base.TestInitialize();

            testConfig = new TestConfig(BaseTestSite);

            BaseTestSite.DefaultProtocolDocShortName = "BranchCache";

            sutControlAdapter = BaseTestSite.GetAdapter <ISUTControlAdapter>();

            contentInformationUtility = new ContentInformationUtility(BaseTestSite, testConfig, sutControlAdapter);
        }
Exemplo n.º 18
0
        public void ContentServer_SmbServer_OffsetInvalid()
        {
            CheckApplicability();

            contentInformationUtility.RetrieveContentData();

            using (Smb2ClientTransport smb2Client = new Smb2ClientTransport(testConfig.Timeout))
            {
                smb2Client.OpenFile(
                    testConfig.ContentServerComputerName,
                    testConfig.SharedFolderName,
                    testConfig.NameOfFileWithMultipleBlocks,
                    testConfig.SecurityPackageType,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword,
                    AccessMask.GENERIC_READ);

                HASH_HEADER hashHeader;
                byte[]      hashData;

                uint smb2Status = 0;
                TestUtility.DoUntilSucceed(
                    () => (smb2Status = smb2Client.ReadHash(
                               SRV_READ_HASH_Request_HashType_Values.SRV_HASH_TYPE_PEER_DIST,
                               SRV_READ_HASH_Request_HashVersion_Values.SRV_HASH_VER_1,
                               SRV_READ_HASH_Request_HashRetrievalType_Values.SRV_HASH_RETRIEVE_HASH_BASED,
                               uint.MaxValue,
                               uint.MaxValue,
                               out hashHeader,
                               out hashData)) != Smb2Status.STATUS_HASH_NOT_PRESENT,
                    testConfig.Timeout,
                    testConfig.RetryInterval);

                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    smb2Status,
                    "The content server should return error for invalid offset");

                /// If the HashRetrievalType is SRV_HASH_RETRIEVE_FILE_BASED and Offset field of the SRV_READ_HASH request is equal to or beyond the end of the file
                /// represented by Open.LocalOpen, the server MUST fail the SRV_READ_HASH request with error code STATUS_END_OF_FILE.
                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_END_OF_FILE,
                    smb2Status,
                    RequirementCategory.EndOfFile,
                    RequirementCategory.EndOfFileMessage);

                smb2Client.CloseFile();
            }
        }
Exemplo n.º 19
0
        public void TcpAdapterTryConnect()
        {
            // Set up a tcp listener, and wait for the tcp connect
            TcpListener tcpListener = new
                                      TcpListener(IPAddress.Parse(BaseTestSite.Properties["MyTcpAdapter.hostname"]), Int32.Parse(BaseTestSite.Properties["MyTcpAdapter.port"]));

            tcpListener.Start();

            IMyTcpAdapter myTcpAdapter = BaseTestSite.GetAdapter <IMyTcpAdapter>();

            BaseTestSite.Assert.IsNotNull(myTcpAdapter, "Get tcp adapter should succeed.");
            myTcpAdapter.Reset();
            tcpListener.Stop();
        }
Exemplo n.º 20
0
        protected override void TestInitialize()
        {
            base.TestInitialize();
            sutAdapter = BaseTestSite.GetAdapter <ISUTControlAdapter>();
            EnvironmentConfig.LoadParameters(BaseTestSite);
            server = new TestServer();
            server.Initialize(BaseTestSite);
            bool       isDeploy = EnvironmentConfig.TestDeployment;
            StackTrace trace    = new System.Diagnostics.StackTrace();

            StackFrame[] frames = trace.GetFrames();
            ValidationModel.Initialize(BaseTestSite, isDeploy);
            ValidationModel.Reset();
        }
Exemplo n.º 21
0
        public static void ClassInitialize(TestContext testContext)
        {
            // A method is used to initialize the variables.
            TestClassBase.Initialize(testContext);

            if (null == SHDACCWSAdapter)
            {
                SHDACCWSAdapter = BaseTestSite.GetAdapter <IMS_SHDACCWSAdapter>();
            }

            if (null == SHDACCWSSUTControlAdapter)
            {
                SHDACCWSSUTControlAdapter = BaseTestSite.GetAdapter <IMS_SHDACCWSSUTControlAdapter>();
            }
        }
Exemplo n.º 22
0
        public void ContentServer_SmbServer_HashV2HashBased_Smb21()
        {
            CheckApplicability();

            contentInformationUtility.RetrieveContentData();

            using (Smb2ClientSupportDialect smb2Client = new Smb2ClientSupportDialect(testConfig.Timeout, DialectRevision.Smb21))
            {
                smb2Client.OpenFile(
                    testConfig.ContentServerComputerName,
                    testConfig.SharedFolderName,
                    testConfig.NameOfFileWithMultipleBlocks,
                    testConfig.SecurityPackageType,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword,
                    AccessMask.GENERIC_READ);

                HASH_HEADER hashHeader;
                byte[]      hashData;

                uint smb2Status = 0;
                TestUtility.DoUntilSucceed(
                    () => (smb2Status = smb2Client.ReadHash(
                               SRV_READ_HASH_Request_HashType_Values.SRV_HASH_TYPE_PEER_DIST,
                               SRV_READ_HASH_Request_HashVersion_Values.SRV_HASH_VER_2,
                               SRV_READ_HASH_Request_HashRetrievalType_Values.SRV_HASH_RETRIEVE_HASH_BASED,
                               0,
                               uint.MaxValue,
                               out hashHeader,
                               out hashData)) != Smb2Status.STATUS_HASH_NOT_PRESENT,
                    testConfig.Timeout,
                    testConfig.RetryInterval);

                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    smb2Status,
                    "The content server should return error for invalid hash type");

                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_INVALID_PARAMETER,
                    smb2Status,
                    RequirementCategory.InvalidParameter,
                    RequirementCategory.InvalidParameterMessage);

                smb2Client.CloseFile();
            }
        }
Exemplo n.º 23
0
        public void TestCaseInitialize()
        {
            this.TestInitialize();

            this.adapter             = BaseTestSite.GetAdapter <IMS_WSSRESTAdapter>();
            this.sutAdapter          = BaseTestSite.GetAdapter <IMS_WSSRESTSUTControlAdapter>();
            this.documentLibraryName = Common.GetConfigurationPropertyValue("DoucmentLibraryListName", this.Site);
            this.generalListName     = Common.GetConfigurationPropertyValue("GeneralListName", this.Site);

            // Check if MS-WSSREST service is supported in current SUT.
            if (!Common.GetConfigurationPropertyValue <bool>("MS-WSSREST_Supported", this.Site))
            {
                SutVersion currentSutVersion = Common.GetConfigurationPropertyValue <SutVersion>("SutVersion", this.Site);
                this.Site.Assert.Inconclusive("This test suite does not supported under current SUT, because MS-WSSREST_Supported value set to false in MS-WSSREST_{0}_SHOULDMAY.deployment.ptfconfig file.", currentSutVersion);
            }
        }
Exemplo n.º 24
0
        protected override void TestInitialize()
        {
            base.TestInitialize();
            this.testConfig    = new TestConfig();
            this.sutController = BaseTestSite.GetAdapter <ISutControlAdapter>();

            if (this.testConfig.LocalRealm.KDC[0].IsWindows && this.testConfig.TrustType != TrustType.NoTrust)
            {
                //set forest trust authentication as forest-wide authentication
                this.sutController.setSelectiveAuth(this.testConfig.LocalRealm.RealmName, this.testConfig.LocalRealm.Admin.Username, this.testConfig.LocalRealm.Admin.Password, this.testConfig.TrustedRealm.RealmName, false);
            }
            if (this.testConfig.TrustedRealm.KDC[0].IsWindows && this.testConfig.TrustType != TrustType.NoTrust)
            {
                //set forest trust authentication as forest-wide authentication
                this.sutController.setSelectiveAuth(this.testConfig.TrustedRealm.RealmName, this.testConfig.TrustedRealm.Admin.Username, this.testConfig.TrustedRealm.Admin.Password, this.testConfig.LocalRealm.RealmName, false);
            }

            // create KKDCP Client Config according to config file
            if (this.testConfig.UseProxy && proxyClientConfig == null)
            {
                X509Certificate2 clientCert = null;
                if (!string.IsNullOrEmpty(this.testConfig.KKDCPClientCertPath))
                {
                    Assert.IsFalse(!string.IsNullOrEmpty(this.testConfig.KKDCPClientCertPassword), "The protected password should be set.");
                    clientCert = new X509Certificate2();
                    try
                    {
                        clientCert.Import(this.testConfig.KKDCPClientCertPath, this.testConfig.KKDCPClientCertPassword, X509KeyStorageFlags.DefaultKeySet);
                    }
                    catch
                    {
                        BaseTestSite.Log.Add(LogEntryKind.TestError, "Error in importing client certificate.");
                        throw;
                    }
                }
                proxyClientConfig = new KKDCPClientConfig()
                {
                    KKDCPServerURL       = this.testConfig.KKDCPServerUrl,
                    TlsClientCertificate = clientCert
                };
            }

            IClientControlAdapter adapter = BaseTestSite.GetAdapter <IClientControlAdapter>();

            adapter.RestoreSupportedEncryptionTypes();
            adapter.EnableCompoundIdentity();
        }
Exemplo n.º 25
0
        public static void ClassInitialize(TestContext testContext)
        {
            // A method is used to initialize the variables.
            TestClassBase.Initialize(testContext);

            Adapter           = BaseTestSite.GetAdapter <IMS_VIEWSSAdapter>();
            SutControlAdapter = BaseTestSite.GetAdapter <IMS_VIEWSSSUTControlAdapter>();

            string displayListName = Common.GetConfigurationPropertyValue("DisplayListName", BaseTestSite);

            TestSuiteBase.ListGUID = SutControlAdapter.GetListGuidByName(displayListName);

            if (TestSuiteBase.OriginalDefaultViewChecked == false)
            {
                // Get name of the default view.
                TestSuiteBase.OriginalDefaultViewName    = SutControlAdapter.GetListAndView(displayListName);
                TestSuiteBase.OriginalDefaultViewChecked = true;
            }
        }
Exemplo n.º 26
0
        public void ContentServer_SmbServer_HashTypeInvalid()
        {
            CheckApplicability();

            contentInformationUtility.RetrieveContentData();

            using (Smb2ClientTransport smb2Client = new Smb2ClientTransport(testConfig.Timeout))
            {
                smb2Client.OpenFile(
                    testConfig.ContentServerComputerName,
                    testConfig.SharedFolderName,
                    testConfig.NameOfFileWithMultipleBlocks,
                    testConfig.SecurityPackageType,
                    testConfig.DomainName,
                    testConfig.UserName,
                    testConfig.UserPassword,
                    AccessMask.GENERIC_READ);

                HASH_HEADER hashHeader;
                byte[]      hashData;
                uint        smb2Status = smb2Client.ReadHash(
                    (SRV_READ_HASH_Request_HashType_Values)0xFEFEFEFE,
                    SRV_READ_HASH_Request_HashVersion_Values.SRV_HASH_VER_1,
                    SRV_READ_HASH_Request_HashRetrievalType_Values.SRV_HASH_RETRIEVE_HASH_BASED,
                    0,
                    uint.MaxValue,
                    out hashHeader,
                    out hashData);

                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    smb2Status,
                    "The content server should return error for invalid hash type");

                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_INVALID_PARAMETER,
                    smb2Status,
                    RequirementCategory.InvalidParameter,
                    RequirementCategory.InvalidParameterMessage);

                smb2Client.CloseFile();
            }
        }
        protected override void TestInitialize()
        {
            //Initialize all adapters
            base.TestInitialize();
            this.TestConfig    = new AzodTestConfig(this.TestSite);
            this.sutController = BaseTestSite.GetAdapter <ISutControlAdapter>();

            maAdapter = BaseTestSite.GetAdapter <IMessageAnalyzerAdapter>();
            maAdapter.Reset();

            // Capture files location on the driver computer
            if (!Directory.Exists(TestConfig.LocalCapFilePath))
            {
                Directory.CreateDirectory(TestConfig.LocalCapFilePath);
            }
            // Logs Path for Powershell Adapter on the driver computer.
            if (!Directory.Exists(TestConfig.DriverLogPath))
            {
                Directory.CreateDirectory(TestConfig.DriverLogPath);
            }
            //other initialization setting if needed
        }
Exemplo n.º 28
0
        public static void ClassInitialize(TestContext testContext)
        {
            TestClassBase.Initialize(testContext);

            if (null == StartedTaskIdsRecorder)
            {
                StartedTaskIdsRecorder = new List <string>();
            }

            if (null == UploadedFilesUrlRecorder)
            {
                UploadedFilesUrlRecorder = new List <string>();
            }

            if (null == ProtocolAdapter)
            {
                ProtocolAdapter = BaseTestSite.GetAdapter <IMS_WWSPAdapter>();
            }

            if (null == SutController)
            {
                SutController = BaseTestSite.GetAdapter <IMS_WWSPSUTControlAdapter>();
            }
        }
        public void DurableHandleV2_Reconnect_WithDifferentDurableOwner()
        {
            /// 1. Client requests a durable handle V2 with LeaseV1 context
            /// 2. Client disconnects
            /// 3. Client reconnects the durable handle V2 with a different durable owner, and expects that server will return STATUS_ACCESS_DENIED.

            #region Check Applicability
            TestConfig.CheckDialect(DialectRevision.Smb30);
            TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_LEASING);
            TestConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2, CreateContextTypeValue.SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2, CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);
            #endregion

            string content    = Smb2Utility.CreateRandomString(testConfig.WriteBufferLengthInKb);
            Guid   clientGuid = Guid.NewGuid();
            durableHandleUncSharePath = Smb2Utility.GetUncPath(testConfig.SutComputerName, testConfig.BasicFileShare);
            fileName = "DurableHandleV2_Reconnect_WithDifferentDurableOwner" + Guid.NewGuid() + ".txt";

            #region client connect to server
            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "Client connects to server and opens file with a durable handle");

            uint treeIdBeforeDisconnection;
            Connect(DialectRevision.Smb30, clientBeforeDisconnection, clientGuid, testConfig.AccountCredential, ConnectShareType.BasicShareWithoutAssert, out treeIdBeforeDisconnection, null);

            Guid                        createGuid = Guid.NewGuid();
            Guid                        leaseKey   = Guid.NewGuid();
            LeaseStateValues            leaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING | LeaseStateValues.SMB2_LEASE_WRITE_CACHING;
            FILEID                      fileIdBeforeDisconnection;
            Smb2CreateContextResponse[] serverCreateContexts = null;
            status = clientBeforeDisconnection.Create(
                treeIdBeforeDisconnection,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdBeforeDisconnection,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[] {
                new Smb2CreateDurableHandleRequestV2
                {
                    CreateGuid = createGuid,
                },
                new Smb2CreateRequestLeaseV2
                {
                    LeaseKey   = leaseKey,
                    LeaseState = leaseState,
                }
            },
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should be successful, actually server returns {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                CheckCreateContextResponses(serverCreateContexts, new DefaultDurableHandleV2ResponseChecker(BaseTestSite, 0, uint.MaxValue));
            });

            status = clientBeforeDisconnection.Write(treeIdBeforeDisconnection, fileIdBeforeDisconnection, content);
            #endregion

            clientBeforeDisconnection.Disconnect();

            #region client reconnect to server
            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                "Client opens the same file and reconnects the durable handle");

            uint treeIdAfterDisconnection;
            Connect(DialectRevision.Smb30, clientAfterDisconnection, clientGuid, testConfig.NonAdminAccountCredential, ConnectShareType.BasicShareWithoutAssert, out treeIdAfterDisconnection, clientBeforeDisconnection);

            FILEID fileIdAfterDisconnection;
            clientAfterDisconnection.Create(
                treeIdAfterDisconnection,
                fileName,
                CreateOptions_Values.FILE_NON_DIRECTORY_FILE,
                out fileIdAfterDisconnection,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[] {
                new Smb2CreateDurableHandleReconnectV2
                {
                    CreateGuid = createGuid,
                    FileId     = new FILEID {
                        Persistent = fileIdBeforeDisconnection.Persistent
                    }
                },
                new Smb2CreateRequestLeaseV2
                {
                    LeaseKey   = leaseKey,
                    LeaseState = leaseState,
                }
            },
                shareAccess: ShareAccess_Values.NONE,
                checker: (header, response) =>
            {
                BaseTestSite.Assert.AreNotEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "{0} should not be successful if the DurableOwner is different, actually server returns {1}.", header.Command, Smb2Status.GetStatusCode(header.Status));
                BaseTestSite.CaptureRequirementIfAreEqual(
                    Smb2Status.STATUS_ACCESS_DENIED,
                    header.Status,
                    RequirementCategory.STATUS_ACCESS_DENIED.Id,
                    RequirementCategory.STATUS_ACCESS_DENIED.Description);
            });

            #endregion

            clientAfterDisconnection.TreeDisconnect(treeIdAfterDisconnection);
            clientAfterDisconnection.LogOff();
            clientAfterDisconnection.Disconnect();
        }
        private void DirecotryLeasing(
            DialectRevision[] requestDialect,
            DialectRevision expectedDialect,
            LeaseStateValues leaseState,
            LeaseBreakAckType leaseBreakAckType = LeaseBreakAckType.None)
        {
            #region Check Applicability
            TestConfig.CheckDialect(DialectRevision.Smb30);
            TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING);
            TestConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2);
            #endregion

            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                @"Start to create a directory on share \\{0}\{1} with lease state {2}",
                TestConfig.SutComputerName, TestConfig.BasicFileShare, leaseState);

            string testDirectory = CreateTestDirectory(TestConfig.SutComputerName, TestConfig.BasicFileShare);
            client.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);

            #region Negotiate
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start the client by sending the following requests: NEGOTIATE; SESSION_SETUP; TREE_CONNECT");
            Capabilities_Values capabilities = Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES;
            status = client.Negotiate(
                requestDialect,
                TestConfig.IsSMB1NegotiateEnabled,
                capabilityValue: capabilities,
                checker: (Packet_Header header, NEGOTIATE_Response response) =>
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "Negotiation should succeed, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));

                TestConfig.CheckNegotiateDialect(expectedDialect, response);
                if (expectedDialect >= DialectRevision.Smb30)
                {
                    TestConfig.CheckNegotiateCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING, response);
                }
            });
            #endregion

            #region SESSION_SETUP
            status = client.SessionSetup(
                TestConfig.DefaultSecurityPackage,
                TestConfig.SutComputerName,
                TestConfig.AccountCredential,
                TestConfig.UseServerGssToken);
            #endregion

            #region TREE_CONNECT to share
            string uncSharePath = Smb2Utility.GetUncPath(TestConfig.SutComputerName, TestConfig.BasicFileShare);
            uint   treeId;
            status = client.TreeConnect(uncSharePath, out treeId);
            #endregion

            #region CREATE
            FILEID fileId;
            Smb2CreateContextResponse[] serverCreateContexts;
            BaseTestSite.Log.Add(
                LogEntryKind.TestStep,
                "Client sends CREATE request for the directory with the LeaseState set to {0} in SMB2_CREATE_REQUEST_LEASE_V2.", leaseState);
            status = client.Create(
                treeId,
                testDirectory,
                CreateOptions_Values.FILE_DIRECTORY_FILE,
                out fileId,
                out serverCreateContexts,
                RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                new Smb2CreateContextRequest[]
            {
                new Smb2CreateRequestLeaseV2
                {
                    LeaseKey   = Guid.NewGuid(),
                    LeaseState = leaseState
                }
            },
                checker: (Packet_Header header, CREATE_Response response) =>
            {
                BaseTestSite.Assert.AreEqual(
                    Smb2Status.STATUS_SUCCESS,
                    header.Status,
                    "CREATE should succeed, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));

                if (expectedDialect == DialectRevision.Smb2002 || expectedDialect == DialectRevision.Smb21)
                {
                    BaseTestSite.Assert.AreEqual(
                        OplockLevel_Values.OPLOCK_LEVEL_NONE,
                        response.OplockLevel,
                        "The expected oplock level is OPLOCK_LEVEL_NONE.");
                }
            });

            #endregion

            if (expectedDialect >= DialectRevision.Smb30)
            {
                // Break the lease with creating another file in the directory
                sutProtocolController.CreateFile(Path.Combine(Smb2Utility.GetUncPath(TestConfig.SutComputerName, TestConfig.BasicFileShare), testDirectory), CurrentTestCaseName, string.Empty);

                // Wait until LEASE_BREAK_Notification is received
                BaseTestSite.Assert.IsTrue(
                    // Wait 5 seconds for notification arrival
                    notificationReceived.WaitOne(SMB2TestConfig.WAIT_TIMEOUT_IN_MILLISECONDS),
                    "LeaseBreakNotification should be raised.");

                if (receivedLeaseBreakNotify.Flags == LEASE_BREAK_Notification_Packet_Flags_Values.SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED)
                {
                    BaseTestSite.Log.Add(
                        LogEntryKind.Debug,
                        "Server requires an LEASE_BREAK_ACK on this LEASE_BREAK_NOTIFY");

                    #region LEASE_BREAK_ACK
                    switch (leaseBreakAckType)
                    {
                    case LeaseBreakAckType.None:
                        status = client.LeaseBreakAcknowledgment(treeId, receivedLeaseBreakNotify.LeaseKey, receivedLeaseBreakNotify.NewLeaseState);
                        break;

                    case LeaseBreakAckType.InvalidLeaseState:
                        LeaseStateValues newLeaseState = LeaseStateValues.SMB2_LEASE_WRITE_CACHING;
                        BaseTestSite.Log.Add(
                            LogEntryKind.Comment,
                            "Client attempts to send LEASE_BREAK_ACK with an invalid LeaseState {0} on this LEASE_BREAK_NOTIFY", newLeaseState);
                        status = client.LeaseBreakAcknowledgment(
                            treeId,
                            receivedLeaseBreakNotify.LeaseKey,
                            newLeaseState,
                            checker: (header, response) =>
                        {
                            BaseTestSite.Assert.AreNotEqual(
                                Smb2Status.STATUS_SUCCESS,
                                header.Status,
                                "LEASE_BREAK_ACK with invalid LeaseState is not expected to SUCCESS, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));
                            BaseTestSite.CaptureRequirementIfAreEqual(
                                Smb2Status.STATUS_REQUEST_NOT_ACCEPTED,
                                header.Status,
                                RequirementCategory.STATUS_REQUEST_NOT_ACCEPTED.Id,
                                RequirementCategory.STATUS_REQUEST_NOT_ACCEPTED.Description);
                        });
                        break;

                    case LeaseBreakAckType.InvalidLeaseKey:
                        Guid invalidLeaseKey = Guid.NewGuid();
                        BaseTestSite.Log.Add(
                            LogEntryKind.Debug,
                            "Client attempts to send LEASE_BREAK_ACK with an invalid LeaseKey {0} on this LEASE_BREAK_NOTIFY", invalidLeaseKey);
                        status = client.LeaseBreakAcknowledgment(
                            treeId,
                            invalidLeaseKey,
                            receivedLeaseBreakNotify.NewLeaseState,
                            checker: (header, response) =>
                        {
                            BaseTestSite.Assert.AreNotEqual(
                                Smb2Status.STATUS_SUCCESS,
                                header.Status,
                                "LEASE_BREAK_ACK with invalid LeaseKey is not expected to SUCCESS, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));
                            BaseTestSite.CaptureRequirementIfAreEqual(
                                Smb2Status.STATUS_OBJECT_NAME_NOT_FOUND,
                                header.Status,
                                RequirementCategory.STATUS_OBJECT_NAME_NOT_FOUND.Id,
                                RequirementCategory.STATUS_OBJECT_NAME_NOT_FOUND.Description);
                        });
                        break;

                    case LeaseBreakAckType.InvalidClientGuid:
                        BaseTestSite.Log.Add(LogEntryKind.Debug, "Initialize a new different client to attempts to send LEASE_BREAK_ACK");
                        Smb2FunctionalClient newClient = new Smb2FunctionalClient(TestConfig.Timeout, TestConfig, BaseTestSite);

                        newClient.ConnectToServer(TestConfig.UnderlyingTransport, TestConfig.SutComputerName, TestConfig.SutIPAddress);

                        #region Negotiate
                        status = newClient.Negotiate(
                            requestDialect,
                            TestConfig.IsSMB1NegotiateEnabled,
                            capabilityValue: Capabilities_Values.GLOBAL_CAP_DFS | Capabilities_Values.GLOBAL_CAP_DIRECTORY_LEASING | Capabilities_Values.GLOBAL_CAP_LARGE_MTU | Capabilities_Values.GLOBAL_CAP_LEASING | Capabilities_Values.GLOBAL_CAP_MULTI_CHANNEL | Capabilities_Values.GLOBAL_CAP_PERSISTENT_HANDLES);
                        #endregion

                        #region SESSION_SETUP
                        status = newClient.SessionSetup(
                            TestConfig.DefaultSecurityPackage,
                            TestConfig.SutComputerName,
                            TestConfig.AccountCredential,
                            TestConfig.UseServerGssToken);
                        #endregion

                        #region TREE_CONNECT to share
                        uint newTreeId;
                        status = newClient.TreeConnect(uncSharePath, out newTreeId);
                        #endregion

                        status = newClient.LeaseBreakAcknowledgment(
                            newTreeId,
                            receivedLeaseBreakNotify.LeaseKey,
                            receivedLeaseBreakNotify.NewLeaseState,
                            checker: (header, response) =>
                        {
                            BaseTestSite.Assert.AreNotEqual(
                                Smb2Status.STATUS_SUCCESS,
                                header.Status,
                                "LEASE_BREAK_ACK is not expected to SUCCESS when the open is closed, actually server returns {0}.", Smb2Status.GetStatusCode(header.Status));
                            BaseTestSite.CaptureRequirementIfAreEqual(
                                Smb2Status.STATUS_OBJECT_NAME_NOT_FOUND,
                                header.Status,
                                RequirementCategory.STATUS_OBJECT_NAME_NOT_FOUND.Id,
                                RequirementCategory.STATUS_OBJECT_NAME_NOT_FOUND.Description);
                        });

                        status = newClient.TreeDisconnect(newTreeId);

                        status = newClient.LogOff();

                        BaseTestSite.Log.Add(
                            LogEntryKind.Comment,
                            "Initialize a new different client to attempts to send LEASE_BREAK_ACK");
                        break;

                    default:
                        throw new InvalidOperationException("Unexpected LeaseBreakAckType " + leaseBreakAckType);
                    }

                    #endregion
                }
                else
                {
                    BaseTestSite.Log.Add(
                        LogEntryKind.Debug,
                        "Server does not require an LEASE_BREAK_ACK on this LEASE_BREAK_NOTIFY");
                }
            }

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the client by sending the following requests: TREE_DISCONNECT; LOG_OFF");
            #region TREE_DISCONNECT
            status = client.TreeDisconnect(treeId);
            #endregion

            #region LOGOFF
            status = client.LogOff();
            #endregion

            BaseTestSite.Log.Add(
                LogEntryKind.Comment,
                @"Complete creating a directory on share \\{0}\{1} with lease state {2}",
                TestConfig.SutComputerName, TestConfig.BasicFileShare, leaseState);
        }