ruby_smb 3.0.6 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/examples/file_server.rb +8 -1
  4. data/examples/virtual_file_server.rb +143 -0
  5. data/lib/ruby_smb/client/encryption.rb +16 -4
  6. data/lib/ruby_smb/client/negotiation.rb +10 -8
  7. data/lib/ruby_smb/fscc/file_information/file_access_information.rb +15 -0
  8. data/lib/ruby_smb/fscc/file_information/file_alignment_information.rb +45 -0
  9. data/lib/ruby_smb/fscc/file_information/file_all_information.rb +23 -0
  10. data/lib/ruby_smb/fscc/file_information/file_basic_information.rb +20 -0
  11. data/lib/ruby_smb/fscc/file_information/file_both_directory_information.rb +3 -3
  12. data/lib/ruby_smb/fscc/file_information/file_directory_information.rb +3 -3
  13. data/lib/ruby_smb/fscc/file_information/file_ea_information.rb +1 -0
  14. data/lib/ruby_smb/fscc/file_information/file_full_directory_information.rb +3 -3
  15. data/lib/ruby_smb/fscc/file_information/file_id_both_directory_information.rb +3 -3
  16. data/lib/ruby_smb/fscc/file_information/file_id_full_directory_information.rb +3 -3
  17. data/lib/ruby_smb/fscc/file_information/file_internal_information.rb +15 -0
  18. data/lib/ruby_smb/fscc/file_information/file_mode_information.rb +29 -0
  19. data/lib/ruby_smb/fscc/file_information/file_name_information.rb +16 -0
  20. data/lib/ruby_smb/fscc/file_information/file_names_information.rb +1 -1
  21. data/lib/ruby_smb/fscc/file_information/file_normalized_name_information.rb +16 -0
  22. data/lib/ruby_smb/fscc/file_information/file_position_information.rb +15 -0
  23. data/lib/ruby_smb/fscc/file_information/file_rename_information.rb +1 -1
  24. data/lib/ruby_smb/fscc/file_information/file_standard_information.rb +20 -0
  25. data/lib/ruby_smb/fscc/file_information/file_stream_information.rb +3 -0
  26. data/lib/ruby_smb/fscc/file_information.rb +43 -6
  27. data/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information.rb +1 -0
  28. data/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information.rb +1 -0
  29. data/lib/ruby_smb/fscc/file_system_information.rb +4 -0
  30. data/lib/ruby_smb/gss/provider/ntlm.rb +20 -3
  31. data/lib/ruby_smb/gss/provider.rb +10 -1
  32. data/lib/ruby_smb/server/server_client/encryption.rb +66 -0
  33. data/lib/ruby_smb/server/server_client/negotiation.rb +14 -3
  34. data/lib/ruby_smb/server/server_client/session_setup.rb +21 -4
  35. data/lib/ruby_smb/server/server_client/share_io.rb +17 -0
  36. data/lib/ruby_smb/server/server_client/tree_connect.rb +40 -3
  37. data/lib/ruby_smb/server/server_client.rb +156 -38
  38. data/lib/ruby_smb/server/session.rb +5 -1
  39. data/lib/ruby_smb/server/share/provider/disk/file_system.rb +28 -0
  40. data/lib/ruby_smb/server/share/provider/disk/processor/close.rb +46 -0
  41. data/lib/ruby_smb/server/share/provider/disk/processor/create.rb +143 -0
  42. data/lib/ruby_smb/server/share/provider/disk/processor/query.rb +359 -0
  43. data/lib/ruby_smb/server/share/provider/disk/processor/read.rb +70 -0
  44. data/lib/ruby_smb/server/share/provider/disk/processor.rb +223 -0
  45. data/lib/ruby_smb/server/share/provider/disk.rb +12 -418
  46. data/lib/ruby_smb/server/share/provider/pipe.rb +2 -2
  47. data/lib/ruby_smb/server/share/provider/processor.rb +16 -0
  48. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb +85 -0
  49. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.rb +196 -0
  50. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat.rb +175 -0
  51. data/lib/ruby_smb/server/share/provider/virtual_disk.rb +116 -0
  52. data/lib/ruby_smb/server/share/provider.rb +1 -0
  53. data/lib/ruby_smb/server.rb +13 -3
  54. data/lib/ruby_smb/signing.rb +18 -4
  55. data/lib/ruby_smb/smb1/commands.rb +1 -0
  56. data/lib/ruby_smb/smb1/packet/nt_create_andx_request.rb +11 -1
  57. data/lib/ruby_smb/smb1/packet/nt_trans/create_request.rb +1 -1
  58. data/lib/ruby_smb/smb1/packet/read_andx_response.rb +5 -4
  59. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +12 -4
  60. data/lib/ruby_smb/smb1/packet/trans2/data_block.rb +9 -1
  61. data/lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb +52 -51
  62. data/lib/ruby_smb/smb1/packet/trans2/find_first2_response.rb +37 -37
  63. data/lib/ruby_smb/smb1/packet/trans2/find_information_level/find_file_both_directory_info.rb +48 -0
  64. data/lib/ruby_smb/smb1/packet/trans2/find_information_level.rb +28 -15
  65. data/lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb +51 -51
  66. data/lib/ruby_smb/smb1/packet/trans2/find_next2_response.rb +36 -36
  67. data/lib/ruby_smb/smb1/packet/trans2/open2_request.rb +40 -39
  68. data/lib/ruby_smb/smb1/packet/trans2/open2_response.rb +40 -40
  69. data/lib/ruby_smb/smb1/packet/trans2/query_file_information_request.rb +60 -0
  70. data/lib/ruby_smb/smb1/packet/trans2/query_file_information_response.rb +59 -0
  71. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_level/query_fs_attribute_info.rb +31 -0
  72. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_level.rb +40 -0
  73. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_request.rb +46 -0
  74. data/lib/ruby_smb/smb1/packet/trans2/query_fs_information_response.rb +59 -0
  75. data/lib/ruby_smb/smb1/packet/trans2/query_information_level/query_file_basic_info.rb +23 -0
  76. data/lib/ruby_smb/smb1/packet/trans2/query_information_level/query_file_standard_info.rb +22 -0
  77. data/lib/ruby_smb/smb1/packet/trans2/query_information_level.rb +62 -0
  78. data/lib/ruby_smb/smb1/packet/trans2/query_path_information_request.rb +65 -0
  79. data/lib/ruby_smb/smb1/packet/trans2/query_path_information_response.rb +59 -0
  80. data/lib/ruby_smb/smb1/packet/trans2/request.rb +24 -8
  81. data/lib/ruby_smb/smb1/packet/trans2/request_secondary.rb +4 -4
  82. data/lib/ruby_smb/smb1/packet/trans2/response.rb +29 -20
  83. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_request.rb +42 -42
  84. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_response.rb +23 -23
  85. data/lib/ruby_smb/smb1/packet/trans2/subcommands.rb +23 -5
  86. data/lib/ruby_smb/smb1/packet/trans2.rb +4 -0
  87. data/lib/ruby_smb/smb1/packet/tree_connect_request.rb +4 -1
  88. data/lib/ruby_smb/smb2/negotiate_context.rb +10 -1
  89. data/lib/ruby_smb/smb2/packet/transform_header.rb +7 -7
  90. data/lib/ruby_smb/smb2/tree.rb +1 -0
  91. data/lib/ruby_smb/smb2.rb +1 -0
  92. data/lib/ruby_smb/version.rb +1 -1
  93. data/spec/lib/ruby_smb/client_spec.rb +31 -8
  94. data/spec/lib/ruby_smb/fscc/file_information/file_access_information_spec.rb +21 -0
  95. data/spec/lib/ruby_smb/fscc/file_information/file_alignment_information_spec.rb +21 -0
  96. data/spec/lib/ruby_smb/fscc/file_information/file_all_information_spec.rb +61 -0
  97. data/spec/lib/ruby_smb/fscc/file_information/file_basic_information_spec.rb +41 -0
  98. data/spec/lib/ruby_smb/fscc/file_information/file_both_directory_information_spec.rb +59 -10
  99. data/spec/lib/ruby_smb/fscc/file_information/file_directory_information_spec.rb +30 -12
  100. data/spec/lib/ruby_smb/fscc/file_information/file_ea_information_spec.rb +21 -0
  101. data/spec/lib/ruby_smb/fscc/file_information/file_full_directory_information_spec.rb +30 -12
  102. data/spec/lib/ruby_smb/fscc/file_information/file_id_both_directory_information_spec.rb +63 -10
  103. data/spec/lib/ruby_smb/fscc/file_information/file_id_full_directory_information_spec.rb +30 -12
  104. data/spec/lib/ruby_smb/fscc/file_information/file_internal_information_spec.rb +21 -0
  105. data/spec/lib/ruby_smb/fscc/file_information/file_mode_information_spec.rb +21 -0
  106. data/spec/lib/ruby_smb/fscc/file_information/file_name_information_spec.rb +44 -0
  107. data/spec/lib/ruby_smb/fscc/file_information/file_names_information_spec.rb +30 -12
  108. data/spec/lib/ruby_smb/fscc/file_information/file_network_open_information_spec.rb +51 -0
  109. data/spec/lib/ruby_smb/fscc/file_information/file_normalized_name_information_spec.rb +44 -0
  110. data/spec/lib/ruby_smb/fscc/file_information/file_position_information_spec.rb +21 -0
  111. data/spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb +1 -1
  112. data/spec/lib/ruby_smb/fscc/file_information/file_standard_information_spec.rb +41 -0
  113. data/spec/lib/ruby_smb/fscc/file_information/file_stream_information_spec.rb +51 -0
  114. data/spec/lib/ruby_smb/fscc/file_information_spec.rb +14 -0
  115. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information_spec.rb +46 -0
  116. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information_spec.rb +51 -0
  117. data/spec/lib/ruby_smb/fscc/file_system_information_spec.rb +14 -0
  118. data/spec/lib/ruby_smb/server/server_client_spec.rb +15 -0
  119. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname_spec.rb +581 -0
  120. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat_spec.rb +207 -0
  121. data/spec/lib/ruby_smb/server/share/provider/virtual_disk_spec.rb +122 -0
  122. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_request_spec.rb +2 -2
  123. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_response_spec.rb +36 -2
  124. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_request_spec.rb +2 -2
  125. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_response_spec.rb +35 -1
  126. data/spec/lib/ruby_smb/smb1/packet/trans2/query_file_information_request_spec.rb +74 -0
  127. data/spec/lib/ruby_smb/smb1/packet/trans2/query_file_information_response_spec.rb +96 -0
  128. data/spec/lib/ruby_smb/smb1/packet/trans2/query_fs_information_request_spec.rb +62 -0
  129. data/spec/lib/ruby_smb/smb1/packet/trans2/query_fs_information_response_spec.rb +88 -0
  130. data/spec/lib/ruby_smb/smb1/packet/trans2/query_path_information_request_spec.rb +79 -0
  131. data/spec/lib/ruby_smb/smb1/packet/trans2/query_path_information_response_spec.rb +96 -0
  132. data/spec/lib/ruby_smb/smb1/packet/trans2/request_spec.rb +2 -2
  133. data/spec/lib/ruby_smb/smb1/packet/trans2/response_spec.rb +3 -3
  134. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_request_spec.rb +3 -2
  135. data/spec/lib/ruby_smb/smb1/packet/trans2/set_file_information_response_spec.rb +7 -2
  136. data/spec/lib/ruby_smb/smb1/tree_spec.rb +3 -3
  137. data/spec/lib/ruby_smb/smb2/packet/transform_header_spec.rb +2 -2
  138. data.tar.gz.sig +0 -0
  139. metadata +88 -2
  140. metadata.gz.sig +0 -0
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileAlignmentInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_ALIGNMENT_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :alignment_requirement }
12
+
13
+ it 'is little endian' do
14
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
15
+ end
16
+
17
+ it 'tracks the alignment requirement in a Uint32 field' do
18
+ expect(struct.alignment_requirement).to be_a BinData::Uint32le
19
+ end
20
+
21
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileAllInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_ALL_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :basic_information }
12
+ it { should respond_to :standard_information }
13
+ it { should respond_to :internal_information }
14
+ it { should respond_to :ea_information }
15
+ it { should respond_to :access_information }
16
+ it { should respond_to :position_information }
17
+ it { should respond_to :mode_information }
18
+ it { should respond_to :alignment_information }
19
+ it { should respond_to :name_information }
20
+
21
+ it 'is little endian' do
22
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
23
+ end
24
+
25
+ it 'tracks the basic information in a FileBasicInformation field' do
26
+ expect(struct.basic_information).to be_a RubySMB::Fscc::FileInformation::FileBasicInformation
27
+ end
28
+
29
+ it 'tracks the standard information in a FileStandardInformation field' do
30
+ expect(struct.standard_information).to be_a RubySMB::Fscc::FileInformation::FileStandardInformation
31
+ end
32
+
33
+ it 'tracks the internal information in a FileInternalInformation field' do
34
+ expect(struct.internal_information).to be_a RubySMB::Fscc::FileInformation::FileInternalInformation
35
+ end
36
+
37
+ it 'tracks the ea information in a FileEaInformation field' do
38
+ expect(struct.ea_information).to be_a RubySMB::Fscc::FileInformation::FileEaInformation
39
+ end
40
+
41
+ it 'tracks the access information in a FileAccessInformation field' do
42
+ expect(struct.access_information).to be_a RubySMB::Fscc::FileInformation::FileAccessInformation
43
+ end
44
+
45
+ it 'tracks the position information in a FilePositionInformation field' do
46
+ expect(struct.position_information).to be_a RubySMB::Fscc::FileInformation::FilePositionInformation
47
+ end
48
+
49
+ it 'tracks the mode information in a FileModeInformation field' do
50
+ expect(struct.mode_information).to be_a RubySMB::Fscc::FileInformation::FileModeInformation
51
+ end
52
+
53
+ it 'tracks the alignment information in a FileAlignmentInformation field' do
54
+ expect(struct.alignment_information).to be_a RubySMB::Fscc::FileInformation::FileAlignmentInformation
55
+ end
56
+
57
+ it 'tracks the name information in a FileNameInformation field' do
58
+ expect(struct.name_information).to be_a RubySMB::Fscc::FileInformation::FileNameInformation
59
+ end
60
+ end
61
+
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileBasicInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_BASIC_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :create_time }
12
+ it { should respond_to :last_access }
13
+ it { should respond_to :last_write }
14
+ it { should respond_to :last_change }
15
+ it { should respond_to :file_attributes }
16
+
17
+ it 'is little endian' do
18
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
19
+ end
20
+
21
+ it 'tracks the create time in a FileTime field' do
22
+ expect(struct.create_time).to be_a RubySMB::Field::FileTime
23
+ end
24
+
25
+ it 'tracks the last access time in a FileTime field' do
26
+ expect(struct.last_access).to be_a RubySMB::Field::FileTime
27
+ end
28
+
29
+ it 'tracks the last write time in a FileTime field' do
30
+ expect(struct.last_write).to be_a RubySMB::Field::FileTime
31
+ end
32
+
33
+ it 'tracks the last modified time in a FileTime field' do
34
+ expect(struct.last_change).to be_a RubySMB::Field::FileTime
35
+ end
36
+
37
+ it 'tracks the file attributes in a FileAttributes field' do
38
+ expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
39
+ end
40
+
41
+ end
@@ -27,6 +27,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileBothDirectoryInformation do
27
27
  expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
28
28
  end
29
29
 
30
+ it 'tracks the next offset in a Uint32 field' do
31
+ expect(struct.next_offset).to be_a BinData::Uint32le
32
+ end
33
+
34
+ it 'tracks the file index in a Uint32 field' do
35
+ expect(struct.file_index).to be_a BinData::Uint32le
36
+ end
37
+
30
38
  it 'tracks the creation time in a Filetime field' do
31
39
  expect(struct.create_time).to be_a RubySMB::Field::FileTime
32
40
  end
@@ -43,6 +51,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileBothDirectoryInformation do
43
51
  expect(struct.last_change).to be_a RubySMB::Field::FileTime
44
52
  end
45
53
 
54
+ it 'tracks the file size in a Int64 field' do
55
+ expect(struct.end_of_file).to be_a BinData::Int64le
56
+ end
57
+
58
+ it 'tracks the allocation size in a Int64 field' do
59
+ expect(struct.allocation_size).to be_a BinData::Int64le
60
+ end
61
+
46
62
  it 'contains the file attributes of the file' do
47
63
  expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
48
64
  end
@@ -52,20 +68,53 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileBothDirectoryInformation do
52
68
  expect(struct.file_name_length).to eq struct.file_name.do_num_bytes
53
69
  end
54
70
 
55
- it 'automatically encodes the file name in UTF-16LE' do
56
- name = 'Hello_world.txt'
57
- struct.file_name = name
58
- expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
71
+ it 'tracks the extended attributes size in a Uint32 field' do
72
+ expect(struct.ea_size).to be_a BinData::Uint32le
59
73
  end
60
74
 
61
- describe 'reading in from a blob' do
62
- it 'uses the file_name_length to know when to stop reading' do
75
+ it 'tracks the short name length in a Uint8 field' do
76
+ expect(struct.short_name_length).to be_a BinData::Uint8
77
+ end
78
+
79
+ it 'tracks the short name in a String16 field' do
80
+ expect(struct.short_name).to be_a RubySMB::Field::String16
81
+ end
82
+
83
+ it 'tracks the file name in a String16 field' do
84
+ expect(struct.file_name).to be_a RubySMB::Field::String16
85
+ end
86
+
87
+ describe '#short_name' do
88
+ it 'automatically encodes the short name in UTF-16LE' do
89
+ name = 'Hello_world.'
90
+ struct.short_name = name
91
+ expect(struct.short_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
92
+ end
93
+
94
+ it 'is always exactly 24 bytes in length' do
95
+ struct.short_name = ''
96
+ expect(struct.short_name.num_bytes).to eq 24
97
+ struct.short_name = 'Hello_world.'
98
+ expect(struct.short_name.num_bytes).to eq 24
99
+ end
100
+ end
101
+
102
+ describe '#file_name' do
103
+ it 'automatically encodes the file name in UTF-16LE' do
63
104
  name = 'Hello_world.txt'
64
105
  struct.file_name = name
65
- blob = struct.to_binary_s
66
- blob << 'AAAA'
67
- new_from_blob = described_class.read(blob)
68
- expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
106
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
107
+ end
108
+
109
+ describe 'reading in from a blob' do
110
+ it 'uses the file_name_length to know when to stop reading' do
111
+ name = 'Hello_world.txt'
112
+ struct.file_name = name
113
+ blob = struct.to_binary_s
114
+ blob << 'AAAA'
115
+ new_from_blob = described_class.read(blob)
116
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
117
+ end
69
118
  end
70
119
  end
71
120
  end
@@ -24,6 +24,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileDirectoryInformation do
24
24
  expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
25
25
  end
26
26
 
27
+ it 'tracks the next offset in a Uint32 field' do
28
+ expect(struct.next_offset).to be_a BinData::Uint32le
29
+ end
30
+
31
+ it 'tracks the file index in a Uint32 field' do
32
+ expect(struct.file_index).to be_a BinData::Uint32le
33
+ end
34
+
27
35
  it 'tracks the creation time in a Filetime field' do
28
36
  expect(struct.create_time).to be_a RubySMB::Field::FileTime
29
37
  end
@@ -40,6 +48,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileDirectoryInformation do
40
48
  expect(struct.last_change).to be_a RubySMB::Field::FileTime
41
49
  end
42
50
 
51
+ it 'tracks the file size in a Int64 field' do
52
+ expect(struct.end_of_file).to be_a BinData::Int64le
53
+ end
54
+
55
+ it 'tracks the allocation size in a Int64 field' do
56
+ expect(struct.allocation_size).to be_a BinData::Int64le
57
+ end
58
+
43
59
  it 'contains the file attributes of the file' do
44
60
  expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
45
61
  end
@@ -49,20 +65,22 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileDirectoryInformation do
49
65
  expect(struct.file_name_length).to eq struct.file_name.do_num_bytes
50
66
  end
51
67
 
52
- it 'automatically encodes the file name in UTF-16LE' do
53
- name = 'Hello_world.txt'
54
- struct.file_name = name
55
- expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
56
- end
57
-
58
- describe 'reading in from a blob' do
59
- it 'uses the file_name_length to know when to stop reading' do
68
+ describe '#file_name' do
69
+ it 'automatically encodes the file name in UTF-16LE' do
60
70
  name = 'Hello_world.txt'
61
71
  struct.file_name = name
62
- blob = struct.to_binary_s
63
- blob << 'AAAA'
64
- new_from_blob = described_class.read(blob)
65
- expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
72
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
73
+ end
74
+
75
+ describe 'reading in from a blob' do
76
+ it 'uses the file_name_length to know when to stop reading' do
77
+ name = 'Hello_world.txt'
78
+ struct.file_name = name
79
+ blob = struct.to_binary_s
80
+ blob << 'AAAA'
81
+ new_from_blob = described_class.read(blob)
82
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
83
+ end
66
84
  end
67
85
  end
68
86
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileEaInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_EA_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :ea_size }
12
+
13
+ it 'is little endian' do
14
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
15
+ end
16
+
17
+ it 'tracks the extended attributes size in a Uint32 field' do
18
+ expect(struct.ea_size).to be_a BinData::Uint32le
19
+ end
20
+
21
+ end
@@ -25,6 +25,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileFullDirectoryInformation do
25
25
  expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
26
26
  end
27
27
 
28
+ it 'tracks the next offset in a Uint32 field' do
29
+ expect(struct.next_offset).to be_a BinData::Uint32le
30
+ end
31
+
32
+ it 'tracks the file index in a Uint32 field' do
33
+ expect(struct.file_index).to be_a BinData::Uint32le
34
+ end
35
+
28
36
  it 'tracks the creation time in a Filetime field' do
29
37
  expect(struct.create_time).to be_a RubySMB::Field::FileTime
30
38
  end
@@ -41,6 +49,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileFullDirectoryInformation do
41
49
  expect(struct.last_change).to be_a RubySMB::Field::FileTime
42
50
  end
43
51
 
52
+ it 'tracks the file size in a Int64 field' do
53
+ expect(struct.end_of_file).to be_a BinData::Int64le
54
+ end
55
+
56
+ it 'tracks the allocation size in a Int64 field' do
57
+ expect(struct.allocation_size).to be_a BinData::Int64le
58
+ end
59
+
44
60
  it 'contains the file attributes of the file' do
45
61
  expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
46
62
  end
@@ -50,20 +66,22 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileFullDirectoryInformation do
50
66
  expect(struct.file_name_length).to eq struct.file_name.do_num_bytes
51
67
  end
52
68
 
53
- it 'automatically encodes the file name in UTF-16LE' do
54
- name = 'Hello_world.txt'
55
- struct.file_name = name
56
- expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
57
- end
58
-
59
- describe 'reading in from a blob' do
60
- it 'uses the file_name_length to know when to stop reading' do
69
+ describe '#file_name' do
70
+ it 'automatically encodes the file name in UTF-16LE' do
61
71
  name = 'Hello_world.txt'
62
72
  struct.file_name = name
63
- blob = struct.to_binary_s
64
- blob << 'AAAA'
65
- new_from_blob = described_class.read(blob)
66
- expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
73
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
74
+ end
75
+
76
+ describe 'reading in from a blob' do
77
+ it 'uses the file_name_length to know when to stop reading' do
78
+ name = 'Hello_world.txt'
79
+ struct.file_name = name
80
+ blob = struct.to_binary_s
81
+ blob << 'AAAA'
82
+ new_from_blob = described_class.read(blob)
83
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
84
+ end
67
85
  end
68
86
  end
69
87
  end
@@ -28,6 +28,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdBothDirectoryInformation do
28
28
  expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
29
29
  end
30
30
 
31
+ it 'tracks the next offset in a Uint32 field' do
32
+ expect(struct.next_offset).to be_a BinData::Uint32le
33
+ end
34
+
35
+ it 'tracks the file index in a Uint32 field' do
36
+ expect(struct.file_index).to be_a BinData::Uint32le
37
+ end
38
+
31
39
  it 'tracks the creation time in a Filetime field' do
32
40
  expect(struct.create_time).to be_a RubySMB::Field::FileTime
33
41
  end
@@ -44,6 +52,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdBothDirectoryInformation do
44
52
  expect(struct.last_change).to be_a RubySMB::Field::FileTime
45
53
  end
46
54
 
55
+ it 'tracks the file size in a Int64 field' do
56
+ expect(struct.end_of_file).to be_a BinData::Int64le
57
+ end
58
+
59
+ it 'tracks the allocation size in a Int64 field' do
60
+ expect(struct.allocation_size).to be_a BinData::Int64le
61
+ end
62
+
47
63
  it 'contains the file attributes of the file' do
48
64
  expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
49
65
  end
@@ -53,20 +69,57 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdBothDirectoryInformation do
53
69
  expect(struct.file_name_length).to eq struct.file_name.do_num_bytes
54
70
  end
55
71
 
56
- it 'automatically encodes the file name in UTF-16LE' do
57
- name = 'Hello_world.txt'
58
- struct.file_name = name
59
- expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
72
+ it 'tracks the extended attributes size in a Uint32 field' do
73
+ expect(struct.ea_size).to be_a BinData::Uint32le
74
+ end
75
+
76
+ it 'tracks the short name length in a Uint8 field' do
77
+ expect(struct.short_name_length).to be_a BinData::Uint8
78
+ end
79
+
80
+ it 'tracks the short name in a String16 field' do
81
+ expect(struct.short_name).to be_a RubySMB::Field::String16
60
82
  end
61
83
 
62
- describe 'reading in from a blob' do
63
- it 'uses the file_name_length to know when to stop reading' do
84
+ it 'tracks the file id in a Uint64 field' do
85
+ expect(struct.file_id).to be_a BinData::Uint64le
86
+ end
87
+
88
+ it 'tracks the file name in a String16 field' do
89
+ expect(struct.file_name).to be_a RubySMB::Field::String16
90
+ end
91
+
92
+ describe '#short_name' do
93
+ it 'automatically encodes the short name in UTF-16LE' do
94
+ name = 'Hello_world.'
95
+ struct.short_name = name
96
+ expect(struct.short_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
97
+ end
98
+
99
+ it 'is always exactly 24 bytes in length' do
100
+ struct.short_name = ''
101
+ expect(struct.short_name.num_bytes).to eq 24
102
+ struct.short_name = 'Hello_world.'
103
+ expect(struct.short_name.num_bytes).to eq 24
104
+ end
105
+ end
106
+
107
+ describe '#file_name' do
108
+ it 'automatically encodes the file name in UTF-16LE' do
64
109
  name = 'Hello_world.txt'
65
110
  struct.file_name = name
66
- blob = struct.to_binary_s
67
- blob << 'AAAA'
68
- new_from_blob = described_class.read(blob)
69
- expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
111
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
112
+ end
113
+
114
+ describe 'reading in from a blob' do
115
+ it 'uses the file_name_length to know when to stop reading' do
116
+ name = 'Hello_world.txt'
117
+ struct.file_name = name
118
+ blob = struct.to_binary_s
119
+ blob << 'AAAA'
120
+ new_from_blob = described_class.read(blob)
121
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
122
+ end
70
123
  end
71
124
  end
72
125
  end
@@ -26,6 +26,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdFullDirectoryInformation do
26
26
  expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
27
27
  end
28
28
 
29
+ it 'tracks the next offset in a Uint32 field' do
30
+ expect(struct.next_offset).to be_a BinData::Uint32le
31
+ end
32
+
33
+ it 'tracks the file index in a Uint32 field' do
34
+ expect(struct.file_index).to be_a BinData::Uint32le
35
+ end
36
+
29
37
  it 'tracks the creation time in a Filetime field' do
30
38
  expect(struct.create_time).to be_a RubySMB::Field::FileTime
31
39
  end
@@ -42,6 +50,14 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdFullDirectoryInformation do
42
50
  expect(struct.last_change).to be_a RubySMB::Field::FileTime
43
51
  end
44
52
 
53
+ it 'tracks the file size in a Int64 field' do
54
+ expect(struct.end_of_file).to be_a BinData::Int64le
55
+ end
56
+
57
+ it 'tracks the allocation size in a Int64 field' do
58
+ expect(struct.allocation_size).to be_a BinData::Int64le
59
+ end
60
+
45
61
  it 'contains the file attributes of the file' do
46
62
  expect(struct.file_attributes).to be_a RubySMB::Fscc::FileAttributes
47
63
  end
@@ -51,20 +67,22 @@ RSpec.describe RubySMB::Fscc::FileInformation::FileIdFullDirectoryInformation do
51
67
  expect(struct.file_name_length).to eq struct.file_name.do_num_bytes
52
68
  end
53
69
 
54
- it 'automatically encodes the file name in UTF-16LE' do
55
- name = 'Hello_world.txt'
56
- struct.file_name = name
57
- expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
58
- end
59
-
60
- describe 'reading in from a blob' do
61
- it 'uses the file_name_length to know when to stop reading' do
70
+ describe '#file_name' do
71
+ it 'automatically encodes the file name in UTF-16LE' do
62
72
  name = 'Hello_world.txt'
63
73
  struct.file_name = name
64
- blob = struct.to_binary_s
65
- blob << 'AAAA'
66
- new_from_blob = described_class.read(blob)
67
- expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
74
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
75
+ end
76
+
77
+ describe 'reading in from a blob' do
78
+ it 'uses the file_name_length to know when to stop reading' do
79
+ name = 'Hello_world.txt'
80
+ struct.file_name = name
81
+ blob = struct.to_binary_s
82
+ blob << 'AAAA'
83
+ new_from_blob = described_class.read(blob)
84
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
85
+ end
68
86
  end
69
87
  end
70
88
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileInternalInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_INTERNAL_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :file_id }
12
+
13
+ it 'is little endian' do
14
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
15
+ end
16
+
17
+ it 'tracks the file ID in a Uint64 field' do
18
+ expect(struct.file_id).to be_a BinData::Uint64le
19
+ end
20
+
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileModeInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_MODE_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :flags }
12
+
13
+ it 'is little endian' do
14
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
15
+ end
16
+
17
+ it 'tracks the flags in a struct field' do
18
+ expect(struct.flags).to be_a BinData::Struct
19
+ end
20
+
21
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileNameInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_NAME_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :file_name_length }
12
+ it { should respond_to :file_name }
13
+
14
+ it 'is little endian' do
15
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
16
+ end
17
+
18
+ it 'tracks the file name length in a Uint32 field' do
19
+ expect(struct.file_name_length).to be_a BinData::Uint32le
20
+ end
21
+
22
+ it 'tracks the file name in a String16 field' do
23
+ expect(struct.file_name).to be_a RubySMB::Field::String16
24
+ end
25
+
26
+ describe '#file_name' do
27
+ it 'automatically encodes the file name in UTF-16LE' do
28
+ name = 'Hello_world.txt'
29
+ struct.file_name = name
30
+ expect(struct.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
31
+ end
32
+
33
+ describe 'reading in from a blob' do
34
+ it 'uses the file_name_length to know when to stop reading' do
35
+ name = 'Hello_world.txt'
36
+ struct.file_name = name
37
+ blob = struct.to_binary_s
38
+ blob << 'AAAA'
39
+ new_from_blob = described_class.read(blob)
40
+ expect(new_from_blob.file_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
41
+ end
42
+ end
43
+ end
44
+ end