rubyntlm 0.3.4 → 0.4.0

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 (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +3 -0
  3. data/.travis.yml +0 -1
  4. data/LICENSE +20 -0
  5. data/Rakefile +8 -15
  6. data/lib/net/ntlm.rb +22 -654
  7. data/lib/net/ntlm/blob.rb +17 -0
  8. data/lib/net/ntlm/encode_util.rb +49 -0
  9. data/lib/net/ntlm/field.rb +35 -0
  10. data/lib/net/ntlm/field_set.rb +125 -0
  11. data/lib/net/ntlm/int16_le.rb +26 -0
  12. data/lib/net/ntlm/int32_le.rb +25 -0
  13. data/lib/net/ntlm/int64_le.rb +26 -0
  14. data/lib/net/ntlm/message.rb +115 -0
  15. data/lib/net/ntlm/message/type0.rb +16 -0
  16. data/lib/net/ntlm/message/type1.rb +43 -0
  17. data/lib/net/ntlm/message/type2.rb +126 -0
  18. data/lib/net/ntlm/message/type3.rb +68 -0
  19. data/lib/net/ntlm/security_buffer.rb +48 -0
  20. data/lib/net/ntlm/string.rb +35 -0
  21. data/lib/net/ntlm/version.rb +11 -0
  22. data/rubyntlm.gemspec +4 -1
  23. data/spec/lib/net/ntlm/blob_spec.rb +16 -0
  24. data/spec/lib/net/ntlm/encode_util_spec.rb +16 -0
  25. data/spec/lib/net/ntlm/field_set_spec.rb +33 -0
  26. data/spec/lib/net/ntlm/field_spec.rb +34 -0
  27. data/spec/lib/net/ntlm/int16_le_spec.rb +18 -0
  28. data/spec/lib/net/ntlm/int32_le_spec.rb +19 -0
  29. data/spec/lib/net/ntlm/int64_le_spec.rb +19 -0
  30. data/spec/lib/net/ntlm/message/type0_spec.rb +21 -0
  31. data/spec/lib/net/ntlm/message/type1_spec.rb +42 -0
  32. data/spec/lib/net/ntlm/message/type2_spec.rb +88 -0
  33. data/spec/lib/net/ntlm/message/type3_spec.rb +20 -0
  34. data/spec/lib/net/ntlm/message_spec.rb +17 -0
  35. data/spec/lib/net/ntlm/security_buffer_spec.rb +64 -0
  36. data/spec/lib/net/ntlm/string_spec.rb +72 -0
  37. data/spec/lib/net/ntlm/version_spec.rb +26 -0
  38. data/spec/lib/net/ntlm_spec.rb +121 -0
  39. data/spec/spec_helper.rb +21 -0
  40. data/spec/support/shared/examples/net/ntlm/field_shared.rb +25 -0
  41. data/spec/support/shared/examples/net/ntlm/fieldset_shared.rb +239 -0
  42. data/spec/support/shared/examples/net/ntlm/int_shared.rb +43 -0
  43. data/spec/support/shared/examples/net/ntlm/message_shared.rb +35 -0
  44. metadata +77 -5
  45. data/spec/unit/ntlm_spec.rb +0 -183
@@ -0,0 +1,21 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter '/spec/'
4
+ add_filter '/config/'
5
+ add_filter '/vendor/'
6
+ end if ENV["COVERAGE"]
7
+
8
+
9
+ require 'rspec'
10
+ require 'net/ntlm'
11
+
12
+ # add project lib directory to load path
13
+ spec_pathname = Pathname.new(__FILE__).dirname
14
+ root_pathname = spec_pathname.join('..').expand_path
15
+ # Requires supporting ruby files with custom matchers and macros, etc,
16
+ # in spec/support/ and its subdirectories.
17
+ support_glob = root_pathname.join('spec', 'support', '**', '*.rb')
18
+
19
+ Dir.glob(support_glob) do |path|
20
+ require path
21
+ end
@@ -0,0 +1,25 @@
1
+ shared_examples_for 'a field' do | value, active|
2
+
3
+ subject do
4
+ described_class.new({
5
+ :value => value,
6
+ :active => active
7
+ })
8
+ end
9
+
10
+ it { should respond_to :active }
11
+ it { should respond_to :value }
12
+ it { should respond_to :size }
13
+ it { should respond_to :parse }
14
+ it { should respond_to :serialize }
15
+
16
+
17
+ it 'should set the value from initialize options' do
18
+ subject.value.should == value
19
+ end
20
+
21
+ it 'should set active from initialize options' do
22
+ subject.active.should == active
23
+ end
24
+
25
+ end
@@ -0,0 +1,239 @@
1
+ shared_examples_for 'a fieldset' do |fields|
2
+
3
+ subject(:fieldset_class) do
4
+ Class.new(described_class)
5
+ end
6
+
7
+ context 'the class' do
8
+ it { should respond_to :string }
9
+ it { should respond_to :int16LE }
10
+ it { should respond_to :int32LE }
11
+ it { should respond_to :int64LE }
12
+ it { should respond_to :security_buffer }
13
+ it { should respond_to :prototypes }
14
+ it { should respond_to :names }
15
+ it { should respond_to :types }
16
+ it { should respond_to :opts }
17
+
18
+ context 'adding a String Field' do
19
+ before(:each) do
20
+ fieldset_class.string(:test_string, { :value => 'Test'})
21
+ end
22
+
23
+ it 'should set the prototypes correctly' do
24
+ fieldset_class.prototypes.should include([:test_string, Net::NTLM::String, {:value=>"Test"}])
25
+ end
26
+
27
+ it 'should set the names correctly' do
28
+ fieldset_class.names.should include(:test_string)
29
+ end
30
+
31
+ it 'should set the types correctly' do
32
+ fieldset_class.types.should include(Net::NTLM::String)
33
+ end
34
+
35
+ it 'should set the opts correctly' do
36
+ fieldset_class.opts.should include({:value => 'Test'})
37
+ end
38
+
39
+ context 'when creating an instance' do
40
+ let(:fieldset_object) do
41
+ fieldset_class.new
42
+ end
43
+
44
+ it 'should have the new accessor' do
45
+ fieldset_object.should respond_to :test_string
46
+ end
47
+
48
+ it 'should have the correct default value' do
49
+ fieldset_object.test_string.should == 'Test'
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'adding a Int16LE Field' do
55
+ before(:each) do
56
+ fieldset_class.int16LE(:test_int, { :value => 15})
57
+ end
58
+
59
+ it 'should set the prototypes correctly' do
60
+ fieldset_class.prototypes.should include([:test_int, Net::NTLM::Int16LE, {:value=>15}])
61
+ end
62
+
63
+ it 'should set the names correctly' do
64
+ fieldset_class.names.should include(:test_int)
65
+ end
66
+
67
+ it 'should set the types correctly' do
68
+ fieldset_class.types.should include(Net::NTLM::Int16LE)
69
+ end
70
+
71
+ it 'should set the opts correctly' do
72
+ fieldset_class.opts.should include({:value => 15})
73
+ end
74
+
75
+ context 'when creating an instance' do
76
+ let(:fieldset_object) do
77
+ fieldset_class.new
78
+ end
79
+
80
+ it 'should have the new accessor' do
81
+ fieldset_object.should respond_to :test_int
82
+ end
83
+
84
+ it 'should have the correct default value' do
85
+ fieldset_object.test_int.should == 15
86
+ end
87
+ end
88
+ end
89
+
90
+ context 'adding a Int32LE Field' do
91
+ before(:each) do
92
+ fieldset_class.int32LE(:test_int, { :value => 15})
93
+ end
94
+
95
+ it 'should set the prototypes correctly' do
96
+ fieldset_class.prototypes.should include([:test_int, Net::NTLM::Int32LE, {:value=>15}])
97
+ end
98
+
99
+ it 'should set the names correctly' do
100
+ fieldset_class.names.should include(:test_int)
101
+ end
102
+
103
+ it 'should set the types correctly' do
104
+ fieldset_class.types.should include(Net::NTLM::Int32LE)
105
+ end
106
+
107
+ it 'should set the opts correctly' do
108
+ fieldset_class.opts.should include({:value => 15})
109
+ end
110
+
111
+ context 'when creating an instance' do
112
+ let(:fieldset_object) do
113
+ fieldset_class.new
114
+ end
115
+
116
+ it 'should have the new accessor' do
117
+ fieldset_object.should respond_to :test_int
118
+ end
119
+
120
+ it 'should have the correct default value' do
121
+ fieldset_object.test_int.should == 15
122
+ end
123
+ end
124
+ end
125
+
126
+ context 'adding a Int64LE Field' do
127
+ before(:each) do
128
+ fieldset_class.int64LE(:test_int, { :value => 15})
129
+ end
130
+
131
+ it 'should set the prototypes correctly' do
132
+ fieldset_class.prototypes.should include([:test_int, Net::NTLM::Int64LE, {:value=>15}])
133
+ end
134
+
135
+ it 'should set the names correctly' do
136
+ fieldset_class.names.should include(:test_int)
137
+ end
138
+
139
+ it 'should set the types correctly' do
140
+ fieldset_class.types.should include(Net::NTLM::Int64LE)
141
+ end
142
+
143
+ it 'should set the opts correctly' do
144
+ fieldset_class.opts.should include({:value => 15})
145
+ end
146
+
147
+ context 'when creating an instance' do
148
+ let(:fieldset_object) do
149
+ fieldset_class.new
150
+ end
151
+
152
+ it 'should have the new accessor' do
153
+ fieldset_object.should respond_to :test_int
154
+ end
155
+
156
+ it 'should have the correct default value' do
157
+ fieldset_object.test_int.should == 15
158
+ end
159
+ end
160
+ end
161
+
162
+ context 'adding a SecurityBuffer Field' do
163
+ before(:each) do
164
+ fieldset_class.security_buffer(:test_buffer, { :value => 15})
165
+ end
166
+
167
+ it 'should set the prototypes correctly' do
168
+ fieldset_class.prototypes.should include([:test_buffer, Net::NTLM::SecurityBuffer, {:value=>15}])
169
+ end
170
+
171
+ it 'should set the names correctly' do
172
+ fieldset_class.names.should include(:test_buffer)
173
+ end
174
+
175
+ it 'should set the types correctly' do
176
+ fieldset_class.types.should include(Net::NTLM::SecurityBuffer)
177
+ end
178
+
179
+ it 'should set the opts correctly' do
180
+ fieldset_class.opts.should include({:value => 15})
181
+ end
182
+
183
+ context 'when creating an instance' do
184
+ let(:fieldset_object) do
185
+ fieldset_class.new
186
+ end
187
+
188
+ it 'should have the new accessor' do
189
+ fieldset_object.should respond_to :test_buffer
190
+ end
191
+
192
+ it 'should have the correct default value' do
193
+ fieldset_object.test_buffer.should == 15
194
+ end
195
+ end
196
+ end
197
+
198
+ end
199
+
200
+ context 'an instance' do
201
+
202
+ subject(:fieldset_object) do
203
+ # FieldSet Base Class and Message Base Class
204
+ # have no fields by default and thus cannot be initialized
205
+ # currently. Clumsy workaround for now.
206
+ if described_class.names.empty?
207
+ described_class.string(:test_string, { :value => 'Test', :active => true, :size => 4})
208
+ end
209
+ described_class.new
210
+ end
211
+
212
+ it { should respond_to :serialize }
213
+ it { should respond_to :parse }
214
+ it { should respond_to :size }
215
+ it { should respond_to :enable }
216
+ it { should respond_to :disable }
217
+
218
+ context 'fields' do
219
+ fields.each do |field|
220
+ it { should respond_to field[:name] }
221
+
222
+ context "#{field[:name]}" do
223
+ it "should be a #{field[:class].to_s}" do
224
+ fieldset_object[field[:name]].class.should == field[:class]
225
+ end
226
+
227
+ it "should have a default value of #{field[:value]}" do
228
+ fieldset_object[field[:name]].value.should == field[:value]
229
+ end
230
+
231
+ it "should have active set to #{field[:active]}" do
232
+ fieldset_object[field[:name]].active.should == field[:active]
233
+ end
234
+ end
235
+ end
236
+ end
237
+
238
+ end
239
+ end
@@ -0,0 +1,43 @@
1
+ shared_examples_for 'an integer field' do |values|
2
+
3
+ subject do
4
+ described_class.new({
5
+ :value => values[:default],
6
+ :active => true
7
+ })
8
+ end
9
+
10
+ context '#serialize' do
11
+ it 'should serialize properly with an integer value' do
12
+ subject.serialize.should == values[:default_hex]
13
+ end
14
+
15
+ it 'should raise an Exception for a String' do
16
+ subject.value = 'A'
17
+ expect {subject.serialize}.to raise_error
18
+ end
19
+
20
+ it 'should raise an Exception for Nil' do
21
+ subject.value = nil
22
+ expect {subject.serialize}.to raise_error
23
+ end
24
+ end
25
+
26
+ context '#parse' do
27
+ it "should parse a raw #{values[:bits].to_s}-bit integer from a string" do
28
+ subject.parse(values[:alt_hex]).should == values[:size]
29
+ subject.value.should == values[:alt]
30
+ end
31
+
32
+ it "should use an offset to find the #{values[:bits].to_s}-bit integer in the string" do
33
+ subject.parse("Value:#{values[:alt_hex]}",6).should == values[:size]
34
+ subject.value.should == values[:alt]
35
+ end
36
+
37
+ it 'should return 0 and not change the value if the string is not big enough' do
38
+ subject.parse(values[:small]).should == 0
39
+ subject.value.should == values[:default]
40
+ end
41
+ end
42
+
43
+ end
@@ -0,0 +1,35 @@
1
+ shared_examples_for 'a message' do |flags|
2
+
3
+ subject(:test_message) do
4
+ unless described_class.names.include?(:flag)
5
+ described_class.int32LE(:flag, {:value => Net::NTLM::DEFAULT_FLAGS[:TYPE1] })
6
+ end
7
+ described_class.new
8
+ end
9
+
10
+ it { should respond_to :has_flag? }
11
+ it { should respond_to :set_flag }
12
+ it { should respond_to :dump_flags }
13
+ it { should respond_to :encode64 }
14
+ it { should respond_to :decode64 }
15
+ it { should respond_to :head_size }
16
+ it { should respond_to :data_size }
17
+ it { should respond_to :size }
18
+ it { should respond_to :security_buffers }
19
+ it { should respond_to :deflag }
20
+ it { should respond_to :data_edge }
21
+
22
+ flags.each do |flag|
23
+ it "should be able to check if the #{flag} flag is set" do
24
+ test_message.has_flag?(flag).should == true
25
+ end
26
+ end
27
+
28
+
29
+ it 'should be able to set a new flag' do
30
+ test_message.set_flag(:DOMAIN_SUPPLIED)
31
+ test_message.has_flag?(:DOMAIN_SUPPLIED).should == true
32
+ end
33
+
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyntlm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Kajimoto
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-08 00:00:00.000000000 Z
12
+ date: 2013-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -39,6 +39,20 @@ dependencies:
39
39
  - - '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: simplecov
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
42
56
  description: Ruby/NTLM provides message creator and parser for the NTLM authentication.
43
57
  email:
44
58
  - koheik@gmail.com
@@ -48,20 +62,58 @@ extensions: []
48
62
  extra_rdoc_files: []
49
63
  files:
50
64
  - .gitignore
65
+ - .rspec
51
66
  - .travis.yml
52
67
  - CHANGELOG.md
53
68
  - Gemfile
69
+ - LICENSE
54
70
  - README.md
55
71
  - Rakefile
56
72
  - examples/http.rb
57
73
  - examples/imap.rb
58
74
  - examples/smtp.rb
59
75
  - lib/net/ntlm.rb
76
+ - lib/net/ntlm/blob.rb
77
+ - lib/net/ntlm/encode_util.rb
78
+ - lib/net/ntlm/field.rb
79
+ - lib/net/ntlm/field_set.rb
80
+ - lib/net/ntlm/int16_le.rb
81
+ - lib/net/ntlm/int32_le.rb
82
+ - lib/net/ntlm/int64_le.rb
83
+ - lib/net/ntlm/message.rb
84
+ - lib/net/ntlm/message/type0.rb
85
+ - lib/net/ntlm/message/type1.rb
86
+ - lib/net/ntlm/message/type2.rb
87
+ - lib/net/ntlm/message/type3.rb
88
+ - lib/net/ntlm/security_buffer.rb
89
+ - lib/net/ntlm/string.rb
90
+ - lib/net/ntlm/version.rb
60
91
  - lib/rubyntlm.rb
61
92
  - rubyntlm.gemspec
62
- - spec/unit/ntlm_spec.rb
93
+ - spec/lib/net/ntlm/blob_spec.rb
94
+ - spec/lib/net/ntlm/encode_util_spec.rb
95
+ - spec/lib/net/ntlm/field_set_spec.rb
96
+ - spec/lib/net/ntlm/field_spec.rb
97
+ - spec/lib/net/ntlm/int16_le_spec.rb
98
+ - spec/lib/net/ntlm/int32_le_spec.rb
99
+ - spec/lib/net/ntlm/int64_le_spec.rb
100
+ - spec/lib/net/ntlm/message/type0_spec.rb
101
+ - spec/lib/net/ntlm/message/type1_spec.rb
102
+ - spec/lib/net/ntlm/message/type2_spec.rb
103
+ - spec/lib/net/ntlm/message/type3_spec.rb
104
+ - spec/lib/net/ntlm/message_spec.rb
105
+ - spec/lib/net/ntlm/security_buffer_spec.rb
106
+ - spec/lib/net/ntlm/string_spec.rb
107
+ - spec/lib/net/ntlm/version_spec.rb
108
+ - spec/lib/net/ntlm_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/shared/examples/net/ntlm/field_shared.rb
111
+ - spec/support/shared/examples/net/ntlm/fieldset_shared.rb
112
+ - spec/support/shared/examples/net/ntlm/int_shared.rb
113
+ - spec/support/shared/examples/net/ntlm/message_shared.rb
63
114
  homepage: https://github.com/winrb/rubyntlm
64
- licenses: []
115
+ licenses:
116
+ - MIT
65
117
  metadata: {}
66
118
  post_install_message:
67
119
  rdoc_options: []
@@ -84,4 +136,24 @@ signing_key:
84
136
  specification_version: 4
85
137
  summary: Ruby/NTLM library.
86
138
  test_files:
87
- - spec/unit/ntlm_spec.rb
139
+ - spec/lib/net/ntlm/blob_spec.rb
140
+ - spec/lib/net/ntlm/encode_util_spec.rb
141
+ - spec/lib/net/ntlm/field_set_spec.rb
142
+ - spec/lib/net/ntlm/field_spec.rb
143
+ - spec/lib/net/ntlm/int16_le_spec.rb
144
+ - spec/lib/net/ntlm/int32_le_spec.rb
145
+ - spec/lib/net/ntlm/int64_le_spec.rb
146
+ - spec/lib/net/ntlm/message/type0_spec.rb
147
+ - spec/lib/net/ntlm/message/type1_spec.rb
148
+ - spec/lib/net/ntlm/message/type2_spec.rb
149
+ - spec/lib/net/ntlm/message/type3_spec.rb
150
+ - spec/lib/net/ntlm/message_spec.rb
151
+ - spec/lib/net/ntlm/security_buffer_spec.rb
152
+ - spec/lib/net/ntlm/string_spec.rb
153
+ - spec/lib/net/ntlm/version_spec.rb
154
+ - spec/lib/net/ntlm_spec.rb
155
+ - spec/spec_helper.rb
156
+ - spec/support/shared/examples/net/ntlm/field_shared.rb
157
+ - spec/support/shared/examples/net/ntlm/fieldset_shared.rb
158
+ - spec/support/shared/examples/net/ntlm/int_shared.rb
159
+ - spec/support/shared/examples/net/ntlm/message_shared.rb