private void InitializeClientsConnections(Smb2CreateRequestLease client1RequestLease, Smb2CreateRequestLease client2RequestLease, out Smb2CreateResponseLease client1ResponseLease,
                                                  out Smb2CreateResponseLease client2ResponseLease, bool isBothClientDirectory = false, bool isClient1ParentDirectory = false, bool expectServerBreakNotification = false)
        {
            Smb2CreateContextResponse client1ResponseContext;
            Smb2CreateContextResponse client2ResponseContext;

            SendRequestContext(client1RequestLease, client2RequestLease, out client1ResponseContext, out client2ResponseContext, isBothClientDirectory, isClient1ParentDirectory, expectServerBreakNotification);

            client1ResponseLease = client1ResponseContext as Smb2CreateResponseLease;
            client2ResponseLease = client2ResponseContext as Smb2CreateResponseLease;
        }
Ejemplo n.º 2
0
        public void BVT_Leasing_FileLeasingV1()
        {
            #region Check Applicability
            TestConfig.CheckDialect(DialectRevision.Smb21);
            TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_LEASING);
            TestConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE);
            #endregion

            Smb2CreateContextRequest leaseContext = new Smb2CreateRequestLease
            {
                LeaseKey   = Guid.NewGuid(),
                LeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_WRITE_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING
            };

            TestFileLeasing(leaseContext);
        }
        public void Comparing_Same_File_LeaseKeysV1()
        {
            CheckLeaseApplicability(DialectRevision.Smb21);

            Smb2CreateRequestLease leaseRequest = createLeaseRequestContext();

            Smb2CreateResponseLease client1ResponseLease;
            Smb2CreateResponseLease client2ResponseLease;

            InitializeClientsConnections(leaseRequest, leaseRequest, out client1ResponseLease, out client2ResponseLease);

            #region Test Cases

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Comparing lease keys");
            BaseTestSite.Assert.AreEqual(leaseRequest.LeaseKey, client1ResponseLease.LeaseKey, "Client 1 Request Lease Key MUST be the same its Response Lease key");
            BaseTestSite.Assert.AreEqual(leaseRequest.LeaseKey, client2ResponseLease.LeaseKey, "Client 2 Request Lease Key MUST be the same its Response Lease key");
            BaseTestSite.Assert.AreEqual(client1ResponseLease.LeaseKey, client2ResponseLease.LeaseKey, "LeaseOpen.leaseKey MUST be the same with OperationOpen.LeaseKey");

            #endregion
        }
        public void Comparing_Same_Directory_LeaseKeysV1()
        {
            CheckLeaseApplicability(DialectRevision.Smb21, checkFileTypeSupport: false, checkDirectoryTypeSupport: true);

            Smb2CreateRequestLease leaseRequest = createLeaseRequestContext(leaseState: LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING);

            Smb2CreateResponseLease client1ResponseLease;
            Smb2CreateResponseLease client2ResponseLease;

            InitializeClientsConnections(leaseRequest, leaseRequest, out client1ResponseLease, out client2ResponseLease, isBothClientDirectory: true);

            #region Test Cases

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Comparing lease keys");
            BaseTestSite.Assert.AreEqual(leaseRequest.LeaseKey, client1ResponseLease.LeaseKey, "Client 1 Request Lease Key MUST be the same with its Response Lease key");
            BaseTestSite.Assert.AreEqual(leaseRequest.LeaseKey, client2ResponseLease.LeaseKey, "Client 2 Request Lease Key MUST be the same with its Response Lease key");
            BaseTestSite.Assert.AreEqual(client1ResponseLease.LeaseKey, client2ResponseLease.LeaseKey, "LeaseOpen.leaseKey MUST be the same with OperationOpen.LeaseKey");

            #endregion
        }
Ejemplo n.º 5
0
        public void TestFileLeasing(Smb2CreateContextRequest leaseContext)
        {
            #region Add Event Handler
            client1.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;
            #endregion

            #region Client1 Open a File with Lease RWH
            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                                 "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with context: {0})",
                                 leaseContext is Smb2CreateRequestLease ? "LeaseV1" : "LeaseV2");
            client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client1.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client1TreeId;
            client1.TreeConnect(sharePath, out client1TreeId);
            FILEID client1FileId;
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts

            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            System.Threading.Timer timer = new System.Threading.Timer(CheckBreakNotification, client1TreeId, 0, Timeout.Infinite);

            #region Lease Break RWH => RH
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING;
            client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client2.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client2TreeId;
            client2.TreeConnect(sharePath, out client2TreeId);
            FILEID client2FileId;
            client2.Create(client2TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to RH after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Lease BreakRH => NONE
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The second client sends WRITE request.");
            expectedNewLeaseState = LeaseStateValues.SMB2_LEASE_NONE;
            byte[] data = { 0 };
            client2.Write(client2TreeId, client2FileId, data);

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends LEASE_BREAK_ACKNOWLEDGEMENT request to break lease state to NONE after receiving LEASE_BREAK_NOTIFICATION response from server.");
            #endregion

            #region Tear Down Clients
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client1.Close(client1TreeId, client1FileId);
            client1.TreeDisconnect(client1TreeId);
            client1.LogOff();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client2.Close(client2TreeId, client2FileId);
            client2.TreeDisconnect(client2TreeId);
            client2.LogOff();
            #endregion
        }
Ejemplo n.º 6
0
        public void TestFileLeasingKey(Smb2CreateContextRequest leaseContext)
        {
            #region Add Event Handler
            client1.Smb2Client.LeaseBreakNotificationReceived += new Action <Packet_Header, LEASE_BREAK_Notification_Packet>(base.OnLeaseBreakNotificationReceived);
            clientToAckLeaseBreak = client1;
            #endregion

            #region Client1 Open a File with Lease RWH
            BaseTestSite.Log.Add(LogEntryKind.TestStep,
                                 "Start the first client to create a file by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE (with context: {0})",
                                 leaseContext is Smb2CreateRequestLease ? "LeaseV1" : "LeaseV2");
            client1.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client1.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client1TreeId;
            client1.TreeConnect(sharePath, out client1TreeId);
            FILEID client1FileId;
            Smb2CreateContextResponse[] createContextResponse;
            client1.Create(client1TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client1FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts of Client1

            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            // Create a task to invoke CheckBreakNotification to check whether server will send out lease break notification or not, no acknowledgement required
            var checkFirstBreakNotificationTask = Task.Run(() => CheckBreakNotification(client1TreeId, false));

            #region Start a second client to request lease by using the same lease key with the first client
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Start a second client to create the same file with the first client by sending the following requests: 1. NEGOTIATE; 2. SESSION_SETUP; 3. TREE_CONNECT; 4. CREATE");
            client2.Negotiate(TestConfig.RequestDialects, TestConfig.IsSMB1NegotiateEnabled);
            client2.SessionSetup(TestConfig.DefaultSecurityPackage, TestConfig.SutComputerName, TestConfig.AccountCredential, false);
            uint client2TreeId;
            client2.TreeConnect(sharePath, out client2TreeId);
            FILEID client2FileId;
            client2.Create(client2TreeId, fileName, CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out client2FileId, out createContextResponse, RequestedOplockLevel_Values.OPLOCK_LEVEL_LEASE,
                           new Smb2CreateContextRequest[]
            {
                leaseContext
            }
                           );
            #endregion

            #region Check Response Contexts of Client2
            if (leaseContext is Smb2CreateRequestLease)
            {
                Smb2CreateRequestLease leaseRequest = leaseContext as Smb2CreateRequestLease;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            else if (leaseContext is Smb2CreateRequestLeaseV2)
            {
                Smb2CreateRequestLeaseV2 leaseRequest = leaseContext as Smb2CreateRequestLeaseV2;
                CheckCreateContextResponses(createContextResponse, new DefaultLeaseV2ResponseChecker(BaseTestSite, leaseRequest.LeaseKey, leaseRequest.LeaseState, LeaseFlagsValues.NONE));
            }
            #endregion

            #region The first client send write request
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client sends WRITE request.");
            byte[] data = { 0 };
            client1.Write(client1TreeId, client1FileId, data);
            #endregion

            #region The second client send write request
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The second client sends WRITE request.");
            client2.Write(client2TreeId, client2FileId, data);
            #endregion

            #region Check whether the server will send lease break notification
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "The first client will not receive lease break notification since the second client is using the same lease key");
            checkFirstBreakNotificationTask.Wait(TestConfig.WaitTimeoutInMilliseconds);
            #endregion

            #region Tear Down Clients
            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the first client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client1.Close(client1TreeId, client1FileId);
            client1.TreeDisconnect(client1TreeId);
            client1.LogOff();

            BaseTestSite.Log.Add(LogEntryKind.TestStep, "Tear down the second client by sending the following requests: 1. CLOSE; 2. TREE_DISCONNECT; 3. LOG_OFF");
            client2.Close(client2TreeId, client2FileId);
            client2.TreeDisconnect(client2TreeId);
            client2.LogOff();
            #endregion
        }