rubyntlm 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.rspec +2 -2
- data/.travis.yml +10 -11
- data/CHANGELOG.md +5 -5
- data/Gemfile +3 -3
- data/LICENSE +19 -19
- data/Rakefile +22 -22
- data/lib/net/ntlm.rb +266 -263
- data/lib/net/ntlm/blob.rb +28 -28
- data/lib/net/ntlm/channel_binding.rb +65 -0
- data/lib/net/ntlm/client.rb +65 -65
- data/lib/net/ntlm/client/session.rb +237 -223
- data/lib/net/ntlm/encode_util.rb +49 -49
- data/lib/net/ntlm/exceptions.rb +14 -0
- data/lib/net/ntlm/field.rb +34 -34
- data/lib/net/ntlm/field_set.rb +129 -129
- data/lib/net/ntlm/int16_le.rb +25 -25
- data/lib/net/ntlm/int32_le.rb +24 -24
- data/lib/net/ntlm/int64_le.rb +25 -25
- data/lib/net/ntlm/message.rb +129 -129
- data/lib/net/ntlm/message/type0.rb +16 -16
- data/lib/net/ntlm/message/type1.rb +18 -18
- data/lib/net/ntlm/message/type2.rb +102 -102
- data/lib/net/ntlm/message/type3.rb +131 -131
- data/lib/net/ntlm/security_buffer.rb +47 -47
- data/lib/net/ntlm/string.rb +34 -34
- data/lib/net/ntlm/target_info.rb +89 -0
- data/lib/net/ntlm/version.rb +11 -11
- data/rubyntlm.gemspec +28 -28
- data/spec/lib/net/ntlm/blob_spec.rb +16 -16
- data/spec/lib/net/ntlm/channel_binding_spec.rb +17 -0
- data/spec/lib/net/ntlm/client/session_spec.rb +68 -68
- data/spec/lib/net/ntlm/client_spec.rb +64 -64
- data/spec/lib/net/ntlm/encode_util_spec.rb +16 -16
- data/spec/lib/net/ntlm/field_set_spec.rb +33 -33
- data/spec/lib/net/ntlm/field_spec.rb +34 -34
- data/spec/lib/net/ntlm/int16_le_spec.rb +17 -17
- data/spec/lib/net/ntlm/int32_le_spec.rb +18 -18
- data/spec/lib/net/ntlm/int64_le_spec.rb +18 -18
- data/spec/lib/net/ntlm/message/type0_spec.rb +20 -20
- data/spec/lib/net/ntlm/message/type1_spec.rb +131 -131
- data/spec/lib/net/ntlm/message/type2_spec.rb +132 -132
- data/spec/lib/net/ntlm/message/type3_spec.rb +225 -225
- data/spec/lib/net/ntlm/message_spec.rb +16 -16
- data/spec/lib/net/ntlm/security_buffer_spec.rb +64 -64
- data/spec/lib/net/ntlm/string_spec.rb +72 -72
- data/spec/lib/net/ntlm/target_info_spec.rb +76 -0
- data/spec/lib/net/ntlm/version_spec.rb +27 -27
- data/spec/lib/net/ntlm_spec.rb +127 -127
- data/spec/spec_helper.rb +22 -22
- data/spec/support/certificates/sha_256_hash.pem +19 -0
- data/spec/support/shared/examples/net/ntlm/field_shared.rb +25 -25
- data/spec/support/shared/examples/net/ntlm/fieldset_shared.rb +239 -239
- data/spec/support/shared/examples/net/ntlm/int_shared.rb +43 -43
- data/spec/support/shared/examples/net/ntlm/message_shared.rb +35 -35
- metadata +12 -3
data/lib/net/ntlm/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
module Net
|
2
|
-
module NTLM
|
3
|
-
# @private
|
4
|
-
module VERSION
|
5
|
-
MAJOR = 0
|
6
|
-
MINOR =
|
7
|
-
TINY =
|
8
|
-
STRING = [MAJOR, MINOR, TINY].join('.')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module Net
|
2
|
+
module NTLM
|
3
|
+
# @private
|
4
|
+
module VERSION
|
5
|
+
MAJOR = 0
|
6
|
+
MINOR = 6
|
7
|
+
TINY = 0
|
8
|
+
STRING = [MAJOR, MINOR, TINY].join('.')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/rubyntlm.gemspec
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'lib', 'net', 'ntlm', 'version')
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.platform = Gem::Platform::RUBY
|
5
|
-
s.name = 'rubyntlm'
|
6
|
-
s.version = Net::NTLM::VERSION::STRING
|
7
|
-
s.summary = 'Ruby/NTLM library.'
|
8
|
-
s.description = 'Ruby/NTLM provides message creator and parser for the NTLM authentication.'
|
9
|
-
|
10
|
-
s.authors = ['Kohei Kajimoto','Paul Morton']
|
11
|
-
s.email = ['koheik@gmail.com','paul.e.morton@gmail.com']
|
12
|
-
s.homepage = 'https://github.com/winrb/rubyntlm'
|
13
|
-
|
14
|
-
|
15
|
-
s.files = `git ls-files`.split($/)
|
16
|
-
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
-
s.require_paths = ["lib"]
|
19
|
-
|
20
|
-
s.required_ruby_version = '>= 1.8.7'
|
21
|
-
|
22
|
-
s.license = 'MIT'
|
23
|
-
|
24
|
-
s.add_development_dependency "pry"
|
25
|
-
s.add_development_dependency "rake"
|
26
|
-
s.add_development_dependency "rspec", ">= 2.11"
|
27
|
-
s.add_development_dependency "simplecov"
|
28
|
-
end
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'net', 'ntlm', 'version')
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.name = 'rubyntlm'
|
6
|
+
s.version = Net::NTLM::VERSION::STRING
|
7
|
+
s.summary = 'Ruby/NTLM library.'
|
8
|
+
s.description = 'Ruby/NTLM provides message creator and parser for the NTLM authentication.'
|
9
|
+
|
10
|
+
s.authors = ['Kohei Kajimoto','Paul Morton']
|
11
|
+
s.email = ['koheik@gmail.com','paul.e.morton@gmail.com']
|
12
|
+
s.homepage = 'https://github.com/winrb/rubyntlm'
|
13
|
+
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split($/)
|
16
|
+
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.required_ruby_version = '>= 1.8.7'
|
21
|
+
|
22
|
+
s.license = 'MIT'
|
23
|
+
|
24
|
+
s.add_development_dependency "pry"
|
25
|
+
s.add_development_dependency "rake"
|
26
|
+
s.add_development_dependency "rspec", ">= 2.11"
|
27
|
+
s.add_development_dependency "simplecov"
|
28
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Blob do
|
4
|
-
|
5
|
-
fields = [
|
6
|
-
{ :name => :blob_signature, :class => Net::NTLM::Int32LE, :value => 257, :active => true },
|
7
|
-
{ :name => :reserved, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
8
|
-
{ :name => :timestamp, :class => Net::NTLM::Int64LE, :value => 0, :active => true },
|
9
|
-
{ :name => :challenge, :class => Net::NTLM::String, :value => '', :active => true },
|
10
|
-
{ :name => :unknown1, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
11
|
-
{ :name => :target_info, :class => Net::NTLM::String, :value => '', :active => true },
|
12
|
-
{ :name => :unknown2, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
13
|
-
]
|
14
|
-
|
15
|
-
it_behaves_like 'a fieldset', fields
|
16
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Blob do
|
4
|
+
|
5
|
+
fields = [
|
6
|
+
{ :name => :blob_signature, :class => Net::NTLM::Int32LE, :value => 257, :active => true },
|
7
|
+
{ :name => :reserved, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
8
|
+
{ :name => :timestamp, :class => Net::NTLM::Int64LE, :value => 0, :active => true },
|
9
|
+
{ :name => :challenge, :class => Net::NTLM::String, :value => '', :active => true },
|
10
|
+
{ :name => :unknown1, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
11
|
+
{ :name => :target_info, :class => Net::NTLM::String, :value => '', :active => true },
|
12
|
+
{ :name => :unknown2, :class => Net::NTLM::Int32LE, :value => 0, :active => true },
|
13
|
+
]
|
14
|
+
|
15
|
+
it_behaves_like 'a fieldset', fields
|
16
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::ChannelBinding do
|
4
|
+
let(:certificates_path) { 'spec/support/certificates' }
|
5
|
+
let(:sha_256_path) { File.join(certificates_path, 'sha_256_hash.pem') }
|
6
|
+
let(:sha_256_cert) { OpenSSL::X509::Certificate.new(File.read(sha_256_path)) }
|
7
|
+
let(:cert_hash) { "\x04\x0E\x56\x28\xEC\x4A\x98\x29\x91\x70\x73\x62\x03\x7B\xB2\x3C".force_encoding(Encoding::ASCII_8BIT) }
|
8
|
+
|
9
|
+
subject { Net::NTLM::ChannelBinding.create(sha_256_cert) }
|
10
|
+
|
11
|
+
describe '#channel_binding_token' do
|
12
|
+
|
13
|
+
it 'returns the correct hash' do
|
14
|
+
expect(subject.channel_binding_token).to eq cert_hash
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,68 +1,68 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Client::Session do
|
4
|
-
let(:t2_challenge) { Net::NTLM::Message.decode64 "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA==" }
|
5
|
-
let(:inst) { Net::NTLM::Client::Session.new(nil, t2_challenge) }
|
6
|
-
let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
|
7
|
-
let(:client_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
|
8
|
-
let(:client_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
|
9
|
-
let(:server_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
|
10
|
-
let(:server_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
|
11
|
-
|
12
|
-
describe "#sign_message" do
|
13
|
-
|
14
|
-
it "signs a message and when KEY_EXCHANGE is true" do
|
15
|
-
expect(inst).to receive(:client_sign_key).and_return(client_sign_key)
|
16
|
-
expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
|
17
|
-
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
18
|
-
sm = inst.sign_message("Test Message")
|
19
|
-
str = "01000000b35ccd60c110c52f00000000"
|
20
|
-
expect(sm.unpack("H*")[0]).to eq(str)
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#verify_signature" do
|
26
|
-
|
27
|
-
it "verifies a message signature" do
|
28
|
-
expect(inst).to receive(:server_sign_key).and_return(server_sign_key)
|
29
|
-
expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
|
30
|
-
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
31
|
-
sig = "01000000b35ccd60c110c52f00000000"
|
32
|
-
sm = inst.verify_signature([sig].pack("H*"), "Test Message")
|
33
|
-
expect(sm).to be true
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "#seal_message" do
|
39
|
-
it "should seal the message" do
|
40
|
-
expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
|
41
|
-
emsg = inst.seal_message("rubyntlm")
|
42
|
-
expect(emsg.unpack("H*")[0]).to eq("d7389b9604f6274f")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "#unseal_message" do
|
47
|
-
it "should unseal the message" do
|
48
|
-
expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
|
49
|
-
msg = inst.unseal_message(["d7389b9604f6274f"].pack("H*"))
|
50
|
-
expect(msg).to eq("rubyntlm")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "#exported_session_key" do
|
55
|
-
it "returns a random 16-byte key when negotiate_key_exchange? is true" do
|
56
|
-
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
57
|
-
expect(inst).not_to receive(:user_session_key)
|
58
|
-
inst.exported_session_key
|
59
|
-
end
|
60
|
-
|
61
|
-
it "returns the user_session_key when negotiate_key_exchange? is false" do
|
62
|
-
expect(inst).to receive(:negotiate_key_exchange?).and_return(false)
|
63
|
-
expect(inst).to receive(:user_session_key).and_return(user_session_key)
|
64
|
-
inst.exported_session_key
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Client::Session do
|
4
|
+
let(:t2_challenge) { Net::NTLM::Message.decode64 "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA==" }
|
5
|
+
let(:inst) { Net::NTLM::Client::Session.new(nil, t2_challenge) }
|
6
|
+
let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
|
7
|
+
let(:client_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
|
8
|
+
let(:client_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
|
9
|
+
let(:server_sign_key) {["f7f97a82ec390f9c903dac4f6aceb132"].pack("H*")}
|
10
|
+
let(:server_seal_key) {["6f0d99535033951cbe499cd1914fe9ee"].pack("H*")}
|
11
|
+
|
12
|
+
describe "#sign_message" do
|
13
|
+
|
14
|
+
it "signs a message and when KEY_EXCHANGE is true" do
|
15
|
+
expect(inst).to receive(:client_sign_key).and_return(client_sign_key)
|
16
|
+
expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
|
17
|
+
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
18
|
+
sm = inst.sign_message("Test Message")
|
19
|
+
str = "01000000b35ccd60c110c52f00000000"
|
20
|
+
expect(sm.unpack("H*")[0]).to eq(str)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#verify_signature" do
|
26
|
+
|
27
|
+
it "verifies a message signature" do
|
28
|
+
expect(inst).to receive(:server_sign_key).and_return(server_sign_key)
|
29
|
+
expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
|
30
|
+
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
31
|
+
sig = "01000000b35ccd60c110c52f00000000"
|
32
|
+
sm = inst.verify_signature([sig].pack("H*"), "Test Message")
|
33
|
+
expect(sm).to be true
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#seal_message" do
|
39
|
+
it "should seal the message" do
|
40
|
+
expect(inst).to receive(:client_seal_key).and_return(client_seal_key)
|
41
|
+
emsg = inst.seal_message("rubyntlm")
|
42
|
+
expect(emsg.unpack("H*")[0]).to eq("d7389b9604f6274f")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#unseal_message" do
|
47
|
+
it "should unseal the message" do
|
48
|
+
expect(inst).to receive(:server_seal_key).and_return(server_seal_key)
|
49
|
+
msg = inst.unseal_message(["d7389b9604f6274f"].pack("H*"))
|
50
|
+
expect(msg).to eq("rubyntlm")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#exported_session_key" do
|
55
|
+
it "returns a random 16-byte key when negotiate_key_exchange? is true" do
|
56
|
+
expect(inst).to receive(:negotiate_key_exchange?).and_return(true)
|
57
|
+
expect(inst).not_to receive(:user_session_key)
|
58
|
+
inst.exported_session_key
|
59
|
+
end
|
60
|
+
|
61
|
+
it "returns the user_session_key when negotiate_key_exchange? is false" do
|
62
|
+
expect(inst).to receive(:negotiate_key_exchange?).and_return(false)
|
63
|
+
expect(inst).to receive(:user_session_key).and_return(user_session_key)
|
64
|
+
inst.exported_session_key
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -1,64 +1,64 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::Client do
|
4
|
-
let(:inst) { Net::NTLM::Client.new("test", "test01", :workstation => "testhost") }
|
5
|
-
let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
|
6
|
-
|
7
|
-
describe "#init_context" do
|
8
|
-
|
9
|
-
it "returns a default Type1 message" do
|
10
|
-
t1 = inst.init_context
|
11
|
-
expect(t1).to be_instance_of Net::NTLM::Message::Type1
|
12
|
-
expect(t1.domain).to eq("")
|
13
|
-
expect(t1.workstation).to eq("testhost")
|
14
|
-
expect(t1).to have_flag(:UNICODE)
|
15
|
-
expect(t1).to have_flag(:OEM)
|
16
|
-
expect(t1).to have_flag(:SIGN)
|
17
|
-
expect(t1).to have_flag(:SEAL)
|
18
|
-
expect(t1).to have_flag(:REQUEST_TARGET)
|
19
|
-
expect(t1).to have_flag(:NTLM)
|
20
|
-
expect(t1).to have_flag(:ALWAYS_SIGN)
|
21
|
-
expect(t1).to have_flag(:NTLM2_KEY)
|
22
|
-
expect(t1).to have_flag(:KEY128)
|
23
|
-
expect(t1).to have_flag(:KEY_EXCHANGE)
|
24
|
-
expect(t1).to have_flag(:KEY56)
|
25
|
-
end
|
26
|
-
|
27
|
-
it "clears session variable on new init_context" do
|
28
|
-
inst.instance_variable_set :@session, "BADSESSION"
|
29
|
-
expect(inst.session).to eq("BADSESSION")
|
30
|
-
inst.init_context
|
31
|
-
expect(inst.session).to be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
it "returns a Type1 message with custom flags" do
|
35
|
-
flags = Net::NTLM::FLAGS[:UNICODE] | Net::NTLM::FLAGS[:REQUEST_TARGET] | Net::NTLM::FLAGS[:NTLM]
|
36
|
-
inst = Net::NTLM::Client.new("test", "test01", :workstation => "testhost", :flags => flags)
|
37
|
-
t1 = inst.init_context
|
38
|
-
expect(t1).to be_instance_of Net::NTLM::Message::Type1
|
39
|
-
expect(t1.domain).to eq("")
|
40
|
-
expect(t1.workstation).to eq("testhost")
|
41
|
-
expect(t1).to have_flag(:UNICODE)
|
42
|
-
expect(t1).not_to have_flag(:OEM)
|
43
|
-
expect(t1).not_to have_flag(:SIGN)
|
44
|
-
expect(t1).not_to have_flag(:SEAL)
|
45
|
-
expect(t1).to have_flag(:REQUEST_TARGET)
|
46
|
-
expect(t1).to have_flag(:NTLM)
|
47
|
-
expect(t1).not_to have_flag(:ALWAYS_SIGN)
|
48
|
-
expect(t1).not_to have_flag(:NTLM2_KEY)
|
49
|
-
expect(t1).not_to have_flag(:KEY128)
|
50
|
-
expect(t1).not_to have_flag(:KEY_EXCHANGE)
|
51
|
-
expect(t1).not_to have_flag(:KEY56)
|
52
|
-
end
|
53
|
-
|
54
|
-
it "calls authenticate! when we receive a Challenge Message" do
|
55
|
-
t2_challenge = "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA=="
|
56
|
-
session = double("session")
|
57
|
-
expect(session).to receive(:authenticate!)
|
58
|
-
expect(Net::NTLM::Client::Session).to receive(:new).with(inst, instance_of(Net::NTLM::Message::Type2)).and_return(session)
|
59
|
-
inst.init_context t2_challenge
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::Client do
|
4
|
+
let(:inst) { Net::NTLM::Client.new("test", "test01", :workstation => "testhost") }
|
5
|
+
let(:user_session_key) {["3c4918ff0b33e2603e5d7ceaf34bb7d5"].pack("H*")}
|
6
|
+
|
7
|
+
describe "#init_context" do
|
8
|
+
|
9
|
+
it "returns a default Type1 message" do
|
10
|
+
t1 = inst.init_context
|
11
|
+
expect(t1).to be_instance_of Net::NTLM::Message::Type1
|
12
|
+
expect(t1.domain).to eq("")
|
13
|
+
expect(t1.workstation).to eq("testhost")
|
14
|
+
expect(t1).to have_flag(:UNICODE)
|
15
|
+
expect(t1).to have_flag(:OEM)
|
16
|
+
expect(t1).to have_flag(:SIGN)
|
17
|
+
expect(t1).to have_flag(:SEAL)
|
18
|
+
expect(t1).to have_flag(:REQUEST_TARGET)
|
19
|
+
expect(t1).to have_flag(:NTLM)
|
20
|
+
expect(t1).to have_flag(:ALWAYS_SIGN)
|
21
|
+
expect(t1).to have_flag(:NTLM2_KEY)
|
22
|
+
expect(t1).to have_flag(:KEY128)
|
23
|
+
expect(t1).to have_flag(:KEY_EXCHANGE)
|
24
|
+
expect(t1).to have_flag(:KEY56)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "clears session variable on new init_context" do
|
28
|
+
inst.instance_variable_set :@session, "BADSESSION"
|
29
|
+
expect(inst.session).to eq("BADSESSION")
|
30
|
+
inst.init_context
|
31
|
+
expect(inst.session).to be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns a Type1 message with custom flags" do
|
35
|
+
flags = Net::NTLM::FLAGS[:UNICODE] | Net::NTLM::FLAGS[:REQUEST_TARGET] | Net::NTLM::FLAGS[:NTLM]
|
36
|
+
inst = Net::NTLM::Client.new("test", "test01", :workstation => "testhost", :flags => flags)
|
37
|
+
t1 = inst.init_context
|
38
|
+
expect(t1).to be_instance_of Net::NTLM::Message::Type1
|
39
|
+
expect(t1.domain).to eq("")
|
40
|
+
expect(t1.workstation).to eq("testhost")
|
41
|
+
expect(t1).to have_flag(:UNICODE)
|
42
|
+
expect(t1).not_to have_flag(:OEM)
|
43
|
+
expect(t1).not_to have_flag(:SIGN)
|
44
|
+
expect(t1).not_to have_flag(:SEAL)
|
45
|
+
expect(t1).to have_flag(:REQUEST_TARGET)
|
46
|
+
expect(t1).to have_flag(:NTLM)
|
47
|
+
expect(t1).not_to have_flag(:ALWAYS_SIGN)
|
48
|
+
expect(t1).not_to have_flag(:NTLM2_KEY)
|
49
|
+
expect(t1).not_to have_flag(:KEY128)
|
50
|
+
expect(t1).not_to have_flag(:KEY_EXCHANGE)
|
51
|
+
expect(t1).not_to have_flag(:KEY56)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "calls authenticate! when we receive a Challenge Message" do
|
55
|
+
t2_challenge = "TlRMTVNTUAACAAAADAAMADgAAAA1goriAAyk1DmJUnUAAAAAAAAAAFAAUABEAAAABgLwIwAAAA9TAEUAUgBWAEUAUgACAAwAUwBFAFIAVgBFAFIAAQAMAFMARQBSAFYARQBSAAQADABzAGUAcgB2AGUAcgADAAwAcwBlAHIAdgBlAHIABwAIADd7mrNaB9ABAAAAAA=="
|
56
|
+
session = double("session")
|
57
|
+
expect(session).to receive(:authenticate!)
|
58
|
+
expect(Net::NTLM::Client::Session).to receive(:new).with(inst, instance_of(Net::NTLM::Message::Type2), nil).and_return(session)
|
59
|
+
inst.init_context t2_challenge
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::EncodeUtil do
|
4
|
-
|
5
|
-
context '#encode_utf16le' do
|
6
|
-
it 'should convert an ASCII string to UTF' do
|
7
|
-
expect(Net::NTLM::EncodeUtil.encode_utf16le('Test')).to eq("T\x00e\x00s\x00t\x00")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
context '#decode_utf16le' do
|
12
|
-
it 'should convert a UTF string to ASCII' do
|
13
|
-
expect(Net::NTLM::EncodeUtil.decode_utf16le("T\x00e\x00s\x00t\x00")).to eq('Test')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::EncodeUtil do
|
4
|
+
|
5
|
+
context '#encode_utf16le' do
|
6
|
+
it 'should convert an ASCII string to UTF' do
|
7
|
+
expect(Net::NTLM::EncodeUtil.encode_utf16le('Test')).to eq("T\x00e\x00s\x00t\x00")
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context '#decode_utf16le' do
|
12
|
+
it 'should convert a UTF string to ASCII' do
|
13
|
+
expect(Net::NTLM::EncodeUtil.decode_utf16le("T\x00e\x00s\x00t\x00")).to eq('Test')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,33 +1,33 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Net::NTLM::FieldSet do
|
4
|
-
|
5
|
-
fields = []
|
6
|
-
|
7
|
-
it_behaves_like 'a fieldset', fields
|
8
|
-
|
9
|
-
subject(:fieldset_class) do
|
10
|
-
Class.new(Net::NTLM::FieldSet)
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'an instance' do
|
14
|
-
subject(:fieldset_object) do
|
15
|
-
fieldset_class.string(:test_string, { :value => 'Test', :active => true, :size => 4})
|
16
|
-
fieldset_class.string(:test_string2, { :value => 'Foo', :active => true, :size => 3})
|
17
|
-
fieldset_class.new
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should serialize all the fields' do
|
21
|
-
expect(fieldset_object.serialize).to eq('TestFoo')
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should parse a string across the fields' do
|
25
|
-
fieldset_object.parse('FooBarBaz')
|
26
|
-
expect(fieldset_object.serialize).to eq('FooBarB')
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should return an aggregate size of all the fields' do
|
30
|
-
expect(fieldset_object.size).to eq(7)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Net::NTLM::FieldSet do
|
4
|
+
|
5
|
+
fields = []
|
6
|
+
|
7
|
+
it_behaves_like 'a fieldset', fields
|
8
|
+
|
9
|
+
subject(:fieldset_class) do
|
10
|
+
Class.new(Net::NTLM::FieldSet)
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'an instance' do
|
14
|
+
subject(:fieldset_object) do
|
15
|
+
fieldset_class.string(:test_string, { :value => 'Test', :active => true, :size => 4})
|
16
|
+
fieldset_class.string(:test_string2, { :value => 'Foo', :active => true, :size => 3})
|
17
|
+
fieldset_class.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should serialize all the fields' do
|
21
|
+
expect(fieldset_object.serialize).to eq('TestFoo')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should parse a string across the fields' do
|
25
|
+
fieldset_object.parse('FooBarBaz')
|
26
|
+
expect(fieldset_object.serialize).to eq('FooBarB')
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return an aggregate size of all the fields' do
|
30
|
+
expect(fieldset_object.size).to eq(7)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|