-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathFSAAdapter.cs
More file actions
6117 lines (5259 loc) · 265 KB
/
FSAAdapter.cs
File metadata and controls
6117 lines (5259 loc) · 265 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Protocols.TestSuites.FileSharing.Common.Adapter;
using Microsoft.Protocols.TestTools;
using Microsoft.Protocols.TestTools.StackSdk;
using Microsoft.Protocols.TestTools.StackSdk.Dtyp;
using Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Cifs;
using Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Fscc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using Smb2 = Microsoft.Protocols.TestTools.StackSdk.FileAccessService.Smb2;
namespace Microsoft.Protocols.TestSuites.FileSharing.FSA.Adapter
{
/// <summary>
/// A base class that implements ManagedAdapterBase and IFSAAdapter
/// </summary>
/// Disable warning CA1506 because it will affect the implementation of Adapter and Model codes if do any changes about maintainability.
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
public partial class FSAAdapter : ManagedAdapterBase, IFSAAdapter
{
# region Define fields
private FSATestConfig testConfig;
private bool isWindows;
private bool isIntegritySupported;
private bool isQuotaSupported;
private bool isReparsePointSupported;
private bool isObjectIDsSupported;
private bool isOffloadImplemented;
private bool isEncryptionSupported;
private bool isCompressionSupported;
private bool isExtendedAttributeSupported;
private bool isSparseFileSupported;
private bool isQueryAllocatedRangesSupported;
private bool isSetZeroDataSupported;
private bool isFileLinkInfoSupported;
private bool isShortNameSupported;
private bool isQueryFileFsControlInformationSupported;
private bool isQueryFileFsObjectIdInformationSupported;
private bool isQueryFileObjectIdInformationSupported;
private bool isQueryFileReparsePointInformationSupported;
private bool isQueryFileQuotaInformationSupported;
private bool isObjectIdIoCtlRequestSupported;
private bool isOpenHasManageVolumeAccessSupported;
private bool isStreamRenameSupported;
private bool isMarkHandleSupported;
private bool isRedundantMedia;
private bool isStreamSnapshotManagementImplemented;
private bool isAlternateDataStreamSupported;
private bool isSingleInstanceStorageSupported;
private bool isObjectSecurityBasedOnAccessControlListsSupported;
private bool isHardLinksSupported;
private bool isStrictAllocationSizesRequired;
private bool isTimestampMinusTwoSupported;
private bool isErrorCodeMappingRequired;
private bool isVolumeReadonly;
private uint clusterSizeInKB;
private uint systemPageSizeInKB;
private long gLockOffset;
private long gLockLength;
private bool gLockIsExclusive;
private bool gLockIsConflicted;
private string fileName;
private string shareName;
private Transport transport;
private FileSystem fileSystem;
private uint reFSVersion;
private IpVersion ipVersion;
private ITestSite site;
private ITransportAdapter transAdapter;
public uint transBufferSize; // Make it accessible from test cases' code.
private string rootDirectory;
private string quotaFile;
private string reparsePointFile;
private CreateOptions gOpenMode;
private FileAccess gOpenGrantedAccess;
private StreamType gStreamType;
private List<string> activeTDIs;
private uint numberOfDataCopies;
public bool Is64bitFileIdSupported;
public bool IsChangeTimeSupported;
// Used to generate random file names.
private static Random randomRange = new Random();
// Used to clean up the generated test files.
protected ISutProtocolControlAdapter sutProtocolController;
protected List<string> testFiles = new List<string>();
protected List<string> testDirectories = new List<string>();
# endregion
#region Properties
public FSATestConfig TestConfig
{
get { return testConfig; }
}
public string FileName
{
get { return fileName; }
}
public FileSystem FileSystem
{
get { return fileSystem; }
}
public Platform Platform
{
get { return this.testConfig.Platform; }
}
public uint ReFSVersion
{
get { return reFSVersion; }
}
public bool IsIntegritySupported
{
get { return isIntegritySupported; }
}
public bool IsOffloadImplemented
{
get { return isOffloadImplemented; }
}
public bool IsObjectIDsSupported
{
get { return isObjectIDsSupported; }
}
public bool IsEncryptionSupported
{
get { return isEncryptionSupported; }
}
public bool IsCompressionSupported
{
get { return isCompressionSupported; }
}
public bool IsExtendedAttributeSupported
{
get { return isExtendedAttributeSupported; }
}
public bool IsSparseFileSupported
{
get { return isSparseFileSupported; }
}
public bool IsQueryAllocatedRangesSupported
{
get { return isQueryAllocatedRangesSupported; }
}
public bool IsReparsePointSupported
{
get { return isReparsePointSupported; }
}
public bool IsSetZeroDataSupported
{
get { return isSetZeroDataSupported; }
}
public bool IsQuotaSupported
{
get { return isQuotaSupported; }
}
public bool IsFileLinkInfoSupported
{
get { return isFileLinkInfoSupported; }
}
public bool IsShortNameSupported
{
get { return isShortNameSupported; }
}
public bool IsStreamSnapshotManagementImplemented
{
get { return isStreamSnapshotManagementImplemented; }
}
public bool IsHardLinksSupported
{
get { return isHardLinksSupported; }
}
public uint ClusterSizeInKB
{
get { return clusterSizeInKB; }
}
public uint SystemPageSizeInKB
{
get { return systemPageSizeInKB; }
}
public bool IsVolumeReadonly
{
get { return isVolumeReadonly; }
}
public Transport Transport
{
get { return transport; }
}
public List<string> ActiveTDIs
{
get { return activeTDIs; }
}
public string RootDirectory
{
get { return rootDirectory; }
}
public string QuotaFile
{
get { return quotaFile; }
}
public string ReparsePointFile
{
get { return reparsePointFile; }
}
public string ShareName
{
get { return shareName; }
set
{
shareName = value;
transAdapter.ShareName = value;
}
}
public bool IsMarkHandleSupported
{
get { return isMarkHandleSupported; }
}
public bool IsRedundantMedia
{
get { return isRedundantMedia; }
}
public uint NumberOfDataCopies
{
get { return numberOfDataCopies; }
}
public bool IsAlternateDataStreamSupported
{
get { return isAlternateDataStreamSupported; }
}
public bool IsStrictAllocationSizeRequired
{
get { return isStrictAllocationSizesRequired; }
}
public bool IsTimestampMinusTwoSupported
{
get { return isTimestampMinusTwoSupported; }
}
public string UncSharePath
{
get
{
return "\\\\" + testConfig.SutComputerName + "\\" + this.shareName;
}
}
protected string CurrentTestCaseName
{
get
{
string fullName = (string)Site.TestProperties["CurrentTestCaseName"];
return fullName.Split('.').LastOrDefault();
}
}
#endregion
#region Initialize
/// <summary>
/// Initialize method, will be called automatically by PTF before all cases executed.
/// </summary>
/// <param name="testSite">ITestSite object which can get PTF settings.</param>
public override void Initialize(ITestSite testSite)
{
//Test Site Configuration
testSite = ReqConfigurableSite.GetReqConfigurableSite(testSite);
base.Initialize(testSite);
this.site = base.Site;
Site.DefaultProtocolDocShortName = "MS-FSA";
this.testConfig = new FSATestConfig(this.site);
//SUT Configuration
this.isWindows = testConfig.Platform == Common.Adapter.Platform.NonWindows ? false : true;
this.ipVersion = testConfig.SutIPAddress.AddressFamily == AddressFamily.InterNetworkV6 ? IpVersion.Ipv6 : IpVersion.Ipv4;
//Transport Configuration
Smb2.DialectRevision[] negotiateDialects = Smb2.Smb2Utility.GetDialects(testConfig.MaxSmbVersionSupported);
this.transport = (Transport)Enum.Parse(typeof(Transport), testConfig.GetProperty("Transport"));
#region Select transAdapter according to transport
switch (this.transport)
{
case Transport.SMB:
this.transAdapter = new SmbTransportAdapter(testConfig);
break;
case Transport.SMB2:
this.transAdapter = new Smb2TransportAdapter(new Smb2.DialectRevision[] { Smb2.DialectRevision.Smb2002, Smb2.DialectRevision.Smb21 }, testConfig);
break;
case Transport.SMB3:
this.transAdapter = new Smb2TransportAdapter(negotiateDialects, testConfig);
break;
default:
throw new Exception("Only support SMB, SMB2 and SMB3 transport.");
}
this.transAdapter.Initialize(this.site);
#endregion
// Signing Configuration
this.transAdapter.IsSendSignedRequest = testConfig.SendSignedRequest;
//File System Under Test
this.fileSystem = (FileSystem)Enum.Parse(typeof(FileSystem), testConfig.GetProperty("FileSystem"));
this.reFSVersion = uint.Parse(testConfig.GetProperty("ReFSVersion"));
this.shareName = testConfig.GetProperty((fileSystem.ToString() + "_ShareFolder"));
this.rootDirectory = testConfig.GetProperty((fileSystem.ToString() + "_RootDirectory"));
this.quotaFile = testConfig.GetProperty("QuotaFile");
this.reparsePointFile = testConfig.GetProperty("ReparsePointFile");
//Supported features for the file system
this.isIntegritySupported = testConfig.GetProperty("WhichFileSystemSupport_Integrity").Contains(this.fileSystem.ToString());
this.isQuotaSupported = testConfig.GetProperty("WhichFileSystemSupport_Quota").Contains(this.fileSystem.ToString());
this.isReparsePointSupported = testConfig.GetProperty("WhichFileSystemSupport_ReparsePoint").Contains(this.fileSystem.ToString());
this.isObjectIDsSupported = testConfig.GetProperty("WhichFileSystemSupport_ObjectID").Contains(this.fileSystem.ToString());
this.isOffloadImplemented = testConfig.GetProperty("WhichFileSystemSupport_Offload").Contains(this.fileSystem.ToString());
this.isCompressionSupported = testConfig.GetProperty("WhichFileSystemSupport_Compression").Contains(this.fileSystem.ToString());
this.isEncryptionSupported = testConfig.GetProperty("WhichFileSystemSupport_Encryption").Contains(this.fileSystem.ToString());
this.isExtendedAttributeSupported = testConfig.GetProperty("WhichFileSystemSupport_ExtendedAttribute").Contains(this.fileSystem.ToString());
this.isSparseFileSupported = testConfig.GetProperty("WhichFileSystemSupport_SparseFile").Contains(this.fileSystem.ToString());
this.isQueryAllocatedRangesSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryAllocatedRanges").Contains(this.fileSystem.ToString());
this.isSetZeroDataSupported = testConfig.GetProperty("WhichFileSystemSupport_SetZeroData").Contains(this.fileSystem.ToString());
this.isFileLinkInfoSupported = testConfig.GetProperty("WhichFileSystemSupport_FileLinkInfo").Contains(this.fileSystem.ToString());
this.isShortNameSupported = testConfig.GetProperty("WhichFileSystemSupport_ShortName").Contains(this.fileSystem.ToString());
this.isQueryFileFsControlInformationSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryFileFsControlInformation").Contains(this.fileSystem.ToString());
this.isQueryFileFsObjectIdInformationSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryFileFsObjectIdInformation").Contains(this.fileSystem.ToString());
this.isQueryFileObjectIdInformationSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryFileObjectIdInformation").Contains(this.fileSystem.ToString());
this.isQueryFileReparsePointInformationSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryFileReparsePointInformation").Contains(this.fileSystem.ToString());
this.isQueryFileQuotaInformationSupported = testConfig.GetProperty("WhichFileSystemSupport_QueryFileQuotaInformation").Contains(this.fileSystem.ToString());
this.isObjectIdIoCtlRequestSupported = testConfig.GetProperty("WhichFileSystemSupport_ObjectIdIoCtlRequest").Contains(this.fileSystem.ToString());
this.isOpenHasManageVolumeAccessSupported = testConfig.GetProperty("WhichFileSystemSupport_OpenHasManageVolumeAccess").Contains(this.fileSystem.ToString());
this.isStreamRenameSupported = testConfig.GetProperty("WhichFileSystemSupport_StreamRename").Contains(this.fileSystem.ToString());
this.isMarkHandleSupported = testConfig.GetProperty("WhichFileSystemSupport_MarkHandle").Contains(this.fileSystem.ToString());
this.isRedundantMedia = testConfig.GetProperty("WhichFileSystemSupport_RedundantStorage").Contains(this.fileSystem.ToString());
this.isStreamSnapshotManagementImplemented = testConfig.GetProperty("WhichFileSystemSupport_StreamSnapshotManagement").Contains(this.fileSystem.ToString());
this.isAlternateDataStreamSupported = testConfig.GetProperty("WhichFileSystemSupport_AlternateDataStream").Contains(this.fileSystem.ToString());
this.isSingleInstanceStorageSupported = testConfig.GetProperty("WhichFileSystemSupport_SingleInstanceStorage", false).Contains(this.FileSystem.ToString());
this.isObjectSecurityBasedOnAccessControlListsSupported = testConfig.GetProperty("WhichFileSystemSupport_ObjectSecurityBasedOnAccessControlLists").Contains(this.FileSystem.ToString());
this.isStrictAllocationSizesRequired = testConfig.GetProperty("WhichFileSystemSupport_StrictAllocationSizes").Contains(this.FileSystem.ToString());
this.isTimestampMinusTwoSupported = testConfig.GetProperty("WhichFileSystemSupport_Timestamp_MinusTwo").Contains(this.FileSystem.ToString());
//Volume Properties
this.clusterSizeInKB = uint.Parse(testConfig.GetProperty((fileSystem.ToString() + "_ClusterSizeInKB")));
this.systemPageSizeInKB = uint.Parse(testConfig.GetProperty("SystemPageSizeInKB"));
this.isVolumeReadonly = bool.Parse(testConfig.GetProperty("IsVolumeReadonly"));
this.isHardLinksSupported = bool.Parse(testConfig.GetProperty("IsHardLinksSupported"));
//Error Code Handling
this.isErrorCodeMappingRequired = bool.Parse(testConfig.GetProperty("IsErrorCodeMappingRequired"));
//TDI Configurations
this.activeTDIs = new List<string>(testConfig.GetProperty("FsaActiveTDIs").Split(';'));
//Other Configurations
this.transBufferSize = uint.Parse(testConfig.GetProperty("BufferSize"));
this.Is64bitFileIdSupported = bool.Parse(testConfig.GetProperty("Is64bitFileIdSupported"));
this.IsChangeTimeSupported = bool.Parse(testConfig.GetProperty("IsChangeTimeSupported"));
this.numberOfDataCopies = uint.Parse(testConfig.GetProperty("NumberOfDataCopies"));
TestTools.StackSdk.Security.KerberosLib.KerberosContext.KDCComputerName = testConfig.DCServerName;
TestTools.StackSdk.Security.KerberosLib.KerberosContext.KDCPort = testConfig.KDCPort;
sutProtocolController = Site.GetAdapter<ISutProtocolControlAdapter>();
this.Reset();
}
/// <summary>
/// Reset, will be called automatically after a case executed.
/// </summary>
public override void Reset()
{
base.Reset();
//Since the transport's reset function cannot be called by SE, we call it manually
this.transAdapter.BufferSize = this.transBufferSize;
this.transAdapter.Domain = testConfig.DomainName;
this.transAdapter.IPVersion = this.ipVersion;
this.transAdapter.Password = testConfig.UserPassword;
this.transAdapter.Port = testConfig.TransportPort;
this.transAdapter.ServerName = testConfig.SutComputerName;
this.transAdapter.ShareName = this.shareName;
this.transAdapter.UserName = testConfig.UserName;
this.transAdapter.Timeout = testConfig.Timeout;
this.transAdapter.Reset();
CleanTestFiles();
}
/// <summary>
/// Dispose
/// </summary>
/// <param name="disposing">Boolean value indicating whether dispose.</param>
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (this.transAdapter != null)
{
transAdapter.Dispose();
this.transAdapter = null;
}
CleanTestFiles();
}
protected void CleanTestFiles()
{
foreach (var fileName in testFiles)
{
try
{
// Remove the appendix. e.g. "::$DATA", ":$I30"
int i = fileName.IndexOf(":");
string temp = fileName;
if (i != -1)
{
temp = fileName.Substring(0, i);
}
sutProtocolController.DeleteFile("\\\\" + testConfig.SutComputerName + "\\" + this.shareName, temp);
}
catch
{
}
}
testFiles.Clear();
foreach (var directory in testDirectories)
{
try
{
int i = directory.IndexOf(":");
string temp = directory;
if (i != -1)
{
temp = directory.Substring(0, i);
}
sutProtocolController.DeleteDirectory("\\\\" + testConfig.SutComputerName + "\\" + this.shareName, temp);
}
catch
{
}
}
testDirectories.Clear();
}
protected void AddTestFileName(CreateOptions createOptions, string fileName)
{
if (createOptions.HasFlag(CreateOptions.DIRECTORY_FILE))
{
testDirectories.Add(fileName);
}
else
{
testFiles.Add(fileName);
}
}
/// <summary>
/// FSA initialize, it contains the follow operations:
/// 1. The client connects to server.
/// 2. The client sets up a session with server.
/// 3. The client connects to a share on server.
/// </summary>
public void FsaInitial()
{
ExecuteFSAEarlyChecks();
this.transAdapter.Initialize(this.isWindows);
}
private void ExecuteFSAEarlyChecks()
{
CheckGlobalEncryptDataCompatibility();
CheckSISRelatedTest();
CheckShortNameRelatedTest();
CheckExtendedAttributeRelatedTest();
CheckFileLinkInfoRelatedTest();
CheckStreamRenameRelatedTest();
CheckSecurityInfoRelatedTest();
CheckIncompatibleTestOverQUIC();
}
private void CheckGlobalEncryptDataCompatibility()
{
if (testConfig.IsGlobalEncryptDataEnabled)
{
if (testConfig.IsGlobalRejectUnencryptedAccessEnabled && TestConfig.MaxSmbVersionClientSupported < Smb2.DialectRevision.Smb30)
{
Site.Assert.Inconclusive("When IsGlobalRejectUnencryptedAccessEnabled is true, it won't allow unencrypted accesses from clients that do not support SMB 3.0 and above.");
}
}
}
private static readonly HashSet<string> sisRelatedTestNames = new HashSet<string>
{
"IoCtlRequestTestCaseS128",
"IoCtlRequestTestCaseS130",
"IoCtlRequestTestCaseS132",
"IoCtlRequestTestCaseS134",
"IoCtlRequestTestCaseS136",
"IoCtlRequestTestCaseS138",
"IoCtlRequestTestCaseS140"
};
private void CheckSISRelatedTest()
{
if (!this.isSingleInstanceStorageSupported && sisRelatedTestNames.Contains(CurrentTestCaseName))
{
Site.Assert.Inconclusive("Single Instance Storage is an optional feature available in the following versions of Windows Server: Windows Storage Server 2003 R2 operating system, Standard Edition, Windows Storage Server 2008, and Windows Storage Server 2008 R2.\n" +
"Single Instance Storage is not supported directly by any of the Windows file systems but is implemented as a file system filter.");
}
}
private static readonly HashSet<string> shortNameRelatedTestNames = new HashSet<string>
{
"QueryFileInformationTestCaseS68",
"SetFileShortNameInformationTestCaseS0",
"SetFileShortNameInformationTestCaseS2",
"SetFileShortNameInformationTestCaseS4",
"SetFileShortNameInformationTestCaseS6",
"SetFileShortNameInformationTestCaseS8"
};
private void CheckShortNameRelatedTest()
{
if (!this.isShortNameSupported && shortNameRelatedTestNames.Contains(CurrentTestCaseName))
{
Site.Assert.Inconclusive($"Short name is not supported on {this.fileSystem}.");
}
}
private void CheckExtendedAttributeRelatedTest()
{
if (!this.isExtendedAttributeSupported && CurrentTestCaseName.StartsWith("SetFileFullEaInformationTestCase"))
{
Site.Assert.Inconclusive($"Extended attribute is not supported on {this.fileSystem}.");
}
}
private void CheckFileLinkInfoRelatedTest()
{
if (!this.isFileLinkInfoSupported && CurrentTestCaseName.StartsWith("SetFileLinkInformationTestCase"))
{
Site.Assert.Inconclusive($"Hard link to a file is not supported on {this.fileSystem}.");
}
}
private void CheckStreamRenameRelatedTest()
{
if (!(this.isAlternateDataStreamSupported && this.isStreamRenameSupported) && CurrentTestCaseName.StartsWith("SetFileStreamRenameInformationTestCase"))
{
Site.Assert.Inconclusive($"Alternate data stream and stream rename are not supported on {this.fileSystem}.");
}
}
private void CheckSecurityInfoRelatedTest()
{
if (!this.isObjectSecurityBasedOnAccessControlListsSupported && CurrentTestCaseName.StartsWith("SetSecurityInformationTestCase"))
{
Site.Assert.Inconclusive($"Object security based on Access Control Lists is not supported on {this.fileSystem}.");
}
}
private static readonly HashSet<string> quicIncompatibleTestNames = new HashSet<string>
{
"IoCtlRequestTestCaseS56",
"IoCtlRequestTestCaseS64",
"IoCtlRequestTestCaseS62",
"IoCtlRequestTestCaseS58",
"IoCtlRequestTestCaseS66",
"IoCtlRequestTestCaseS68",
"IoCtlRequestTestCaseS70",
"IoCtlRequestTestCaseS74",
"IoCtlRequestTestCaseS60",
"IoCtlRequestTestCaseS72",
"IoCtlRequestTestCaseS54",
"IoCtlRequestTestCaseS48",
"IoCtlRequestTestCaseS50"
};
private void CheckIncompatibleTestOverQUIC()
{
if (testConfig.UnderlyingTransport == Smb2.Smb2TransportType.Quic && quicIncompatibleTestNames.Contains(CurrentTestCaseName))
{
Site.Assert.Inconclusive("Ignoring test {0} over QUIC", CurrentTestCaseName);
}
}
#endregion
#region 3.1.5 Higher-Layer Triggered Events
#region 3.1.5.1 Server Requests an Open of a File
#region 3.1.5.1.1 Creation of a New File
/// <summary>
/// Implement CreateFile method
/// </summary>
/// <param name="desiredFileAttribute">Desired file attribute</param>
/// <param name="createOption">Specifies the options to be applied when creating or opening the file</param>
/// <param name="streamTypeNameToOpen">The name of stream type to open</param>
/// <param name="desiredAccess">A bitmask indicating desired access for the open, as specified in [MS-SMB2] section 2.2.13.1.</param>
/// <param name="shareAccess">A bitmask indicating sharing access for the open, as specified in [MS-SMB2] section 2.2.13.</param>
/// <param name="createDisposition">The desired disposition for the open, as specified in [MS-SMB2] section 2.2.13.</param>
/// <param name="streamFoundType">Indicate if the stream is found or not.</param>
/// <param name="symbolicLinkType">Indicate if it is symbolic link or not.</param>
/// <param name="openFileType">Filetype of open file</param>
/// <param name="fileNameStatus">File name status</param>
/// <returns>An NTSTATUS code that specifies the result.</returns>
/// Disable warning CA1502 because it will affect the implementation of Adapter and Model codes if do any changes about maintainability.
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
public MessageStatus CreateFile(
FileAttribute desiredFileAttribute,
CreateOptions createOption,
StreamTypeNameToOpen streamTypeNameToOpen,
FileAccess desiredAccess,
ShareAccess shareAccess,
CreateDisposition createDisposition,
StreamFoundType streamFoundType,
SymbolicLinkType symbolicLinkType,
FileType openFileType,
FileNameStatus fileNameStatus
)
{
gOpenMode = createOption;
gStreamType = (streamTypeNameToOpen == StreamTypeNameToOpen.INDEX_ALLOCATION ? StreamType.DirectoryStream : StreamType.DataStream);
uint createAction = 0;
string randomFile = this.ComposeRandomFileName();
this.fileName = randomFile;
if (fileNameStatus == FileNameStatus.NotPathNameValid)
{
// The loop time is 32
for (int i = 0; i < 32; i++)
{
randomFile += testConfig.GetProperty("InvalidName");
}
}
//Get the SymboLinkFile name on the server if SymbolicLink is required.
else if (symbolicLinkType == SymbolicLinkType.IsSymbolicLink)
{
randomFile = testConfig.GetProperty("SymbolicLinkFile");
if (this.FileSystem == FileSystem.FAT32)
{
site.Assume.Inconclusive("Symbolic Link is not supported by FAT32 system.");
}
}
//Retrieve the existing the folder
else if (createDisposition == CreateDisposition.OPEN
&& openFileType == FileType.DirectoryFile)
{
randomFile = testConfig.GetProperty("ExistingFolder");
}
//Retrieve the existing the file
else if (createDisposition == CreateDisposition.OPEN
&& openFileType == FileType.DataFile)
{
randomFile = testConfig.GetProperty("ExistingFile");
}
//Construct a path name with trailing backslash.
else if ((fileNameStatus == FileNameStatus.BackslashName) &&
(createOption & CreateOptions.NON_DIRECTORY_FILE) != 0)
{
if (this.isAlternateDataStreamSupported)
{
randomFile = randomFile + @"\\\\\\" + "::$DATA";
}
else
{
// For file systems other than NTFS or ReFS, the constructed path name with trailing backslash should not contain "::$DATA"
randomFile = randomFile + @"\\\\\\";
}
}
//Construct a data file for an directory operation to
//trigger the error code OBJECT_NAME_COLLISION
//for creating operation and NOT_A_DIRECTORY for openning operation.
else if ((createOption == CreateOptions.DIRECTORY_FILE) &&
(fileNameStatus == FileNameStatus.OpenFileNotNull) &&
(openFileType != FileType.DirectoryFile))
{
if (createDisposition == CreateDisposition.CREATE)
{
randomFile = testConfig.GetProperty("ExistingFile");
randomFile = randomFile + "::$INDEX_ALLOCATION";
}
else if (createDisposition == CreateDisposition.OPEN)
{
randomFile = testConfig.GetProperty("ExistingFile");
randomFile = randomFile + "::$DATA";
}
}
//Construct a directory file for an data file operation to
//trigger the error code FILE_IS_A_DIRECTORY.
else if ((createOption == CreateOptions.NON_DIRECTORY_FILE) &&
(streamTypeNameToOpen == StreamTypeNameToOpen.NULL) &&
(fileNameStatus != FileNameStatus.FileNameNull) && (openFileType == FileType.DirectoryFile))
{
randomFile = testConfig.GetProperty("ExistingFolder");
}
//Constuct message with CreateOptions.RANDOM_ACCESS and use file name to
//indicate the file type.
else if (createDisposition == CreateDisposition.CREATE
&& (createOption & CreateOptions.RANDOM_ACCESS) != 0)
{
if (streamTypeNameToOpen == StreamTypeNameToOpen.DATA)
{
randomFile = randomFile + "::$DATA";
}
else if (streamTypeNameToOpen == StreamTypeNameToOpen.INDEX_ALLOCATION)
{
randomFile = randomFile + "::$INDEX_ALLOCATION";
}
}
//Construct the Non-Existfile to trigger the message OBJECT_NAME_NOT_FOUND
if (createDisposition == CreateDisposition.OPEN && streamFoundType == StreamFoundType.StreamIsNotFound)
{
randomFile = Guid.NewGuid().ToString();
}
//Construct the Non-Exist folder to trigger the error code OBJECT_PATH_NOT_FOUND
if (createDisposition == CreateDisposition.OPEN && fileNameStatus == FileNameStatus.IsPrefixLinkNotFound)
{
randomFile = Guid.NewGuid().ToString();
}
if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION)
{
// Full name of a stream is <filename>:<stream name>:<stream type>
// If any StreamTypeNamei is "$INDEX_ALLOCATION"
// and the corresponding StreamNamei has a value other than an empty string or "$I30",
// the operation SHOULD be failed with STATUS_INVALID_PARAMETER.
//
// Set <stream name> as a random string (not an empty string or $I30) to test above requirement.
string fileName = this.ComposeRandomFileName();
string streamName = this.ComposeRandomFileName();
randomFile = fileName + ":" + streamName + ":$INDEX_ALLOCATION";
}
//Construct path name with streamTypeNameToOpen
if (streamTypeNameToOpen != StreamTypeNameToOpen.NULL &&
symbolicLinkType != SymbolicLinkType.IsSymbolicLink)
{
if (streamTypeNameToOpen == StreamTypeNameToOpen.DATA
&& !randomFile.Contains("$DATA"))
{
randomFile = randomFile + "::$DATA";
}
else if (streamTypeNameToOpen == StreamTypeNameToOpen.INDEX_ALLOCATION
&& !randomFile.Contains("$INDEX_ALLOCATION"))
{
if ((desiredFileAttribute & FileAttribute.READONLY) == FileAttribute.READONLY &&
(createOption & CreateOptions.DELETE_ON_CLOSE) == CreateOptions.DELETE_ON_CLOSE &&
(fileSystem != Adapter.FileSystem.NTFS && fileSystem != Adapter.FileSystem.REFS))
{
/*
* To cover the below requirements in a file system other than NTFS and ReFS, remove complex suffix:
* Section 2.1.5.1.1 Create a New File
* If DesiredFileAttributes.FILE_ATTRIBUTE_READONLY and CreateOptions.FILE_DELETE_ON_CLOSE are both set,
* the operation MUST be failed with STATUS_CANNOT_DELETE.
* =>
* If "::$INDEX_ALLOCATION" is added to the file name, it will return unexpected error codes in FAT32 that
* does not recognize the "::$INDEX_ALLOCATION" complex suffix.
*/
}
else
{
randomFile = randomFile + "::$INDEX_ALLOCATION";
}
}
else if (streamTypeNameToOpen == StreamTypeNameToOpen.Other
&& !randomFile.Contains("$TEST"))
{
randomFile = randomFile + "::$TEST";
}
}
if (desiredFileAttribute == FileAttribute.REPARSE_POINT && createOption == CreateOptions.OPEN_REPARSE_POINT)
{
randomFile = testConfig.GetProperty("ReparsePointFile");
}
MessageStatus returnedStatus = transAdapter.CreateFile(
randomFile,
(uint)desiredFileAttribute,
(uint)desiredAccess,
(uint)shareAccess,
(uint)createOption,
(uint)createDisposition,
out createAction);
gOpenGrantedAccess = returnedStatus == MessageStatus.SUCCESS ? desiredAccess : FileAccess.None;
site.Log.Add(LogEntryKind.Debug, $"CreateFile returned {returnedStatus} for creating file {randomFile}");
/*
* Work around for test cases only designed for NTFS and ReFS:
* Make assertion in the adapter, then convert the return code according to the test case.
*/
if (!this.isAlternateDataStreamSupported)
{
if ((createOption & CreateOptions.DIRECTORY_FILE) == CreateOptions.DIRECTORY_FILE &&
(createOption & CreateOptions.NON_DIRECTORY_FILE) == CreateOptions.NON_DIRECTORY_FILE)
{
/*
* To cover the below requirements in a file system other than NTFS and ReFS, remove complex suffix:
* Section 2.1.5.1
* Phase 1 - Parameter Validation
* If CreateOptions.FILE_DIRECTORY_FILE && CreateOptions.FILE_NON_DIRECTORY_FILE,
* the operation MUST be failed with STATUS_INVALID_PARAMETER.
* =>
* Return the status immediately.
*
* Test Cases:
* CreateFileTestCaseS12
*/
return returnedStatus;
}
else if (openFileType == FileType.DataFile && symbolicLinkType == SymbolicLinkType.IsSymbolicLink)
{
/*
* To cover the below requirements in a file system other than NTFS and ReFS that does not support Symbolic Link:
* Section 2.1.5.1
* Phase 6 -- Location of file:
* If Link.File.IsSymbolicLink is TRUE, the operation MUST be failed with Status set to STATUS_STOPPED_ON_SYMLINK
* and ReparsePointData set to Link.File.ReparsePointData.
* Section 2.1.5.1.2
* Else if FileTypeToOpen is DataFile:
* If CreateDisposition is FILE_CREATE, then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.
* =>
* In NTFS and ReFS, these cases are expecting STATUS_STOPPED_ON_SYMLINK, while in other file system that does
* not support symbolic link will consider this action as creating a file that is already existed. The return
* will be STATUS_OBJECT_NAME_COLLISION instead.
*
* Test Cases:
* CreateFileTestCaseS42
*/
site.Log.Add(LogEntryKind.Checkpoint, @"Section 2.1.5.1.2
Else if FileTypeToOpen is DataFile:
If CreateDisposition is FILE_CREATE, then the operation MUST be failed with STATUS_OBJECT_NAME_COLLISION.");
site.Assert.AreEqual<MessageStatus>(MessageStatus.OBJECT_NAME_COLLISION, returnedStatus, "return of CreateFile");
// Make a fake return
return MessageStatus.STOPPED_ON_SYMLINK;
}
else if (randomFile.Contains("$STANDARD_INFORMATION")
|| randomFile.Contains("$ATTRIBUTE_LIST")
|| randomFile.Contains("$FILE_NAME")
|| randomFile.Contains("$OBJECT_ID")
|| randomFile.Contains("$SECURITY_DESCRIPTOR")
|| randomFile.Contains("$VOLUME_NAME")
|| randomFile.Contains("$VOLUME_INFORMATION")
|| randomFile.Contains("$DATA")
|| randomFile.Contains("$INDEX_ROOT")
|| randomFile.Contains("$INDEX_ALLOCATION")
|| randomFile.Contains("$BITMAP")
|| randomFile.Contains("$REPARSE_POINT")
|| randomFile.Contains("$EA_INFORMATION")
|| randomFile.Contains("$EA")
|| randomFile.Contains("$LOGGED_UTILITY_STREAM"))
{
if (fileNameStatus == FileNameStatus.StreamTypeNameIsINDEX_ALLOCATION)
{
return MessageStatus.INVALID_PARAMETER;
}
else if (createDisposition == CreateDisposition.OPEN
|| createDisposition == CreateDisposition.OVERWRITE
|| createDisposition == CreateDisposition.OPEN_IF)
{
/*
* To cover the below requirements in a file system other than NTFS and ReFS that does not support stream type names:
* Section 2.1.5.1
* Phase 6 -- Location of file:
* If StreamTypeNameToOpen is non-empty and StreamTypeNameToOpen is not equal to one of the stream type names
* recognized by the object store<42> (using case-insensitive string comparisons), the operation MUST be failed
* with STATUS_OBJECT_NAME_INVALID.
*
* Section 5
* <42> Section 2.1.5.1: NTFS and ReFS recognize the following stream type names:
* "$STANDARD_INFORMATION"
* "$ATTRIBUTE_LIST"
* "$FILE_NAME"
* "$OBJECT_ID"
* "$SECURITY_DESCRIPTOR"
* "$VOLUME_NAME"
* "$VOLUME_INFORMATION"
* "$DATA"
* "$INDEX_ROOT"
* "$INDEX_ALLOCATION"
* "$BITMAP"
* "$REPARSE_POINT"
* "$EA_INFORMATION"
* "$EA"
* "$LOGGED_UTILITY_STREAM"
* Other Windows file systems do not recognize any stream type names.
* =>
* In NTFS and ReFS, these cases are expecting STATUS_OBJECT_NAME_NOT_FOUND, while in other file system that does not
* support the the stream type names will return STATUS_OBJECT_NAME_INVALID.
*
* Test Cases:
* CreateFileTestCaseS38
* CreateFileTestCaseS40
* LockAndUnlockTestCaseS2
*/
site.Log.Add(LogEntryKind.Checkpoint, @"Section 2.1.5.1
Phase 6 -- Location of file:
If StreamTypeNameToOpen is non-empty and StreamTypeNameToOpen is not equal to one of the stream type names
recognized by the object store<42> (using case-insensitive string comparisons), the operation MUST be failed
with STATUS_OBJECT_NAME_INVALID.");
site.Assert.AreEqual<MessageStatus>(MessageStatus.OBJECT_NAME_INVALID, returnedStatus, "return of CreateFile");
// Remove the complex name suffixes and try to create the file again.
randomFile = randomFile.Remove(randomFile.IndexOf(":"));
returnedStatus = transAdapter.CreateFile(
randomFile,
(uint)desiredFileAttribute,
(uint)desiredAccess,
(uint)shareAccess,
(uint)createOption,
(uint)createDisposition,
out createAction);
return returnedStatus;
}
}
else if (randomFile.Contains(":$I30")
|| randomFile.Contains("::$INDEX_ALLOCATION")
|| randomFile.Contains(":$I30:$INDEX_ALLOCATION")
|| randomFile.Contains("::$BITMAP")
|| randomFile.Contains(":$I30:$BITMAP")
|| randomFile.Contains("::$ATTRIBUTE_LIST")
|| randomFile.Contains("::$REPARSE_POINT"))
{
/*
* To cover the below requirements in a file system other than NTFS and ReFS that does not complex name suffixes:
* Section 2.1.5.1
* Phase 6 -- Location of file:
* If ComplexNameSuffix is non-empty and ComplexNameSuffix is not equal to one of the complex name suffixes
* recognized by the object store<41> (using case-insensitive string comparisons), the operation MUST be
* failed with STATUS_OBJECT_NAME_INVALID.
*
* Section 5
* <41> Section 2.1.5.1: NTFS and ReFS recognize the following complex name suffixes:
* ":$I30"