|
| 1 | +/* Copyright (C) 2025 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. |
| 2 | + * |
| 3 | + * You can redistribute this program and/or modify it under the terms of |
| 4 | + * the GNU Lesser Public License as published by the Free Software Foundation, |
| 5 | + * either version 3 of the License, or (at your option) any later version. |
| 6 | + */ |
| 7 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 8 | +using SMBLibrary.DFS; |
| 9 | +using System; |
| 10 | +using System.Collections.Generic; |
| 11 | + |
| 12 | +namespace SMBLibrary.Tests.DFS |
| 13 | +{ |
| 14 | + [TestClass] |
| 15 | + public class ResponseGetDfsReferralTests |
| 16 | + { |
| 17 | + [TestMethod] |
| 18 | + public void ParseResponseGetDfsReferralWithSingleDfsReferralEntryV4() |
| 19 | + { |
| 20 | + // Arrange |
| 21 | + // Returned by Windows Server 2008 R2 SP1 |
| 22 | + byte[] buffer = new byte[] |
| 23 | + { |
| 24 | + 0x3e ,0x00 ,0x01 ,0x00 ,0x03 ,0x00 ,0x00 ,0x00 ,0x04 ,0x00 ,0x22 ,0x00 ,0x01 ,0x00 ,0x04 ,0x00, |
| 25 | + 0x2c ,0x01 ,0x00 ,0x00 ,0x22 ,0x00 ,0x62 ,0x00 ,0xa2 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, |
| 26 | + 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x5c ,0x00 ,0x57 ,0x00 ,0x49 ,0x00, |
| 27 | + 0x4e ,0x00 ,0x2d ,0x00 ,0x4d ,0x00 ,0x51 ,0x00 ,0x38 ,0x00 ,0x33 ,0x00 ,0x44 ,0x00 ,0x45 ,0x00, |
| 28 | + 0x35 ,0x00 ,0x4e ,0x00 ,0x47 ,0x00 ,0x37 ,0x00 ,0x32 ,0x00 ,0x5c ,0x00 ,0x44 ,0x00 ,0x66 ,0x00, |
| 29 | + 0x73 ,0x00 ,0x20 ,0x00 ,0x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buffer); |
| 43 | + |
| 44 | + // Assert |
| 45 | + Assert.AreEqual(62, response.PathConsumed); |
| 46 | + Assert.AreEqual(DfsReferralHeaderFlags.ReferalServers | DfsReferralHeaderFlags.StorageServers , response.ReferralHeaderFlags); |
| 47 | + Assert.AreEqual(1, response.ReferralEntries.Count); |
| 48 | + Assert.IsInstanceOfType(response.ReferralEntries[0], typeof(DfsReferralEntryV4)); |
| 49 | + |
| 50 | + DfsReferralEntryV4 entry = (DfsReferralEntryV4)response.ReferralEntries[0]; |
| 51 | + Assert.AreEqual((uint)300, entry.TimeToLive); |
| 52 | + Assert.AreEqual(DfsReferralEntryFlags.TargetSetBoundary, entry.ReferralEntryFlags); |
| 53 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.DfsPath); |
| 54 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.DfsAlternatePath); |
| 55 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.NetworkAddress); |
| 56 | + Assert.AreEqual(Guid.Empty, entry.ServiceSiteGuid); |
| 57 | + } |
| 58 | + |
| 59 | + [TestMethod] |
| 60 | + public void Parse_ResponseGetDfsReferralWithSingleDfsReferralEntryV4_GetBytes() |
| 61 | + { |
| 62 | + // Arrange |
| 63 | + ResponseGetDfsReferral response = new ResponseGetDfsReferral(); |
| 64 | + response.PathConsumed = 62; |
| 65 | + response.ReferralHeaderFlags = DfsReferralHeaderFlags.ReferalServers | DfsReferralHeaderFlags.StorageServers; |
| 66 | + response.ReferralEntries = new List<DfsReferralEntry>() |
| 67 | + { |
| 68 | + new DfsReferralEntryV4() |
| 69 | + { |
| 70 | + TimeToLive = 300, |
| 71 | + ReferralEntryFlags = DfsReferralEntryFlags.TargetSetBoundary, |
| 72 | + DfsPath = "\\WIN-MQ83DE5NG72\\Dfs Namespace1", |
| 73 | + DfsAlternatePath = "\\WIN-MQ83DE5NG72\\Dfs Namespace1", |
| 74 | + NetworkAddress = "\\WIN-MQ83DE5NG72\\Dfs Namespace1", |
| 75 | + ServiceSiteGuid = Guid.Empty |
| 76 | + } |
| 77 | + }; |
| 78 | + |
| 79 | + // Act |
| 80 | + response = new ResponseGetDfsReferral(response.GetBytes()); |
| 81 | + |
| 82 | + // Assert |
| 83 | + Assert.AreEqual(62, response.PathConsumed); |
| 84 | + Assert.AreEqual(DfsReferralHeaderFlags.ReferalServers | DfsReferralHeaderFlags.StorageServers, response.ReferralHeaderFlags); |
| 85 | + Assert.AreEqual(1, response.ReferralEntries.Count); |
| 86 | + Assert.IsInstanceOfType(response.ReferralEntries[0], typeof(DfsReferralEntryV4)); |
| 87 | + |
| 88 | + DfsReferralEntryV4 entry = (DfsReferralEntryV4)response.ReferralEntries[0]; |
| 89 | + Assert.AreEqual((uint)300, entry.TimeToLive); |
| 90 | + Assert.AreEqual(DfsReferralEntryFlags.TargetSetBoundary, entry.ReferralEntryFlags); |
| 91 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.DfsPath); |
| 92 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.DfsAlternatePath); |
| 93 | + Assert.AreEqual("\\WIN-MQ83DE5NG72\\Dfs Namespace1", entry.NetworkAddress); |
| 94 | + Assert.AreEqual(Guid.Empty, entry.ServiceSiteGuid); |
| 95 | + } |
| 96 | + } |
| 97 | +} |
0 commit comments