public void Comparing_Same_LeaseKeysV2() { CheckLeaseApplicability(); Smb2CreateRequestLeaseV2 leaseRequest = createLeaseV2RequestContext(); Smb2CreateResponseLeaseV2 client1ResponseLease; Smb2CreateResponseLeaseV2 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"); BaseTestSite.Assert.AreNotSame(client1ResponseLease.LeaseKey, Guid.Empty, "LeaseOpen.LeaseKey can not be empty"); BaseTestSite.Assert.IsTrue(client1ResponseLease.LeaseKey != Guid.Empty || client1ResponseLease.ParentLeaseKey != Guid.Empty, "Both LeaseOpen.LeaseKey and LeaseOpen.ParentLeaseKey can not be empty"); BaseTestSite.Assert.IsTrue(client2ResponseLease.LeaseKey != Guid.Empty || client2ResponseLease.ParentLeaseKey != Guid.Empty, "Both OperationOpen.LeaseKey and OperationOpen.ParentLeaseKey can not be empty"); BaseTestSite.Assert.IsTrue(client1ResponseLease.LeaseKey != Guid.Empty, "LeaseOpen.LeaseKey can not be empty"); #endregion }
private void InitializeClientsConnections(Smb2CreateRequestLeaseV2 client1RequestLease, Smb2CreateRequestLeaseV2 client2RequestLease, out Smb2CreateResponseLeaseV2 client1ResponseLease, out Smb2CreateResponseLeaseV2 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 Smb2CreateResponseLeaseV2; client2ResponseLease = client2ResponseContext as Smb2CreateResponseLeaseV2; }
public void BVT_Leasing_FileLeasingV2() { #region Check Applicability TestConfig.CheckDialect(DialectRevision.Smb30); TestConfig.CheckCapabilities(NEGOTIATE_Response_Capabilities_Values.GLOBAL_CAP_LEASING); TestConfig.CheckCreateContext(CreateContextTypeValue.SMB2_CREATE_REQUEST_LEASE_V2); #endregion Smb2CreateContextRequest leaseContext = new Smb2CreateRequestLeaseV2 { LeaseKey = Guid.NewGuid(), LeaseState = LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_WRITE_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING }; TestFileLeasing(leaseContext); }
public void Compare_Zero_LeaseFlag_ParentLeaseKey() { CheckLeaseApplicability(); Smb2CreateRequestLeaseV2 leaseRequest = createLeaseV2RequestContext(leaseFlag: LeaseFlagsValues.NONE); Smb2CreateResponseLeaseV2 client1ResponseLease; Smb2CreateResponseLeaseV2 client2ResponseLease; InitializeClientsConnections(leaseRequest, leaseRequest, out client1ResponseLease, out client2ResponseLease); #region Test Cases BaseTestSite.Log.Add(LogEntryKind.TestStep, "Comparing lease keys"); BaseTestSite.Assert.AreNotEqual(leaseRequest.ParentLeaseKey, Guid.Empty, "LeaseRequest.ParentLeaseKey should not be empty"); BaseTestSite.Assert.AreEqual(client1ResponseLease.ParentLeaseKey, Guid.Empty, "LeaseOpen.ParentLeaseKey MUST be empty if LeaseFlag is set to Zero"); #endregion }
public void DirectoryComparing_ParentLeaseKey_ChildLeaseKey() { CheckLeaseApplicability(checkDirectoryTypeSupport: true); Guid leaseKey = Guid.NewGuid(); Smb2CreateRequestLeaseV2 client1RequestLease = createLeaseV2RequestContext(leaseKey, leaseState: LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING); Smb2CreateRequestLeaseV2 client2RequestLease = createLeaseV2RequestContext(parentLeaseKey: leaseKey); Smb2CreateResponseLeaseV2 client1ResponseLease; Smb2CreateResponseLeaseV2 client2ResponseLease; InitializeClientsConnections(client1RequestLease, client2RequestLease, out client1ResponseLease, out client2ResponseLease, isClient1ParentDirectory: true); #region Test Cases BaseTestSite.Log.Add(LogEntryKind.TestStep, "Comparing lease keys"); BaseTestSite.Assert.IsTrue(client2ResponseLease.ParentLeaseKey != Guid.Empty, "OperationOpen.ParentLeaseKey CANNOT be empty when SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET Flags is set"); BaseTestSite.Assert.AreEqual(client1ResponseLease.LeaseKey, client2ResponseLease.ParentLeaseKey, "LeaseOpen.LeaseKey MUST be equal to OperationOpen.ParentLeasekey"); #endregion }
public void DirectoryComparing_Child_Invalid_ParentLeaseKeys() { CheckLeaseApplicability(checkDirectoryTypeSupport: true); Guid leaseKey = Guid.NewGuid(); Smb2CreateRequestLeaseV2 client1RequestLease = createLeaseV2RequestContext(leaseKey, leaseState: LeaseStateValues.SMB2_LEASE_READ_CACHING | LeaseStateValues.SMB2_LEASE_HANDLE_CACHING); Smb2CreateRequestLeaseV2 client2RequestLease = createLeaseV2RequestContext(); client2RequestLease.ParentLeaseKey = new Guid(); // Invalid Key Smb2CreateResponseLeaseV2 client1ResponseLease; Smb2CreateResponseLeaseV2 client2ResponseLease; InitializeClientsConnections(client1RequestLease, client2RequestLease, out client1ResponseLease, out client2ResponseLease, isClient1ParentDirectory: true, expectServerBreakNotification: true); #region Test Cases BaseTestSite.Log.Add(LogEntryKind.TestStep, "Comparing lease keys"); BaseTestSite.Assert.AreEqual(client2RequestLease.ParentLeaseKey, Guid.Empty, "request.ParentLeaseKey should be empty"); BaseTestSite.Assert.AreEqual(client2ResponseLease.ParentLeaseKey, Guid.Empty, "open.ParentLeaseKey should be empty"); #endregion }
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 }
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 }